使用Jekyll创建一个网站,该网站具有带有分页内容的博客子目录

Ben*_*tra 4 pagination jekyll github-pages

我正在使用Jekyll创建一个网站,主页面(jekyllsiteblogpaginated.com/index.html)不显示任何博客内容.另外,我想为博客创建一个子目录,主页jekyllsiteblogpaginated.com/blog/index.html以分页方式显示帖子.

我在这里推动了我的例子 http://bpatra.github.io/jekyllsiteblogpaginated.可以在此处找到github存储库

您可能会在存储库分支中看到我已经测试了几个组织:使用index.html文件创建子目录博客或直接在根级别添加blog.html文件.我也试图利用paginate_path选项,但也没有成功,paginator总是空的.

这个问题类似于这一个,用户在评论说,他终于用一个插件.我想避免插件,因为我的网站将托管在github页面上.

Dav*_*uel 18

我成功了 !

1 - 添加config.yml

paginate_path: "/blog/page:num"
Run Code Online (Sandbox Code Playgroud)

2 - 在你的代码中:

{% for post in paginator.posts %}
Run Code Online (Sandbox Code Playgroud)

并不是

{% for post in paginated.posts %}
Run Code Online (Sandbox Code Playgroud)

3 - 最后一个微妙的观点.如在Jekyll变量doc的底部所见

Paginator变量可用性

这些仅在索引文件中可用,但它们可以位于子目录中,例如/blog/index.html.

因此,通过将blog.html重命名为blog/index.html,您最终可以获得博客的分页.

Etvoilà!