blob: 3421985842618cd57558ddf844157b62d2d50b12 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#!/usr/bin/lua
-- Filters the given file through markdown, inserts it into the template
-- specified by stdin by replacing simple {{ variable }} tags, and outputs the
-- result to stdout.
-- Filter the file through markdown using TOC generation in order to get header
-- anchors, but ignore the actual TOC.
local name = arg[1]
local f = io.open(name, 'r')
local markdown = f:read('*a')
f:close()
local p = io.popen('markdown -f toc -T ' .. name)
local html = p:read('*a'):match('^.-\n</ul>\n(.+)$')
p:close()
-- Fill in HTML layout (stdin) with markdown output and print the result.
local title, content = '{{ page.title }}', '{{ content }}'
io.write(io.stdin:read('*a'):gsub(title, html:match('<h%d.->([^<]+)')):
gsub(content, (html:gsub('%%', '%%%%'))))
|