diff options
author | mitchell <70453897+orbitalquark@users.noreply.github.com> | 2020-09-04 23:33:02 -0400 |
---|---|---|
committer | mitchell <70453897+orbitalquark@users.noreply.github.com> | 2020-09-04 23:33:02 -0400 |
commit | 7a98e09ae4b424031835cdb8986d93926c7ac0bd (patch) | |
tree | 65dcff0f522310d142943701fd4b60df29ffcf24 /scripts | |
parent | e6feddc952ecb232ac0304ffa698ae707ac39cdb (diff) |
Moved all top-level .md files into docs/ except README.md.
Also fixed lack of header anchors in generated HTML.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/gen_doc.lua | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/scripts/gen_doc.lua b/scripts/gen_doc.lua index 1d317935..fff69a12 100755 --- a/scripts/gen_doc.lua +++ b/scripts/gen_doc.lua @@ -1,11 +1,23 @@ #!/usr/bin/lua --- Part of a pipeline that fills in simple {{ variable }} templates when --- generating documentation offline. --- cat file.md | markdown | gen_doc > file.html +-- Filters the given file through markdown, replaces simple {{ variable }} +-- templates, and saves the result to an HTML file of the same name for offline +-- documentation generation. -local html = io.read('*a') -local f = io.open('../docs/_layouts/default.html') -io.write( - f:read('*a'):gsub('{{ page.title }}', html:match('<h%d>([^<]+)')): - gsub('{{ content }}', (html:gsub('%%', '%%%%')))) +-- 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 with markdown content. +f = io.open('../docs/_layouts/default.html') +html = f:read('*a'):gsub('{{ page.title }}', html:match('<h%d.->([^<]+)')): + gsub('{{ content }}', (html:gsub('%%', '%%%%'))) +f:close() + +-- Write to HTML file. +io.open(name:gsub('^(.+)%.md$', '%1.html'), 'wb'):write(html):close() |