Jekyll分页导航到错误的页面



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

上的页面。我做了这个GIF来说明这个问题:https://i.stack.imgur.com/2emIA.gif

我的设置我使用的Jekyll主题托管在AWS Amplify上。通常对于这个主题,索引页是所有博客文章的位置。我改变了这一点,所以索引页是一个"欢迎"的帖子,而不是一个超链接到博客。

实现:

  1. 我移动index.html(分页代码)从我的根目录到一个文件夹"博客">
  2. 增加索引。
  3. 在我的根目录。
  4. 将此代码添加到我的_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

博客的历史记录在这里bgigurtsis/blog

Pagination将"Older"按钮链接到我的主页,而不是我博客的第一页。似乎pagination不知道bgigurtsis。com/blog是博客文章的第一页,但我不知道如何解决这个问题。什么好主意吗?

谢谢!

在./_includes/pagination.html中,它告诉pagination在访问新帖子时导航到哪里。默认情况下,这个设置为/,当你的博客文章通常是有效的。我只是把它改成了/blog。

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

最新更新