summaryrefslogtreecommitdiff
path: root/bin/render-markdown
blob: 84be15024be0f854d979934e9d22f27bd4ae1c8c (plain) (blame)
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
#!/usr/bin/env ruby
require 'kramdown'
require 'yaml'

@site_name = ENV["SITE_NAME"]
@url = ENV["URL"]

template = ARGV.shift
source_file = ARGV.first
source = ARGF.read
meta = {}

if (md = source.match(/^(?<metadata>---\s*\n.*?\n?)^(---\s*$\n?)/m))
  source = md.post_match
  meta = YAML.load(md[:metadata]) || {}
end

body = Kramdown::Document.new(source).to_html

if meta["title"]
  title="#{@site_name} / #{meta["title"]}"
else
  title=@site_name
end

puts(File.read(template) % {body: body, title: title, built_at: Time.now.utc, source_file: source_file, site_name: @site_name, url: @url})