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
6 回答
The post is not placed in the
_posts
directory.The post has incorrect title.帖子应命名为
YEAR-MONTH-DAY-title.MARKUP
(注意MARKUP
扩展名,通常为.md
或.markdown
)The post's date is in the future. 您可以通过在
_config.yml
(documentation)中设置future: true
来使帖子可见The post has published: false in its front matter.将其设置为
true
.Headers 包含:字符 . 将其替换为&#58 . 适用于jekyll
3.8.3
(可能还有其他'recent'版本) .您可以使用
jekyll build --verbose
详细查看构建过程 .例如输出:
从日志我发现jeklly跳过
2018-01-14-boot-android-on-charge.md
因为它有一个未来的日期 .或者它也可以是浏览器缓存,如果您不在_site文件夹中,而是直接在博客的主页上显示帖子列表 .
我已经为我的博客写了表达这些规则的Rspec测试:
这可能对其他人有用,因为我因为日期中的拼写错误而失去了很多时间 .
这些测试以及Rspec配置的其余部分可以在上下文here中看到 .
一个可能的原因是前面指定的
date
不包含时区偏移,在这种情况下,它默认为UTC,而不是您可能期望的本地计算机的时区 . 我浪费了一个小时,直到UTC "caught up"与我当前的当地时区BST .我还没有找到明确的答案,但我认为前面的日期必须以UTC给出时区偏移量(如果省略则默认为零) .
所以
date: 2018-05-03 12:34:27
is in UTC 无论你在世界的哪个地方,都与_config.yml
中的timezone
设置无关 .所以要小心指定这样的日期时间:
我的帖子也没出现错误,在我的名字中我使用了一个点,例如
2017-10-18-test.2.md
.这是不被接受的,你必须使用
2017-10-18-test2.md
.