使用GH Pages的默认插件进行分页?

时间:2018-03-01 14:25:25

标签: jekyll github-pages jekyll-paginator

我正在尝试在GH Pages上填充我的小博客。我被Jekyll分页了。

这是我的_config.yml

theme: jekyll-theme-cayman

title: iBug @ GitHub
url: https://ibug.github.io/
tagline: The small personal site for iBug
description: The small personal site for iBug
author: iBug
show_downloads: false

plugins:
  - jekyll-paginate
  - jekyll-redirect-from
  - jekyll-mentions
  - jekyll-seo-tag

paginate: 5
paginate_path: "/blog/page:num/"

这里是唯一一篇帖子的内容:

---
layout: blog
permalink: /p/1
---

# Test Post

Nothing here

我想要/blog上的分页索引页面以及/blog/page#上的后续页面(其中#是一个数字)。我复制了一个示例index.html,并将其放在我的仓库中的/blog/index.html

但是当我导航到https://ibug.github.io/blog时,它就会显示出来:

  

{%if paginator.total_pages> 1%}   {%if paginator.previous_page%} « Prev {%else%}«Prev {%endif%} {%for page in(1..paginator.total_pages)%} {%if page == paginator.page% } {{page}} {%elsif page == 1%} {{ page }} {%else%} {{ page }} {%endif%} {%endfor%} {%if paginator.next_page%} Next » {%else%}下一页»{%endif%}   {%endif%}

阅读GH文档,我了解到jekyll-paginate是一个默认插件,无法禁用,因此不应该这样。

我在/_posts/2018-03-01-first-post.md也有一个虚拟帖子,它正确显示在https://ibug.github.io/2018/03/01/first-post

我不想安装Ruby dev环境和其他东西。我只想使用GH Pages的内置功能。<​​/ p>

我可以在/blog/blog/pageN获得索引吗?

1 个答案:

答案 0 :(得分:3)

查看源代码,这可能是您博客子目录中index.html文件的问题。

您需要在Jekyll要处理的任何文件中包含前端内容,即使它不包含任何键/值数据。如果没有这个,Jekyll会认为它是一个静态资产,并且只会在构建时将其直接复制到您的_site目录中。

index.html文件的顶部添加此文件应修复它:

---
---
content here

您还要确保您确实在该页面上显示帖子,而不仅仅是分页导航。所以一定要在它上面加上这样的东西:

{% for post in paginator.posts %}
  <h1><a href="{{ post.url }}">{{ post.title }}</a></h1>
  <p class="author">
    <span class="date">{{ post.date }}</span>
  </p>
  <div class="content">
    {{ post.content }}
  </div>
{% endfor %}

作为旁注,您可能需要在_config.yml内查看setting defaults以了解永久链接。它比在每个帖子上定义链接要清晰得多。