【问题标题】:Show blog post title in meta information在元信息中显示博客文章标题
【发布时间】:2014-02-17 15:18:43
【问题描述】:

我正在为我的 Jekyll 网站进行搜索引擎优化,但遇到了无法设置元信息的问题。

...
<meta name="og:title" content="{{ seo_title }}" />
...
<!-- now in my for post-loop: -->
{% for post in site.posts %}
  <li class="post-link">
    <a class="post-title" href="{{ post.url }}">
      <span class="post-date">{{ post.date | date_to_string }}</span>
      {{ assign seo_title = post.title }}
      {{ post.title }}
    </a>
  </li>
{% endfor %}

我将sel_title 分配给帖子标题,但它没有出现在我的元信息中!我刚收到&lt;meta name="og:title" content="" /&gt;

我还尝试使用{{ page.seo_title }} {{ post.seo_title }}{{ seo_title }} 在我的post.html 帖子布局中添加{{ assign seo_title = page.title }} 无济于事

现在,显然这真的不是我想要的,因为从逻辑上讲 - 在这个 for 循环之后,它会将其设置为最后一个帖子的标题,但我什至无法显示它。理想情况下,我希望它出现在帖子中。

You can view the page here 我希望它出现在哪里。 我哪里错了?如何使用我的帖子信息来填写我的 SEO 元信息?

【问题讨论】:

    标签: html seo jekyll


    【解决方案1】:

    查看了您的 github 存储库。您只对索引和帖子使用一种基本布局。在您的 _posts 中,当您执行 {% include post.html %} 时,YAML Front Matters 将第一次(并且仅一次)得到处理。但是随后您将其传递给默认布局,并且您也无法将帖子中的 YAML 变量传递给它。

    您可以采用的一种典型模式是拆分默认布局并在 _includes 文件夹中创建部分 html 文件,即 header.html 和 footer.html。然后,您可以使用它们来创建默认布局和发布布局。这样您就可以将帖子中相关的 YAML Front Matter 变量传递给标题。

    【讨论】:

      猜你喜欢
      • 2021-06-24
      • 1970-01-01
      • 2015-07-02
      • 1970-01-01
      • 2019-05-17
      • 1970-01-01
      • 2016-03-31
      • 2016-05-18
      • 1970-01-01
      相关资源
      最近更新 更多