我正在尝试向我的 Jekyll 网站添加新帖子,但当我运行
jekyll serve
时,我无法在生成的页面上看到它。
Jekyll 帖子无法生成的常见原因有哪些?
_posts
目录中。collections_dir
从.
(默认)更改为my_col_folder
时,您的所有帖子都必须移动到my_col_folder/_posts
jekyll默认值YEAR-MONTH-DAY-title.MARKUP
(注意扩展名MARKUP
,通常是.md
或
.markdown
)
future: true
(文档)中设置_config.yml
来使帖子可见
published: false
。 将其设置为
true
。
:
字符。将其替换为:
。
3.8.3
(可能在其他“最近”版本中)。
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
,因为它有一个未来的日期。
date
不包含时区偏移量,在这种情况下它默认为UTC,而不是您所期望的本地计算机的时区。我在这上面浪费了一个小时,直到 UTC“赶上”我当前的本地时区 BST。我还没有找到明确的答案,但我认为前面的日期必须以 UTC 格式给出,并带有时区偏移量(如果省略,则默认为零)。
因此,
date: 2018-05-03 12:34:27
采用 UTC,无论您身在世界何处,也无论
timezone
中的
_config.yml
设置如何。所以要小心指定这样的日期时间:
date: 2018-05-03 12:34:27 +0100
_site 文件夹中查找,而是直接在带有帖子列表的博客主页上查找,那么它也可以是浏览器缓存。
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 配置的其余部分可以在上下文中看到
这里。
_drafts
移动到
_post
时,有时需要删除
_site
才能重新生成文章。就我而言,经常会发生
_site
在重新生成之前不会被完全删除,因此新文章不会出现。无论如何
rm -rf _site
和
bundle exec jekyll serve
有效:)
--verbose
中的文件,并且该文件被默默忽略,请尝试删除
collections_dir
文件中的
config.yml
。这为我解决了这个问题。
2017-10-18-test.2.md
。这是不被接受的,你必须使用
2017-10-18-test2.md
。
jekyll build --verbose
也没有透露任何内容(在我的例子中,它只是表现得好像该文件根本不存在,甚至没有将其列为排除对象) ,检查文件的编码。显然,它需要是没有签名的
UTF-8
。如果它是
UTF-8 BOM
(或某些文本编辑器所称的
UTF-8 with Signature
),那么它将被默默地忽略。更糟糕的是,一些编辑器会将两种类型都显示为
UTF-8
,使得差异更难发现。