diff options
| author | Robert Günzler <r@gnzler.io> | 2024-10-16 15:24:41 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2024-10-16 15:40:15 +0200 |
| commit | 23d862844c4cce0100bedd20a8b521ab9f8f822d (patch) | |
| tree | 42a2ba6299adb6bf322271fe72fc2bcd5cad8723 /front.lua | |
| parent | cbba4db4e7f716ba799dc2c65f2df6ddc433c1ac (diff) | |
| download | site-23d862844c4cce0100bedd20a8b521ab9f8f822d.tar.gz | |
use pandoc filter to generate date & toc
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to 'front.lua')
| -rw-r--r-- | front.lua | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/front.lua b/front.lua new file mode 100644 index 0000000..a6046b1 --- /dev/null +++ b/front.lua @@ -0,0 +1,42 @@ +---@diagnostic disable: undefined-global +-- see https://pandoc.org/lua-filters.html +return { + 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", '<section class="table-of-contents">')) + table.insert(front, pandoc.RawBlock("html5", '<nav class="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>")) + table.insert(front, pandoc.RawBlock("html5", "</section>")) + 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 + + -- prepend front stuffs + for i = #front, 1, -1 do + table.insert(doc.blocks, 1, front[i]) + end + + -- return finished ast + return doc + end, +} |