Jekyllのお勉強 -YAML部分と記事本文を分離する正規表現-
JekyllのYAML部分と記事本文を分離していると思われる正規表現を確認する。
正規表現
/\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
こんな感じらしい
# Read the YAML frontmatter.
#
# base - The String path to the dir containing the file.
# name - The String filename of the file.
#
# Returns nothing.
def read_yaml(base, name)
begin
self.content = File.read(File.join(base, name))
if self.content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
self.content = $POSTMATCH
self.data = YAML.safe_load($1)
end
rescue SyntaxError => e
puts "YAML Exception reading #{File.join(base, name)}: #{e.message}"
rescue Exception => e
puts "Error reading file #{File.join(base, name)}: #{e.message}"
end
self.data ||= {}
end参考
Related contents
TECH
2013.11.24
TECH
2013.05.20
TECH
2013.04.24
TECH
2013.02.03
TECH
2017.01.08
TECH
2015.08.30
TECH
2014.12.13
TECH
2014.12.02