diff options
| author | Robert Günzler <r@gnzler.io> | 2026-09-22 17:58:42 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2026-09-22 22:37:51 +0200 |
| commit | 6d868d605c43e38373f1b88f99901c3e43b69cdb (patch) | |
| tree | f0ac9ef2a819400a01b3806e094cb4c4a9d6c97f | |
| parent | 5bc242742e1225c7c3b87a31c2c2a3998ac18685 (diff) | |
| download | site-6d868d605c43e38373f1b88f99901c3e43b69cdb.tar.gz | |
format preproc script and add comment
Signed-off-by: Robert Günzler <r@gnzler.io>
| -rw-r--r-- | preproc.lua | 89 |
1 files changed, 50 insertions, 39 deletions
diff --git a/preproc.lua b/preproc.lua index 7be9a48..e9aa366 100644 --- a/preproc.lua +++ b/preproc.lua @@ -1,47 +1,58 @@ ---@diagnostic disable: undefined-global -- see https://pandoc.org/lua-filters.html return { - Link = function(link) - -- set target="_blank" for outgoing links (open them in new tab) - if string.match(link.target, "gzr.im") == nil then - table.insert(link.attributes, { "target", "_blank" }) - end - return link - end, - Pandoc = function(doc) - local front = {} + Link = function(link) + -- set target="_blank" for outgoing links (open them in new tab) + if string.match(link.target, "gzr.im") == nil then + table.insert(link.attributes, { "target", "_blank" }) + end + return link + end, + Pandoc = function(doc) + local front = {} - local toc = pandoc.structure.table_of_contents(doc) - if doc.meta.toc and toc then - table.insert(front, pandoc.RawBlock("html5", '<nav class="table-of-contents capital">')) - table.insert(front, pandoc.RawBlock("html5", "<ol>")) - -- insert jump to top - table.insert(front, pandoc.Link("back to top", "#top")) - -- create custom toc - toc:walk({ - Link = function(e) - table.insert(front, pandoc.RawBlock("html5", "<li>")) - table.insert(front, e) - table.insert(front, pandoc.RawBlock("html5", "</li>")) - end, - }) - table.insert(front, pandoc.RawBlock("html5", "</ol>")) - table.insert(front, pandoc.RawBlock("html5", "</nav>")) - end + -- add a comment + table.insert( + front, + pandoc.RawBlock( + "html5", + "<!-- Generated file, you may edit and discard " + .. pandoc.path.filename(PANDOC_STATE.input_files[1]) + .. " :) -->" + ) + ) - -- insert date blocks - if doc.meta.date then - table.insert(front, pandoc.RawBlock("html5", '<span class="date">')) - table.insert(front, doc.meta.date) - table.insert(front, pandoc.RawBlock("html5", "</span>")) - end + local toc = pandoc.structure.table_of_contents(doc) + if doc.meta.toc and toc then + table.insert(front, pandoc.RawBlock("html5", '<nav class="table-of-contents capital">')) + table.insert(front, pandoc.RawBlock("html5", "<ol>")) + -- insert jump to top + table.insert(front, pandoc.Link("back to top", "#top")) + -- create custom toc + toc:walk({ + Link = function(e) + table.insert(front, pandoc.RawBlock("html5", "<li>")) + table.insert(front, e) + table.insert(front, pandoc.RawBlock("html5", "</li>")) + end, + }) + table.insert(front, pandoc.RawBlock("html5", "</ol>")) + table.insert(front, pandoc.RawBlock("html5", "</nav>")) + end - -- prepend front stuffs - for i = #front, 1, -1 do - table.insert(doc.blocks, 1, front[i]) - end + -- insert date blocks + if doc.meta.date then + table.insert(front, pandoc.RawBlock("html5", '<span class="date">')) + table.insert(front, doc.meta.date) + table.insert(front, pandoc.RawBlock("html5", "</span>")) + end - -- return finished ast - return doc - end, + -- prepend front stuffs + for i = #front, 1, -1 do + table.insert(doc.blocks, 1, front[i]) + end + + -- return finished ast + return doc + end, } |