From 50dedd3578474d02d8a9604fc01def1664a17de6 Mon Sep 17 00:00:00 2001 From: urosm Date: Mon, 18 Mar 2024 21:08:43 +0100 Subject: [PATCH] update `pandoc` data dir --- pandoc/bavbavhaus.net.lua | 421 +++++++++--------- pandoc/templates/bavbavhaus.net.html5 | 8 +- pandoc/templates/bavbavhaus.net.partial.html5 | 2 +- 3 files changed, 221 insertions(+), 210 deletions(-) diff --git a/pandoc/bavbavhaus.net.lua b/pandoc/bavbavhaus.net.lua index 4dc12ef..9941bf6 100644 --- a/pandoc/bavbavhaus.net.lua +++ b/pandoc/bavbavhaus.net.lua @@ -1,240 +1,249 @@ -local path = pandoc.path -local MetaList = pandoc.MetaList -local Link = pandoc.Link - INPUT_FILES = (function(prog) - local insert = table.insert - local input_files = {} - local pfile = io.popen(prog) - for filename in pfile:lines() do - insert(input_files, filename) - end - pfile:close() - return input_files + print("[INFO] bavbavhaus.net: collecting input files") + local insert = table.insert + local input_files = {} + local pfile = io.popen(prog) + for filename in pfile:lines() do + insert(input_files, filename) + end + pfile:close() + return input_files end)("ls -t *.md") OUTPUT_FILES = (function(pattern) - local split_extension = pandoc.path.split_extension - local insert = table.insert - local output_files = {} - for _,filename in ipairs(INPUT_FILES) do - local basename = split_extension(filename) - insert(output_files, (pattern):format(basename)) - end - return output_files + print("[INFO] bavbavhaus.net: collecting output files") + local split_extension = pandoc.path.split_extension + local insert = table.insert + local output_files = {} + for _,filename in ipairs(INPUT_FILES) do + local basename = split_extension(filename) + insert(output_files, (pattern):format(basename)) + end + return output_files end)("public_html/%s.html") -print("[INFO] bavbavhaus.net: reading pages") PAGES = (function() - local pages = MetaList({}) - function pages:get(input_file) - return self:find_if(function(page) - return page["meta"]["input_file"] == input_file - end) - end - local read = pandoc.read - local ropts = pandoc.ReaderOptions({}) - for _,input_file in ipairs(INPUT_FILES) do - print("[INFO] bavbavhaus.net: reading page: " .. input_file) - local f = io.open(input_file) - if not f then goto continue end - pages:insert(read(f:read("a"), "markdown", ropts)) - f:close() - ::continue:: - end - return pages + print("[INFO] bavbavhaus.net: reading pages") + local pages = pandoc.MetaList({}) + function pages:get(input_file) + return self:find_if(function(page) + return page["meta"]["input_file"] == input_file + end) + end + local read = pandoc.read + local ropts = pandoc.ReaderOptions({}) + for _,input_file in ipairs(INPUT_FILES) do + print("[INFO] bavbavhaus.net: reading page: " .. input_file) + local f = io.open(input_file) + if not f then goto continue end + pages:insert(read(f:read("a"), "markdown", ropts)) + f:close() + ::continue:: + end + return pages end)() -print("[INFO] bavbavhaus.net: updating metadata") do - for i,page in ipairs(PAGES) do - local input_file = INPUT_FILES[i] - local output_file = OUTPUT_FILES[i] - PAGES[i] = page:walk({ - Meta = function(meta) - meta["input_file"] = input_file - meta["output_file"] = output_file - meta["url"] = input_file - meta["title"] = meta["title"] or input_file - return meta - end, - }) - end + print("[INFO] bavbavhaus.net: updating pages metadata") + for i,page in ipairs(PAGES) do + local input_file = INPUT_FILES[i] + local output_file = OUTPUT_FILES[i] + PAGES[i] = page:walk({ + Meta = function(meta) + meta["input_file"] = input_file + meta["output_file"] = output_file + meta["url"] = input_file + meta["title"] = meta["title"] or input_file + return meta + end, + }) + end +end + +do + print("[INFO] bavbavhaus.net: processing citations") + local csl = "pandoc/csl/chicago-fullnote-sl" + local citeproc = pandoc.utils.citeproc + for i,page in ipairs(PAGES) do + PAGES[i] = page:walk({ + Meta = function(meta) + meta["csl"] = csl + return meta + end, + Pandoc = function(doc) + return citeproc(doc) + end + }) + end end -print("[INFO] bavbavhaus.net: scanning pages for internal links") BACKLINKS, FORELINKS = (function(pages) - local MetaList = pandoc.MetaList - local MetaMap = pandoc.MetaMap - local backlinks = MetaMap({}) - local forelinks = MetaMap({}) - for i,page in ipairs(pages) do - local input_file = page["meta"]["input_file"] - page:walk({ - Link = function(link) - if not PAGES:get(link.target) then return end - if input_file == link.target then return end - if not backlinks[link.target] then - backlinks[link.target] = MetaList({}) - end - if not forelinks[input_file] then - forelinks[input_file] = MetaList({}) - end - if not backlinks[link.target]:includes(input_file) then - backlinks[link.target]:insert(input_file) - end - if not forelinks[input_file]:includes(link.target) then - forelinks[input_file]:insert(link.target) - end - end - }) - end - return backlinks, forelinks + print("[INFO] bavbavhaus.net: scanning pages for internal links") + local MetaList = pandoc.MetaList + local MetaMap = pandoc.MetaMap + local backlinks = MetaMap({}) + local forelinks = MetaMap({}) + for i,page in ipairs(pages) do + local input_file = page["meta"]["input_file"] + page:walk({ + Link = function(link) + if not PAGES:get(link.target) then return end + if input_file == link.target then return end + if not backlinks[link.target] then + backlinks[link.target] = MetaList({}) + end + if not forelinks[input_file] then + forelinks[input_file] = MetaList({}) + end + if not backlinks[link.target]:includes(input_file) then + backlinks[link.target]:insert(input_file) + end + if not forelinks[input_file]:includes(link.target) then + forelinks[input_file]:insert(link.target) + end + end + }) + end + return backlinks, forelinks end)(PAGES) -print("[INFO] bavbavhaus.net: updating index page") do - local index = "index.md" - FORELINKS[index] = MetaList({}) - for i,page in ipairs(PAGES) do - if PAGES[i]["meta"]["input_file"] == index then goto continue end - FORELINKS[index]:insert(page["meta"]["input_file"]) - ::continue:: - end + print("[INFO] bavbavhaus.net: updating index page") + local index = "index.md" + FORELINKS[index] = pandoc.MetaList({}) + for i,page in ipairs(PAGES) do + if PAGES[i]["meta"]["input_file"] == index then goto continue end + FORELINKS[index]:insert(page["meta"]["input_file"]) + ::continue:: + end end -print("[INFO] bavbavhaus.net: updating link targets") do - function update_target(target) - return ("%s.html#start"):format(path.split_extension(target)) - end - for i,page in ipairs(PAGES) do - PAGES[i] = page:walk({ - Meta = function(meta) - meta["url"] = update_target(meta["url"]) - return meta - end, - Link = function(link) - if not PAGES:get(link.target) then return end - link.target = update_target(link.target) - return Link(link.content, link.target) - end - }) - end -end - -print("[INFO] bavbavhaus.net: processing citations") -do - local csl = "pandoc/csl/chicago-fullnote-sl" - local citeproc = pandoc.utils.citeproc - for i,page in ipairs(PAGES) do - PAGES[i] = page:walk({ - Meta = function(meta) - meta["csl"] = csl - return meta - end, - Pandoc = function(doc) - return citeproc(doc) - end - }) - end + print("[INFO] bavbavhaus.net: updating link targets") + local split_extension = pandoc.path.split_extension + function update_target(target) + return ("%s.html#start"):format(split_extension(target)) + end + local Link = pandoc.Link + for i,page in ipairs(PAGES) do + PAGES[i] = page:walk({ + Meta = function(meta) + meta["url"] = update_target(meta["url"]) + return meta + end, + Link = function(link) + if not PAGES:get(link.target) then return end + link.target = update_target(link.target) + return Link(link.content, link.target) + end + }) + end end SITEMAP = (function() - print("[INFO] bavbavhaus.net: generating sitemap") - local sitemap = pandoc.MetaList({}) - for _,page in ipairs(PAGES) do - local meta = page["meta"] - sitemap:insert(Link(meta["title"], meta["url"])) - end - return sitemap + print("[INFO] bavbavhaus.net: generating sitemap") + local sitemap = pandoc.MetaList({}) + local Link = pandoc.Link + for _,page in ipairs(PAGES) do + local meta = page["meta"] + sitemap:insert(Link(meta["title"], meta["url"])) + end + return sitemap end)() do - print("[INFO] bavbavhaus.net: updating metadata (sitemap)") - for i,page in ipairs(PAGES) do - PAGES[i] = page:walk({ - Meta = function(meta) - meta["sitemap"] = SITEMAP - return meta - end - }) - end + print("[INFO] bavbavhaus.net: updating sitemap metadata") + for i,page in ipairs(PAGES) do + PAGES[i] = page:walk({ + Meta = function(meta) + meta["sitemap"] = SITEMAP + return meta + end + }) + end end do - print("[INFO] bavbavhaus.net: writing partial pages") - local write = pandoc.write - local WriterOptions = pandoc.WriterOptions - local compile = pandoc.template.compile - local partial_template = (function(filepath) + print("[INFO] bavbavhaus.net: updating backlinks metadata") + local compile = pandoc.template.compile + local partial_template = (function(filepath) + local f = io.open(filepath) + if not f then return end + local template = f:read("a") + f:close() + return compile(template) + end)("pandoc/templates/bavbavhaus.net.partial.html5") + local MetaList = pandoc.MetaList + local RawBlock = pandoc.RawBlock + local write = pandoc.write + local WriterOptions = pandoc.WriterOptions + for i,page in ipairs(PAGES) do + local input_file = page["meta"]["input_file"] + if not BACKLINKS[input_file] then goto continue end + local backlinks = MetaList({}) + for _,backlink in ipairs(BACKLINKS[input_file]) do + backlinks:insert(RawBlock("html5", write( + PAGES:get(backlink), + "html5", + WriterOptions({ + identifier_prefix = "back/" .. backlink, + table_of_contents = true, + template = partial_template + }) + ))) + end + PAGES[i] = page:walk({ + Meta = function(meta) + meta["backlinks"] = backlinks + return meta + end + }) + ::continue:: + end + print("[INFO] bavbavhaus.net: updating forelinks metadata") + for i,page in ipairs(PAGES) do + local input_file = page["meta"]["input_file"] + if not FORELINKS[input_file] then goto continue end + local forelinks = MetaList({}) + for _,forelink in ipairs(FORELINKS[input_file]) do + forelinks:insert(RawBlock("html5", write( + PAGES:get(forelink), + "html5", + WriterOptions({ + identifier_prefix = "fore/" .. forelink, + table_of_contents = true, + template = partial_template + }) + ))) + end + PAGES[i] = page:walk({ + Meta = function(meta) + meta["forelinks"] = forelinks + return meta + end + }) + ::continue:: + end +end + +do + print("[INFO] bavbavhaus.net: writing pages") + local compile = pandoc.template.compile + local WriterOptions = pandoc.WriterOptions + local write = pandoc.write + local wopts = WriterOptions({ + table_of_contents = true, + template = (function(filepath) local f = io.open(filepath) if not f then return end local template = f:read("a") f:close() return compile(template) - end)("pandoc/templates/bavbavhaus.net.partial.html5") - local RawBlock = pandoc.RawBlock - for i,page in ipairs(PAGES) do - local input_file = page["meta"]["input_file"] - if not BACKLINKS[input_file] then goto continue end - local backlinks = MetaList({}) - for _,backlink in ipairs(BACKLINKS[input_file]) do - backlinks:insert(RawBlock("html5", write( - PAGES:get(backlink), - "html5", - WriterOptions({ - identifier_prefix = "back/" .. backlink, - table_of_contents = true, - template = partial_template - }) - ))) - end - PAGES[i] = page:walk({ - Meta = function(meta) - meta["backlinks"] = backlinks - return meta - end - }) - ::continue:: - end - for i,page in ipairs(PAGES) do - local input_file = page["meta"]["input_file"] - if not FORELINKS[input_file] then goto continue end - local forelinks = MetaList({}) - for _,forelink in ipairs(FORELINKS[input_file]) do - forelinks:insert(RawBlock("html5", write( - PAGES:get(forelink), - "html5", - WriterOptions({ - identifier_prefix = "fore/" .. forelink, - table_of_contents = true, - template = partial_template - }) - ))) - end - PAGES[i] = page:walk({ - Meta = function(meta) - meta["forelinks"] = forelinks - return meta - end - }) - ::continue:: - end - print("[INFO] bavbavhaus.net: writing pages") - local wopts = WriterOptions({ - table_of_contents = true, - template = (function(filepath) - local f = io.open(filepath) - if not f then return end - local template = f:read("a") - f:close() - return compile(template) - end)("pandoc/templates/bavbavhaus.net.html5") - }) - for _,page in ipairs(PAGES) do - local f = io.open(page["meta"]["output_file"], "w") - f:write(write(page, "html", wopts)) - f:close() - end + end)("pandoc/templates/bavbavhaus.net.html5") + }) + for i,page in ipairs(PAGES) do + local f = io.open(page["meta"]["output_file"], "w") + f:write(write(page, "html", wopts)) + f:close() + end end diff --git a/pandoc/templates/bavbavhaus.net.html5 b/pandoc/templates/bavbavhaus.net.html5 index 2de9d3c..52aebe0 100644 --- a/pandoc/templates/bavbavhaus.net.html5 +++ b/pandoc/templates/bavbavhaus.net.html5 @@ -6,6 +6,8 @@ $if(description-meta)$ +$else$ + $endif$ bavbavhaus.net/$title$ @@ -14,8 +16,8 @@ $endif$
$if(sitemap)$ -
-