首页 > 解决方案 > Jekyll `site.posts` 在将自定义域与 Github 页面合并后显示为空

问题描述

我正在使用 Jekyll 构建一个简单的静态网站作为我的个人网站。我正在使用 GitHub 页面来托管它(https://username.github.io)。最近我试图将我的自定义域与它合并并面临一个问题。

例如,我有一个页面的标题posts.html是这样的:

---
layout: page
title: Posts
permalink: posts
---

Some Text

<ul>
    {% for post in site.posts %}
        <li> List item </li>
    {% endfor %}
</ul>

以前一切都按预期出现。但是在合并自定义域之后,没有出现任何列表项(即使我在本地运行时一切都很完美)。我想site.posts似乎是空的。任何建议为什么是?

我有另一个页面,例如以下内容,它遍历site.posts. 即使在合并自定义域之后,它也显得很完美。

---
layout: page
title: Books I Have Read
permalink: read-books
---

Some text

<ul>
    {% for book in site.data.read-books %}
        <li>
            <a href={{book.goodreads}}> {{book.title}} </a>;
            {{book.author}} [{{book.date}}]
            {% if book.comment %}
                <br/>
                (Opinion: {{book.comment}})
            {% endif %}
        </li>
    {% endfor %}
</ul>

我的帖子格式:YYYY-MM-DD-title.md

帖子目录名称:_posts

本地 Jekyll 版本为:3.7.0

_config.yml内容:

Title: Md. Taufique Hussain
brieftitle: Taufique
baseUrl: ""
# Where things are
source:          .
destination:     ./_site
collections_dir: .
plugins_dir:     _plugins
layouts_dir:     _layouts
data_dir:        _data
includes_dir:    _includes
collections:
  posts:
    output:   true

# Handling Reading
safe:                 false
include:              [".htaccess"]
exclude:              ["Gemfile", "Gemfile.lock", "node_modules", "vendor/bundle/", "vendor/cache/", "vendor/gems/", "vendor/ruby/"]
keep_files:           [".git", ".svn"]
encoding:             "utf-8"
markdown_ext:         "markdown,mkdown,mkdn,mkd,md"
strict_front_matter: false

# Filtering Content
show_drafts: null
limit_posts: 0
future:      false
unpublished: false

# Plugins
whitelist: []
plugins:
    - jekyll-seo-tag

# Conversion
markdown:    kramdown
highlighter: rouge
lsi:         false
excerpt_separator: "\n\n"
incremental: false

# Serving
detach:  false
port:    4000
host:    127.0.0.1
baseurl: "" # does not include hostname
show_dir_listing: false

# Outputting
permalink:     date
paginate_path: /page:num
timezone:      null

quiet:    false
verbose:  false
defaults: []

liquid:
  error_mode: warn

# Markdown Processors
rdiscount:
  extensions: []

redcarpet:
  extensions: []

kramdown:
  auto_ids:       true
  entity_output:  as_char
  toc_levels:     1..6
  smart_quotes:   lsquo,rsquo,ldquo,rdquo
  input:          GFM
  hard_wrap:      false
  footnote_nr:    1

标签: jekyllliquidgithub-pages

解决方案


首先是你想在 Github Pages 配置中本地测试 Jekyll,你的 Gemfile 必须包含:

source "https://rubygems.org"
gem 'github-pages'

将加载 gh 页面上可用的所有插件,请参阅此处的完整列表

这将允许您重现来自您的配置指令之一的 gh pages 错误:

collections_dir: .

如果您删除或评论此指令,一切都会恢复正常。


推荐阅读