将自定义域与Github页面合并后,Jekyll`site.posts`变为空白

时间:2018-07-29 11:14:44

标签: jekyll liquid github-pages

我正在与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

1 个答案:

答案 0 :(得分:2)

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

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

将加载gh页上所有可用的插件,请参见complete list here

这将允许您重现gh页面错误,该错误来自您的config指令之一:

collections_dir: .

如果删除或注释该指令,一切将恢复正常。