about summary refs log tree commit diff
path: root/preproc.lua
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2024-10-28 12:15:35 +0100
committerRobert Günzler <r@gnzler.io>2024-11-02 14:33:14 +0100
commit24460c250816e9b1dc06c5348f4c470bc98f7153 (patch)
treecc4a58df59b4c114a00ced6e4a86543148a19220 /preproc.lua
parent5e48e1de8ba3caf684709fa519f8b94970d4de44 (diff)
downloadsite-24460c250816e9b1dc06c5348f4c470bc98f7153.tar.gz
renmae front.lua to preproc.lua
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to 'preproc.lua')
-rw-r--r--preproc.lua40
1 files changed, 40 insertions, 0 deletions
diff --git a/preproc.lua b/preproc.lua
new file mode 100644
index 0000000..6bfa8c5
--- /dev/null
+++ b/preproc.lua
@@ -0,0 +1,40 @@
+---@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", '<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
+
+        -- 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,
+}