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



我正在尝试在GH页面上填充我的小博客。我被困在杰基尔分页。

这是我的_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 时,它只是像这样显示:

{% 如果paginator.total_pages> 1 %} {% 如果paginator.previous_page %}« 上一页 {% else %} « 上一页 {% 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 %} Next » {% endif %}{% endif %}

阅读 GH 文档,我了解到jekyll-paginate是一个默认插件,不能禁用,所以它不应该以这种方式工作。

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

我不想安装 Ruby 开发环境和其他东西。我只想使用 GH Pages 的内置功能。

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

查看您的源代码,这可能是博客子目录中的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中为帖子永久链接设置默认值。它可能比在每个帖子上定义链接要干净得多。

最新更新