如何在jekyll中分页?

时间:2019-08-26 13:56:09

标签: jekyll

我需要将Paging放在我的jekll网站上,但是当我尝试发布这些帖子时,就会消失。

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

我想在index.html中分页

code 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/

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

2 个答案:

答案 0 :(得分:1)

在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 /” 行。文件。

答案 1 :(得分:0)

分页检查清单:

1-在 _config.yml 中:

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

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