Jekyll post 未生成
Jekyll post not generated
我正在尝试向我的 Jekyll 站点添加一个新的 post,但是当我 运行 jekyll serve
.
时,我在生成的页面上看不到它
没有生成 Jekyll post 的一些常见原因是什么?
- post没有放在
_posts
目录下
- The post has incorrect title. 帖子应命名为
YEAR-MONTH-DAY-title.MARKUP
(请注意 MARKUP
扩展名 ,通常为 .md
或 .markdown
)
- post 的日期在未来。 您可以通过在 [=16] 中设置
future: true
使 post 可见=] (documentation)
- The post has
published: false
in its front matter. 设置为 true
.
The title contains a :
character. 将其替换为 :
。 在 jekyll 3.8.3
中有效(可能在其他 'recent' 发布).
如果您不是在 _site 文件夹中查找,而是直接在包含帖子列表的博客主页上查找,它也可以是浏览器缓存。
我的 post 也没有出现,错误是,在我的名字中我使用了一个点,例如2017-10-18-test.2.md
.
这不被接受,你必须使用2017-10-18-test2.md
。
您可以使用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.
...
我从日志中发现跳过了 jekyll 2018-01-14-boot-android-on-charge.md
因为它有一个未来的日期。
一个可能的原因是前文中指定的date
不包含时区偏移量,在这种情况下它默认为UTC,而不是您可能期望的本地机器的时区。我浪费了一个小时,直到 UTC "caught up" 与我当前的本地时区 BST。
我还没有找到明确的答案,但我认为前面的日期必须以 UTC 格式给出,并带有时区偏移(如果省略则默认为零)。
所以 date: 2018-05-03 12:34:27
是 UTC,无论您身在何处,也无论 _config.yml
中的 timezone
设置如何。
所以要小心指定这样的日期时间:
date: 2018-05-03 12:34:27 +0100
我已经为我的博客编写了 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
这可能对其他人有用,因为日期等方面的错别字让我浪费了很多时间
可以在上下文 here.
中查看这些测试以及 Rspec 配置的其余部分
再补充一个原因,当您将文章从 _drafts
移动到 _post
时,您有时需要删除 _site
才能重新生成文章。
在我的情况下,经常发生 _site
不会在 re-generation 之前被完全删除,所以新文章不会出现。
无论如何 rm -rf _site
和 bundle exec jekyll serve
有效:)
如果你已经检查了你的前面的事情,一切似乎都很好,甚至 jekyll build --verbose
也没有透露任何东西(在我的情况下,它只是表现得好像文件根本不存在,而不是甚至将其列为排除项),请检查文件的编码。显然,它需要 UTF-8
没有签名。它是 UTF-8 BOM
(或某些文本编辑器所称的 UTF-8 with Signature
),然后它将被默默地忽略。更糟糕的是,一些编辑器会将这两种类型都显示为 UTF-8
,这使得差异更难发现。
如果您无法跟踪 --verbose
中的文件并且文件被静默忽略,请尝试删除 config.yml
文件中的 collections_dir
。这解决了我的问题。
我正在尝试向我的 Jekyll 站点添加一个新的 post,但是当我 运行 jekyll serve
.
没有生成 Jekyll post 的一些常见原因是什么?
- post没有放在
_posts
目录下 - The post has incorrect title. 帖子应命名为
YEAR-MONTH-DAY-title.MARKUP
(请注意MARKUP
扩展名 ,通常为.md
或.markdown
) - post 的日期在未来。 您可以通过在 [=16] 中设置
future: true
使 post 可见=] (documentation) - The post has
published: false
in its front matter. 设置为true
. The title contains a在 jekyll:
character. 将其替换为:
。3.8.3
中有效(可能在其他 'recent' 发布).
如果您不是在 _site 文件夹中查找,而是直接在包含帖子列表的博客主页上查找,它也可以是浏览器缓存。
我的 post 也没有出现,错误是,在我的名字中我使用了一个点,例如2017-10-18-test.2.md
.
这不被接受,你必须使用2017-10-18-test2.md
。
您可以使用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.
...
我从日志中发现跳过了 jekyll 2018-01-14-boot-android-on-charge.md
因为它有一个未来的日期。
一个可能的原因是前文中指定的date
不包含时区偏移量,在这种情况下它默认为UTC,而不是您可能期望的本地机器的时区。我浪费了一个小时,直到 UTC "caught up" 与我当前的本地时区 BST。
我还没有找到明确的答案,但我认为前面的日期必须以 UTC 格式给出,并带有时区偏移(如果省略则默认为零)。
所以 date: 2018-05-03 12:34:27
是 UTC,无论您身在何处,也无论 _config.yml
中的 timezone
设置如何。
所以要小心指定这样的日期时间:
date: 2018-05-03 12:34:27 +0100
我已经为我的博客编写了 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
这可能对其他人有用,因为日期等方面的错别字让我浪费了很多时间
可以在上下文 here.
中查看这些测试以及 Rspec 配置的其余部分再补充一个原因,当您将文章从 _drafts
移动到 _post
时,您有时需要删除 _site
才能重新生成文章。
在我的情况下,经常发生 _site
不会在 re-generation 之前被完全删除,所以新文章不会出现。
无论如何 rm -rf _site
和 bundle exec jekyll serve
有效:)
如果你已经检查了你的前面的事情,一切似乎都很好,甚至 jekyll build --verbose
也没有透露任何东西(在我的情况下,它只是表现得好像文件根本不存在,而不是甚至将其列为排除项),请检查文件的编码。显然,它需要 UTF-8
没有签名。它是 UTF-8 BOM
(或某些文本编辑器所称的 UTF-8 with Signature
),然后它将被默默地忽略。更糟糕的是,一些编辑器会将这两种类型都显示为 UTF-8
,这使得差异更难发现。
如果您无法跟踪 --verbose
中的文件并且文件被静默忽略,请尝试删除 config.yml
文件中的 collections_dir
。这解决了我的问题。