-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexport-to-jekyll.rb
More file actions
executable file
·35 lines (27 loc) · 947 Bytes
/
export-to-jekyll.rb
File metadata and controls
executable file
·35 lines (27 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env ruby
require 'yaml'
articles = YAML.load_file("article-dump.yaml")
# KEYS: [:slug, :title, :summary, :published, :issue_number, :volume, :body]
def yaml_frontmatter(article)
front_matter = {
'layout' => 'post',
'title' => article[:title],
'date' => article[:published].strftime("%F"),
'categories' => 'articles',
'author' => author(article),
'permalink' => "articles/#{article[:slug]}",
'summary' => article[:summary],
'issue_number' => article[:issue_number]
}.to_yaml
front_matter << "---\n\n"
end
def author(article)
article[:summary][/\(w\. (.*)\)/, 1] || 'Gregory Brown'
end
def write_to_file(article)
date = article[:published].strftime("%F")
filename = "#{date}-#{article[:slug]}.md"
output = yaml_frontmatter(article) + article[:body]
File.write("_posts/#{filename}", output)
end
articles.each { |article| write_to_file(article) }