diff options
author | Jordan Bracco <href@random.sh> | 2022-03-31 03:59:05 +0000 |
---|---|---|
committer | Jordan Bracco <href@random.sh> | 2022-03-31 03:59:05 +0000 |
commit | f836ca4eab996342b1873dd708bbb0cd0e2def24 (patch) | |
tree | 1c6e9f5ccd48512c2e5d4e2591735cd451bbcaf7 /bin/render-markdown |
Diffstat (limited to 'bin/render-markdown')
-rwxr-xr-x | bin/render-markdown | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/bin/render-markdown b/bin/render-markdown new file mode 100755 index 0000000..84be150 --- /dev/null +++ b/bin/render-markdown @@ -0,0 +1,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}) |