如何在不同的页面上改变jekyll的`site.title`?

时间:2016-03-15 10:27:22

标签: jekyll

我想在我的网站的不同部分呈现不同的网站标题(由路径前缀标识)。理想的设置如下:

_config.yml contains:
defaults:
  -
    scope:
      path: ""
    values:
      title: logophile
  -
    scope:
      path: "blog"
    values:
      title: (b)logophile

标题包含在页面和帖子模板中,

_config.yml

然而,这会将空字符串写入生成的html。

我试过的替代方案:

  • site.title: logophile使用site.title: (b)logophile / _config.yml
  • my_site_title: logophile定义{{ my_site_title }}等,并在_includes/header.html
  • 中使用 var request = (HttpWebRequest)WebRequest.Create(url); var postData = "name=" + name + "&config=" + config; var data = Encoding.ASCII.GetBytes(postData); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; using (var stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } var response = (HttpWebResponse)request.GetResponse(); var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); if (responseString != null) { var jsonObject = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(responseString); return jsonObject.result == "success"; }

1 个答案:

答案 0 :(得分:0)

默认title只会更改page.title(如果尚未设置)。所以,这不起作用。

您可以像这样设置默认值:

defaults:
  -
    scope:
      path: ""
    values:
      alternative_site_title: logophile
  -
    scope:
      path: "blog"
    values:
      alternative_site_title: (b)logophile

并像这样调用这个变量:

<a class="site-title" href="{{ site.baseurl }}/">
  {{ page.alternative_site_title }}
</a>