Jekyll 帖子未生成

问题描述 投票:0回答:10

我正在尝试向我的 Jekyll 网站添加新帖子,但当我运行

jekyll serve
时,我无法在生成的页面上看到它。

Jekyll 帖子无法生成的常见原因有哪些?

jekyll
10个回答
266
投票

25
投票
您可以使用

jekyll build --verbose

查看详细的构建过程。

示例输出:

Logging at level: debug Configuration file: /home/fangxing/fffx.github.io/_config.yml Logging at level: debug Requiring: jekyll-archives Requiring: jekyll-livereload Requiring: kramdown Source: /home/fangxing/fffx.github.io Destination: /home/fangxing/fffx.github.io/_site Incremental build: enabled Generating... EntryFilter: excluded /Gemfile EntryFilter: excluded /Gemfile.lock Reading: _posts/2018-01-14-new-post.md Reading: _posts/2014-01-01-example-content.md Reading: _posts/2014-01-02-introducing-lanyon.md Reading: _posts/2017-11-21-welcome-to-jekyll.markdown Reading: _posts/2018-01-14-boot-android-on-charge.md Reading: _posts/2013-12-31-whats-jekyll.md Skipping: _posts/2018-01-14-boot-android-on-charge.md has a future date Generating: Jekyll::Archives::Archives finished in 0.000122873 seconds. Generating: JekyllFeed::Generator finished in 0.000468846 seconds. ...

从日志中我发现 jeklly 跳过了

2018-01-14-boot-android-on-charge.md

,因为它有一个未来的日期。


9
投票
一个可能的原因是前文中指定的

date

不包含时区偏移量,在这种情况下它默认为UTC,而不是您所期望的本地计算机的时区。我在这上面浪费了一个小时,直到 UTC“赶上”我当前的本地时区 BST。

我还没有找到明确的答案,但我认为前面的日期必须以 UTC 格式给出,并带有时区偏移量(如果省略,则默认为零)。

因此,

date: 2018-05-03 12:34:27

 
采用 UTC,无论您身在世界何处,也无论 timezone
 中的 
_config.yml
 设置如何。

所以要小心指定这样的日期时间:

date: 2018-05-03 12:34:27 +0100
    

2
投票
或者,如果您不是在

_site 文件夹中查找,而是直接在带有帖子列表的博客主页上查找,那么它也可以是浏览器缓存。


2
投票
我已经为我的博客编写了表达这些规则的 Rspec 测试:

require 'spec_helper' require 'yaml' # Documented at https://jekyllrb.com/news/2017/03/02/jekyll-3-4-1-released/ post_regex = %r!^(?:.+/)*(\d{2,4}-\d{1,2}-\d{1,2})-(.*)(\.[^.]+)$! def date_in_front_matter(date) return date if date.is_a?(Date) return date.to_date if date.is_a?(Time) return Date.parse(date) if date.is_a?(String) end describe 'posts' do Dir.glob("_posts/*md").each do |file| basename = File.basename(file) context basename do front_matter = YAML.load(File.read(file).split(/---/)[1]) it 'filename must match documented post regex' do expect(basename).to match post_regex end it 'date in file name same day as date in front matter' do date_in_file_name = Date.parse(post_regex.match(basename).captures[0]) expect(date_in_front_matter(front_matter['date'])).to eq date_in_file_name end it 'title in front matter should not contain a colon' do expect(front_matter['title']).to_not match /:/ end it 'front matter should not have published: false' do expect(front_matter['published']).to_not be false end end end end

这可能对其他人有用,因为我由于日期等错误而损失了很多时间。

这些测试以及 Rspec 配置的其余部分可以在上下文中看到

这里


2
投票
再补充一个原因,当您将一篇文章从

_drafts

移动到
_post
时,有时需要删除
_site
才能重新生成文章。 

就我而言,经常会发生

_site

在重新生成之前不会被完全删除,因此新文章不会出现。

无论如何

rm -rf _site

bundle exec jekyll serve
 有效:)


1
投票
如果您无法跟踪

--verbose

 中的文件,并且该文件被默默忽略,请尝试删除 
collections_dir
 文件中的 
config.yml
。这为我解决了这个问题。


0
投票
我的帖子也没有出现,错误是,在我的名字中我使用了一个点,例如

2017-10-18-test.2.md

这是不被接受的,你必须使用
2017-10-18-test2.md


0
投票
如果您检查了前言,一切似乎都很好,甚至

jekyll build --verbose

 也没有透露任何内容(在我的例子中,它只是表现得好像该文件根本不存在,甚至没有将其列为排除对象) ,检查文件的编码。显然,它需要是没有签名的
UTF-8
。如果它是 
UTF-8 BOM
(或某些文本编辑器所称的 
UTF-8 with Signature
),那么它将被默默地忽略。更糟糕的是,一些编辑器会将两种类型都显示为 
UTF-8
,使得差异更难发现。


0
投票
就我而言,我启用了增量构建,这导致了此问题,请务必检查它。

© www.soinside.com 2019 - 2024. All rights reserved.