1

我正在尝试在 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 %}下一个 » {% else %} 下一个 » {% endif %} {% endif %}

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

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

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

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

4

1 回答 1

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它比在每个帖子上定义链接要干净得多。

于 2018-03-01T15:56:07.593 回答