【问题标题】:How to paginate in jekyll?如何在jekyll中进行分页?
【发布时间】:2019-12-30 17:29:05
【问题描述】:

我需要在我的 jekll 网站上放置 Paging,但是当我尝试时帖子消失了。

我使用 jekyll 3.8.6 并包含 jekyll-paginate 插件,我在 _config.yml 文件中使用 gem 命令 'github-pages', '170', group:: jekyll_plugins。

我想在 index.html 中分页

代码 index.html:

---
layout: default
---

{% 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 %}

<!-- Pagination links -->
<div class="pagination">
  {% if paginator.previous_page %}
    <a href="{{ paginator.previous_page_path }}" class="previous">
      Previous
    </a>
  {% else %}
    <span class="previous">Previous</span>
  {% endif %}
  <span class="page_number ">
    Page: {{ paginator.page }} of {{ paginator.total_pages }}
  </span>
  {% if paginator.next_page %}
    <a href="{{ paginator.next_page_path }}" class="next">Next</a>
  {% else %}
    <span class="next ">Next</span>
  {% endif %}
</div>

代码_config.yml

# Welcome to Jekyll!
#
# This config file is meant for settings that affect your whole blog, values
# which you are expected to set up once and rarely edit after that. If you find
# yourself editing this file very often, consider using Jekyll's data files
# feature for the data you need to update frequently.
#
# For technical reasons, this file is *NOT* reloaded automatically when you use
# 'bundle exec jekyll serve'. If you change this file, please restart the server process.

# Site settings
# These are used to personalize your new site. If you look in the HTML files,
# you will see them accessed via {{ site.title }}, {{ site.email }}, and so on.
# You can create any custom variable you would like, and they will be accessible
# in the templates via {{ site.myvariable }}.
title: <>Davi Luis</>
email: your-email@example.com
description: Experências no Mundo da Tecnologia
baseurl: "" # the subpath of your site, e.g. /blog
url: "www.daviluis.com.br" # the base hostname & protocol for your site, e.g. http://example.com

paginate: 5
paginate_path: "/blog/page:num/"
comments: true

gem 'github-pages', '170', group: :jekyll_plugins


# Build settings
theme: minima

# minima theme settings
show_excerpts: false # set to true to show excerpts on the homepage

# Minima date format
# refer to http://shopify.github.io/liquid/filters/date/ if you want to customize this
minima:
  date_format: "%b %-d, %Y"

disqus:
  shortname: https-www-daviluis-com-br

# If you want to link only specific pages in your header, uncomment
# this and add the path to the pages in order as they should show up
#header_pages:
# - about.html

# social links
#twitter_username: jekyllrb
github_username:  daviluis321
#rss: rss
# dribbble_username: jekyll
# facebook_username: jekyll
# flickr_username: jekyll
# instagram_username: jekyll na
# linkedin_username: jekyll
# pinterest_username: jekyll
# youtube_username: jekyll
# googleplus_username: +jekyll

# Mastodon instances
# mastodon:
# - username: jekyll
#   instance: example.com
# - username: jekyll2
#   instance: example.com


# Exclude from processing.
# The following items will not be processed, by default. Create a custom list
# to override the default setting.
# exclude:
#   - Gemfile
#   - Gemfile.lock
#   - node_modules
#   - vendor/bundle/
#   - vendor/cache/
#   - vendor/gems/
#   - vendor/ruby/

我索引代码节点我尝试打印帖子及其页码。

【问题讨论】:

  • 小心; paginate_path: "/blog/page:num/"... 你的帖子在哪个目录下?

标签: jekyll


【解决方案1】:

分页检查表:

1- 在 _config.yml 中:

paginate: 5
paginate_path: "/blog/page:num/"

2- 在paginate_path 中创建一个 index.html(不是降价)首页。这里是 /blog/index.html

【讨论】:

    【解决方案2】:

    在 Minima 主题的根文件夹中。将 index.md 文件名更改为 index.html 然后在其上方粘贴分页代码。

    {% 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 %}
    
    <!-- Pagination links -->
    <div class="pagination">
      {% if paginator.previous_page %}
        <a href="{{ paginator.previous_page_path }}" class="previous">
          Previous
        </a>
      {% else %}
        <span class="previous">Previous</span>
      {% endif %}
      <span class="page_number ">
        Page: {{ paginator.page }} of {{ paginator.total_pages }}
      </span>
      {% if paginator.next_page %}
        <a href="{{ paginator.next_page_path }}" class="next">Next</a>
      {% else %}
        <span class="next ">Next</span>
      {% endif %}
    </div>
    

    注意:如果这不起作用,请删除 config.yml 中的 paginate_path: "/blog/page:num/" 行文件。

    【讨论】:

    • 谢谢。使用 minima 2.5.1 的我不需要 paginate_path
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-11
    • 2014-06-19
    • 1970-01-01
    相关资源
    最近更新 更多