Skip to content

Commit 7c1d938

Browse files
committed
Load YAML frontmatter.
1 parent 2d58507 commit 7c1d938

File tree

8 files changed

+552
-92
lines changed

8 files changed

+552
-92
lines changed

lib/nanoc/github.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44

55
module Nanoc
66
module Github
7-
Error = Class.new(StandardError)
7+
REGEX = /^(?<metadata>---\s*\n.*?\n?)^(---\s*$\n?)/m
88

99
class Source < Nanoc::DataSource
1010
identifier :github
1111

1212
def items
1313
repository_items.map do |item|
14-
identifier = Nanoc::Identifier.new("/#{item[:name]}")
15-
new_item(decode(item[:content]), {}, identifier)
14+
identifier = Nanoc::Identifier.new("/#{item[:name]}")
15+
metadata, data = decode(item[:content])
16+
17+
new_item(data, metadata, identifier)
1618
end
1719
end
1820

@@ -23,7 +25,11 @@ def client
2325
end
2426

2527
def decode(content)
26-
Base64.decode64(content)
28+
content = Base64.decode64(content)
29+
matchdata = content.match(REGEX)
30+
metadata = matchdata ? YAML.load(matchdata[:metadata]) : {}
31+
32+
[metadata, content.gsub(REGEX, '')]
2733
end
2834

2935
def repository_items

test/fixtures/test_frontmatter.yml

Lines changed: 219 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)