Jekyllのお勉強 -YAML部分と記事本文を分離する正規表現-
更新日:2023.05.05
作成日:2013.05.23
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
Jekyllのバージョンアップ

TECH
2013.05.20
Sublime Text 2にLiveReloadを導入してMarkdown Previewを快適に!!

TECH
2013.04.24
Octopressに「続きを読む」のプラグイン導入

TECH
2013.02.03
はてなダイアリーからJekyllへお引越し

TECH
2017.01.08
静的サイトジェネレータ「Hugo」でシンプルブログサイトを構築する

TECH
2015.08.30
JekyllからHugoへの移行ポイント

TECH
2014.12.13
Jekyllのタグとカテゴリを整理するために、一覧表示するWebアプリ(個人用)をつくった

TECH
2014.12.02
Jekyllに月別アーカイブを実装する