aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/fill_layout.lua
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+orbitalquark@users.noreply.github.com>2020-09-08 23:11:24 -0400
committerGravatar mitchell <70453897+orbitalquark@users.noreply.github.com>2020-09-08 23:11:24 -0400
commit60e98cdfdacc7f2973e557fc6d0b28e6f9a6b139 (patch)
tree72c9b1f686c0f3c07cc209d4b91bcfa017ff2d16 /scripts/fill_layout.lua
parent0ecb986767b5aeec567f01241b0c06f67c28433c (diff)
Changed processing pipeline for manually generating documentation.
Diffstat (limited to 'scripts/fill_layout.lua')
-rwxr-xr-xscripts/fill_layout.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/scripts/fill_layout.lua b/scripts/fill_layout.lua
new file mode 100755
index 00000000..34219858
--- /dev/null
+++ b/scripts/fill_layout.lua
@@ -0,0 +1,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('%%', '%%%%'))))