jekyll博客标题,包括分页变量 [英] jekyll blog title to include pagination variables

查看:59
本文介绍了jekyll博客标题,包括分页变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使博客的第2页以上具有不同的标题,以便搜索引擎将其编入索引.

I am trying to get Page 2+ of my blog to have a different title for search engines to index.

我已经阅读了其他一些stackoverflow答案,指出您不能在开头的Yaml中使用液体标签.一个建议使用JS来更新标题,但是这对我不起作用,因为我希望搜索引擎为已解析的标题建立索引.

I have read several other stackoverflow answers stating that you cannot use liquid tags in the front matter yaml. One suggested to use JS to update the title, however this will not work for me as I want the search engine to index the parsed title.

我认为可能还有另一种方式.我也许可以为我的每个页面创建一个HTML页面.我想这样做,而不必将我的每一篇帖子都手动添加到每个页面中(每次我发布新文章都会导致正在进行的耗时任务).

I thought there may be another way. I can perhaps create a HTML page for each of my pages. I would like to do that without having to manually add each one of my posts into each of the pages (resulting in an ongoing time consuming task each time I post a new article).

我当时以为我可以将一页写成1-10,另一页写成11-20,依此类推……诸如此类:

I was thinking I could make one page for 1-10, another page for 11-20, etc... Something like this:

---
title: Blog Page 2
---

{% for post in paginator.posts %}
{% if post.index > 10 %}{% if post.index <= 20 %}
<div class="post-preview">
    <a href="{{ post.url | prepend: site.baseurl }}">
        <h2 class="post-title"> {{ post.title }}</h2>
        {{ post.excerpt }}
    </a>
</div>
{% endif %}{% endif %}
{% endfor %}

似乎没有可用的post.index变量.我可以使用类似的东西吗?

It seems there is no post.index variable available. Is there anything similar I can use?

或者还有其他方法可以实现标题中的博客页面X"吗?

Or are there any other ways to achieve "Blog Page X" in my title?

推荐答案

假设您的head标签位于_includes/head.html文件中.在title标记中,只需添加:

Supposing that your head tags are in your _includes/head.html file. In the title tag just add :

{% if paginator %} - page {{ paginator.page }}{% endif %}

您的标题标签现在看起来像这样:

Your title tag now looks like this :

<title>
{% if page.title %}{{ page.title }}{% else %}{{ site.title }}{% endif %}
{%if paginator %} - page {{ paginator.page }}{% endif %}
</title>

这篇关于jekyll博客标题,包括分页变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆