【问题标题】:Jekyll pagination navigates to wrong pageJekyll 分页导航到错误的页面
【发布时间】:2021-05-22 10:11:41
【问题描述】:

问题:您可以点击“Older”进入旧博客的第二页,即https://www.bgigurtsis.com/blog/page2/。但是,在第二个页面上单击“更新”一次会将您带到主页https://www.bgigurtsis.com,而不是您刚刚在https://www.bgigurtsis.com/blog上的页面

我制作了这个 GIF 来说明这个问题:https://i.imgur.com/JN9qXoN.gif

我的设置 我使用的是托管在 AWS Amplify 上的 Jekyll 主题。通常对于这个主题,索引页面是所有博客文章所在的位置。我对此进行了更改,因此索引页面是一个“欢迎”帖子,其中包含指向博客的超链接。

要实现这一点:

  1. 我将 index.html(分页代码)从我的根目录移到了一个文件夹中 称为“博客”
  2. 在我的根目录中添加了一个 index.md(欢迎页面)。
  3. 将此代码添加到我的 _config.yml:paginate_path:“/blog/page:num”

这是文件夹结构:

website
├── config.yml
├── index.md (welcome post)
├── blog
       ├── index.html (paginate code)
│
├── posts
       ├── post1.md
       ├── post2.md
       ├── post3.md
       ├── post4.md
       ├── post5.md

我的 _config.yml 构建设置:

# Build settings
markdown:     kramdown
redcarpet:
  extensions: ['smart', 'tables', 'with_toc_data']
permalink: /blog/:title
paginate_path: "/blog/page:num"
paginate:     4

这是我的分页代码,包含在 blog/index.html 中:

---
layout: default
---
{% assign posts_count = paginator.posts | size %}

<div class="home">
  {% if posts_count > 0 %}
    <div class="posts">
      {% for post in paginator.posts %}
        <div class="post py3">
          <p class="post-meta">
        {% if site.date_format %}
          {{ post.date | date: site.date_format }}
        {% else %}
          {{ post.date | date: "%b %-d, %Y" }}
        {% endif %}
      </p>
          <a href="{{ post.url | relative_url }}" class="post-link"><h3 class="h1 post-title">{{ post.title }}</h3></a>
          <span class="post-summary">
            {% if post.summary %}
              {{ post.summary }}
            {% else %}
              {{ post.excerpt }}
            {% endif %}
          </span>
        </div>
      {% endfor %}
    </div>

    {% include pagination.html %}
  {% else %}
    <h1 class='center'>{{ site.text.index.coming_soon }}</h1>
  {% endif %}
</div>

我的博客主页在这里bgigurtsis.com

博客的repistory在这里bgigurtsis/blog

分页将“旧”按钮链接到我的主页,而不是我博客的第一页。似乎分页不知道 bgigurtsis dot com/blog 是博客文章的第一页,但我不知道如何解决这个问题。有什么想法吗?

谢谢!

【问题讨论】:

    标签: pagination jekyll


    【解决方案1】:

    在 ./_includes/pagination.html 中,它告诉分页在转到较新的帖子时导航到哪里。默认情况下,这设置为 / 当您的博客文章通常是时有效。我只是将其更改为 /blog。

    完整的变化可以在这里看到: https://github.com/bgigurtsis/blog/commit/72f6210518551b8983a27ef2bf44bf67028b6b4f

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多