如何在没有index.html的情况下使用jekyll-paginate



我正在尝试在github页面上构建我的博客,并且由于明显的原因,我必须使用jekyll-paginate。问题是,除了欢迎页面以外,我不使用index.html页面。我在一个称为文章的文件夹中有一个单独的页面,称为index.html,因此博客的URL应为 xyz.github.io/articles/

但是,这提出了一个主要问题 - 显然,jekyll -paginate拒绝在博客的根目录中没有明确的index.html工作。因此,我尝试使用没有这种限制的jekyll-paginate-v2,并且效果很好!

但是,github页面不支持jekyll-paginate-v2,因此,我回到了正方形1。我该怎么办?

注意:这是我的代码:

index.md

---
layout: home
title: SomuSysAdmin
---
If you're new to this site and have no idea what's going on, first go and read the [About](about.md) section of the blog.
Here's a list of all the major articles this blog contains: 
## [Red Hat Certified Systems Administrator (RHCSA) Guide]({% post_url 2017-09-11-RHCSA %})

这是我的_config.yml:

# -----------------------------------------------------------------------------
#  User configuration
# -----------------------------------------------------------------------------
title:               SomuSysAdmin
# The unique resource location of your page.
# Set to `https://<username>.github.io` when hosting on GitHub Pages
url:                 https://somuSysAdmin.github.io
# Set to '' when hosting a blog on GitHub Pages, ie on `//<username>.github.io`
# Set to '/<reponame>' when using the `gh-pages` branch of a repository
baseurl:             ''
# A very short description of your page
tagline:             Easiest way to earn some SysAdmin mojo!
# A short description of the page, used in the sidebar and as fallback for the meta description tag.
# Markdown enabled, but don't use more than one paragraph (enforced by `>`)
description:         >
  A short set of notes and pointers concerning everything I know about System Administration.
# This should be the same author as first entry in `_data/authors.yml`
author:
  name:              Somenath Sinha
  email:             somu.sysa_fakeID@gmail.com
# Fallback image and color
image:               /assets/img/nap.jpg
color:               '#4ea97e'
# The font used for headings. Expects a string that is a valid CSS font-family value.
font_heading:        "'Roboto Slab', Helvetica, Arial, sans-serif"
# The text font. Expects a string that is a valid CSS font-family value.
font:                "'Noto Sans', Helvetica, Arial, sans-serif"
# The string encoding what fonts to fetch from Google Fonts.
# See: https://qwtel.com/hydejack/docs/configuration/
google_fonts:        Roboto+Slab:700|Noto+Sans:400,400i,700,700i
# If you do not use a Google Fonts, uncomment the line below
# no_google_fonts:     true
# Set your Google Analytics id to receive `pageview` events.
# To remove Google Anaylics from your page, remove the line below.
google_analytics:    <UA-XXXXXXXX-X>
# Setting a disqus shortname will enable the comment section on pages with `comments: true` in the front matter
disqus_shortname:    somusa
# This text will appear in the footer of every page. Markdown enabled.
copyright:           '&copy; 2017 Somenath Sinha. All rights reserved.'
# Format of the permalinks
permalink:           pretty
# Pagination configuration (used by the `blog` layout)
paginate:            5
paginate_path:       '/page-:num/'
# If you are upgrading form a v5 verison of Hydejack, uncomment the two lines below,
# so that the location of the feed XML stays the same.
# feed:
#   path:              atom.xml
# Set to true when building with the `--lsi` option
# See: https://jekyllrb.com/docs/variables/#site-variables
# use_lsi:             true
# Set to `true` if you don't want to show an icon after each link that opens to an external site
# no_mark_external:    true
# Uncomment this line if third party plugins fail to work with dynimically loaded pages
# disable_push_state:  true
# Uncomment this line if want to disable the touch drawer on mobile
# disable_drawer: true
# -----------------------------------------------------------------------------
#  Collections
# -----------------------------------------------------------------------------
collections:
  featured_categories:
    permalink:       /category/:name/
    output:          true
  featured_tags:
    permalink:       /tag/:name/
    output:          true
  projects:
    permalink:       /projects/:path/
    output:          true
# -----------------------------------------------------------------------------
#  Advanced configuration
# -----------------------------------------------------------------------------
gems:
  - jekyll-default-layout
  - jekyll-feed
  - jekyll-optional-front-matter
  - jekyll-paginate
  - jekyll-redirect-from
  - jekyll-relative-links
  - jekyll-sitemap
exclude:
  - README.md
  - node_modules
  - package.json
  - package-lock.json
  - Gemfile
  - Gemfile.lock
kramdown:
  footnote_backlink: '&#x21a9;&#xfe0e;'
  math_engine:       mathjax
  math_engine_opts:
    preview:         true
    preview_as_code: true
compress_html:
  comments:          ["<!-- ", " -->"]
  clippings:         all
  endings:           all
  ignore:
    envs:            [development]
sass:
  style:             compressed

这是我的文章/index.md的内容:

---
layout  : blog
title   : Articles
menu    : true
order   : 1
---

那么,我有什么办法可以使用jekyll-paginate而不使用显式index.html?

这是我尝试在没有index.html的目前博客上运行jekyll的情况:

$ bundle exec jekyll serve --incremental
Configuration file: D:/Git/blog/_config.yml
      Deprecation: The 'gems' configuration option has been renamed to 'plugins'. Please update your config file accordingly.
      Source: D:/Git/blog
      Destination: D:/Git/blog/_site
Incremental build: enabled
    Generating...
      Pagination: Pagination is enabled, but I couldn't find an index.html page to use as the pagination template. Skipping pagination.
                    done in 1.736 seconds.
Please add the following to your Gemfile to avoid polling for changes:
    gem 'wdm', '>= 0.1.0' if Gem.win_platform?
Auto-regeneration: enabled for 'D:/Git/blog'
  Server address: http://127.0.0.1:4000/
  Server running... press ctrl-c to stop.

如您所见,分页完全不起作用,所以我该如何修复它?我是Markdown和Jekyll的新手,所以我甚至可能缺少明显的东西!请帮助我修复它!

jekyll分页的文档说:

分页仅在HTML文件中起作用

分页不在jekyll网站中的降价或纺织品文件中工作。分页在从HTML文件中调用时可工作,名为index.html,该文件可以通过paginate_path配置值居住并从子目录中驻留并产生分页。

因此,如果您希望您的博客在URL /articles//articles/N/上,请在您的配置中指定:

paginate_path: "/articles/:num/"

并将index.html文件放入articles目录中,该文件列出了当前页面的帖子:

<!-- This loops through the paginated posts -->
{% 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>

(有关更多片段和配置详细信息,请参见文档。)

编辑:我认为您的问题是您的paginate_path设置。您将其设置为'/page-:num/',因此Jekyll paginate在您的网站root中寻找index.html

对我而言,解决方案是:

如果您想将您的博客页面完全放在index.html之外。

blog                   # New directory
└── index.html         # Your new blog page

在您的blog/index.html中,您需要添加它,该添加将渲染博客页面(home布局是您拥有paginator.posts的位置)

---
layout: home
title: Blog
permalink: /blog/
---

,然后确保您的_config.yml中有Paginator配置:

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

相关内容

  • 没有找到相关文章

最新更新