在 Jekyll 中导航页面(不是帖子)
Navigation for pages (not for posts) in Jekyll
我正在使用 Jekyll 构建一个网站,只有页面。
我想找到一种方法来为页面生成上一个和下一个链接,并为页面设置一个属性,例如 order
。
有什么东西可以完成这项工作(没有插件)?我只能找到关于帖子的东西。
{% assign sortedPages = site.pages | sort:'order' | where: 'published', true %}
{% for p in sortedPages %}
{% if p.url == page.url %}
{% if forloop.first == false %}
{% assign prevIndex = forloop.index0 | minus: 1 %}
<a href="{{site.baseurl}}{{sortedPages[prevIndex].url}}">
previous : {{sortedPages[prevIndex].title}}
</a>
{% endif %}
{% if forloop.last == false %}
{% assign nextIndex = forloop.index0 | plus: 1 %}
<a href="{{site.baseurl}}{{sortedPages[nextIndex].url}}">
next : {{sortedPages[nextIndex].title}}
</a>
{% endif %}
{% endif %}
{% endfor %}
这样就可以了。
为了过滤您发布的页面,您可以在页面前端添加一个published
变量。
设置变量
published: true
-> 这是一个布尔值
published: 'true'
-> 这是一个字符串
使用 where 过滤器
| where: 'published', true
将测试布尔值
| where: 'published', 'true'
将测试字符串
我正在使用 Jekyll 构建一个网站,只有页面。
我想找到一种方法来为页面生成上一个和下一个链接,并为页面设置一个属性,例如 order
。
有什么东西可以完成这项工作(没有插件)?我只能找到关于帖子的东西。
{% assign sortedPages = site.pages | sort:'order' | where: 'published', true %}
{% for p in sortedPages %}
{% if p.url == page.url %}
{% if forloop.first == false %}
{% assign prevIndex = forloop.index0 | minus: 1 %}
<a href="{{site.baseurl}}{{sortedPages[prevIndex].url}}">
previous : {{sortedPages[prevIndex].title}}
</a>
{% endif %}
{% if forloop.last == false %}
{% assign nextIndex = forloop.index0 | plus: 1 %}
<a href="{{site.baseurl}}{{sortedPages[nextIndex].url}}">
next : {{sortedPages[nextIndex].title}}
</a>
{% endif %}
{% endif %}
{% endfor %}
这样就可以了。
为了过滤您发布的页面,您可以在页面前端添加一个published
变量。
设置变量
published: true
-> 这是一个布尔值
published: 'true'
-> 这是一个字符串
使用 where 过滤器
| where: 'published', true
将测试布尔值
| where: 'published', 'true'
将测试字符串