update `pandoc` data dir

urosm 2024-03-18 21:08:43 +01:00
parent ca484be94f
commit 50dedd3578
3 changed files with 221 additions and 210 deletions

View File

@ -1,240 +1,249 @@
local path = pandoc.path
local MetaList = pandoc.MetaList
local Link = pandoc.Link
INPUT_FILES = (function(prog) INPUT_FILES = (function(prog)
local insert = table.insert print("[INFO] bavbavhaus.net: collecting input files")
local input_files = {} local insert = table.insert
local pfile = io.popen(prog) local input_files = {}
for filename in pfile:lines() do local pfile = io.popen(prog)
insert(input_files, filename) for filename in pfile:lines() do
end insert(input_files, filename)
pfile:close() end
return input_files pfile:close()
return input_files
end)("ls -t *.md") end)("ls -t *.md")
OUTPUT_FILES = (function(pattern) OUTPUT_FILES = (function(pattern)
local split_extension = pandoc.path.split_extension print("[INFO] bavbavhaus.net: collecting output files")
local insert = table.insert local split_extension = pandoc.path.split_extension
local output_files = {} local insert = table.insert
for _,filename in ipairs(INPUT_FILES) do local output_files = {}
local basename = split_extension(filename) for _,filename in ipairs(INPUT_FILES) do
insert(output_files, (pattern):format(basename)) local basename = split_extension(filename)
end insert(output_files, (pattern):format(basename))
return output_files end
return output_files
end)("public_html/%s.html") end)("public_html/%s.html")
print("[INFO] bavbavhaus.net: reading pages")
PAGES = (function() PAGES = (function()
local pages = MetaList({}) print("[INFO] bavbavhaus.net: reading pages")
function pages:get(input_file) local pages = pandoc.MetaList({})
return self:find_if(function(page) function pages:get(input_file)
return page["meta"]["input_file"] == input_file return self:find_if(function(page)
end) return page["meta"]["input_file"] == input_file
end end)
local read = pandoc.read end
local ropts = pandoc.ReaderOptions({}) local read = pandoc.read
for _,input_file in ipairs(INPUT_FILES) do local ropts = pandoc.ReaderOptions({})
print("[INFO] bavbavhaus.net: reading page: " .. input_file) for _,input_file in ipairs(INPUT_FILES) do
local f = io.open(input_file) print("[INFO] bavbavhaus.net: reading page: " .. input_file)
if not f then goto continue end local f = io.open(input_file)
pages:insert(read(f:read("a"), "markdown", ropts)) if not f then goto continue end
f:close() pages:insert(read(f:read("a"), "markdown", ropts))
::continue:: f:close()
end ::continue::
return pages end
return pages
end)() end)()
print("[INFO] bavbavhaus.net: updating metadata")
do do
for i,page in ipairs(PAGES) do print("[INFO] bavbavhaus.net: updating pages metadata")
local input_file = INPUT_FILES[i] for i,page in ipairs(PAGES) do
local output_file = OUTPUT_FILES[i] local input_file = INPUT_FILES[i]
PAGES[i] = page:walk({ local output_file = OUTPUT_FILES[i]
Meta = function(meta) PAGES[i] = page:walk({
meta["input_file"] = input_file Meta = function(meta)
meta["output_file"] = output_file meta["input_file"] = input_file
meta["url"] = input_file meta["output_file"] = output_file
meta["title"] = meta["title"] or input_file meta["url"] = input_file
return meta meta["title"] = meta["title"] or input_file
end, return meta
}) end,
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 end
print("[INFO] bavbavhaus.net: scanning pages for internal links")
BACKLINKS, FORELINKS = (function(pages) BACKLINKS, FORELINKS = (function(pages)
local MetaList = pandoc.MetaList print("[INFO] bavbavhaus.net: scanning pages for internal links")
local MetaMap = pandoc.MetaMap local MetaList = pandoc.MetaList
local backlinks = MetaMap({}) local MetaMap = pandoc.MetaMap
local forelinks = MetaMap({}) local backlinks = MetaMap({})
for i,page in ipairs(pages) do local forelinks = MetaMap({})
local input_file = page["meta"]["input_file"] for i,page in ipairs(pages) do
page:walk({ local input_file = page["meta"]["input_file"]
Link = function(link) page:walk({
if not PAGES:get(link.target) then return end Link = function(link)
if input_file == link.target then return end if not PAGES:get(link.target) then return end
if not backlinks[link.target] then if input_file == link.target then return end
backlinks[link.target] = MetaList({}) if not backlinks[link.target] then
end backlinks[link.target] = MetaList({})
if not forelinks[input_file] then end
forelinks[input_file] = MetaList({}) if not forelinks[input_file] then
end forelinks[input_file] = MetaList({})
if not backlinks[link.target]:includes(input_file) then end
backlinks[link.target]:insert(input_file) if not backlinks[link.target]:includes(input_file) then
end backlinks[link.target]:insert(input_file)
if not forelinks[input_file]:includes(link.target) then end
forelinks[input_file]:insert(link.target) if not forelinks[input_file]:includes(link.target) then
end forelinks[input_file]:insert(link.target)
end end
}) end
end })
return backlinks, forelinks end
return backlinks, forelinks
end)(PAGES) end)(PAGES)
print("[INFO] bavbavhaus.net: updating index page")
do do
local index = "index.md" print("[INFO] bavbavhaus.net: updating index page")
FORELINKS[index] = MetaList({}) local index = "index.md"
for i,page in ipairs(PAGES) do FORELINKS[index] = pandoc.MetaList({})
if PAGES[i]["meta"]["input_file"] == index then goto continue end for i,page in ipairs(PAGES) do
FORELINKS[index]:insert(page["meta"]["input_file"]) if PAGES[i]["meta"]["input_file"] == index then goto continue end
::continue:: FORELINKS[index]:insert(page["meta"]["input_file"])
end ::continue::
end
end end
print("[INFO] bavbavhaus.net: updating link targets")
do do
function update_target(target) print("[INFO] bavbavhaus.net: updating link targets")
return ("%s.html#start"):format(path.split_extension(target)) local split_extension = pandoc.path.split_extension
end function update_target(target)
for i,page in ipairs(PAGES) do return ("%s.html#start"):format(split_extension(target))
PAGES[i] = page:walk({ end
Meta = function(meta) local Link = pandoc.Link
meta["url"] = update_target(meta["url"]) for i,page in ipairs(PAGES) do
return meta PAGES[i] = page:walk({
end, Meta = function(meta)
Link = function(link) meta["url"] = update_target(meta["url"])
if not PAGES:get(link.target) then return end return meta
link.target = update_target(link.target) end,
return Link(link.content, link.target) Link = function(link)
end if not PAGES:get(link.target) then return end
}) link.target = update_target(link.target)
end return Link(link.content, link.target)
end end
})
print("[INFO] bavbavhaus.net: processing citations") end
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
end end
SITEMAP = (function() SITEMAP = (function()
print("[INFO] bavbavhaus.net: generating sitemap") print("[INFO] bavbavhaus.net: generating sitemap")
local sitemap = pandoc.MetaList({}) local sitemap = pandoc.MetaList({})
for _,page in ipairs(PAGES) do local Link = pandoc.Link
local meta = page["meta"] for _,page in ipairs(PAGES) do
sitemap:insert(Link(meta["title"], meta["url"])) local meta = page["meta"]
end sitemap:insert(Link(meta["title"], meta["url"]))
return sitemap end
return sitemap
end)() end)()
do do
print("[INFO] bavbavhaus.net: updating metadata (sitemap)") print("[INFO] bavbavhaus.net: updating sitemap metadata")
for i,page in ipairs(PAGES) do for i,page in ipairs(PAGES) do
PAGES[i] = page:walk({ PAGES[i] = page:walk({
Meta = function(meta) Meta = function(meta)
meta["sitemap"] = SITEMAP meta["sitemap"] = SITEMAP
return meta return meta
end end
}) })
end end
end end
do do
print("[INFO] bavbavhaus.net: writing partial pages") print("[INFO] bavbavhaus.net: updating backlinks metadata")
local write = pandoc.write local compile = pandoc.template.compile
local WriterOptions = pandoc.WriterOptions local partial_template = (function(filepath)
local compile = pandoc.template.compile local f = io.open(filepath)
local partial_template = (function(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) local f = io.open(filepath)
if not f then return end if not f then return end
local template = f:read("a") local template = f:read("a")
f:close() f:close()
return compile(template) return compile(template)
end)("pandoc/templates/bavbavhaus.net.partial.html5") end)("pandoc/templates/bavbavhaus.net.html5")
local RawBlock = pandoc.RawBlock })
for i,page in ipairs(PAGES) do for i,page in ipairs(PAGES) do
local input_file = page["meta"]["input_file"] local f = io.open(page["meta"]["output_file"], "w")
if not BACKLINKS[input_file] then goto continue end f:write(write(page, "html", wopts))
local backlinks = MetaList({}) f:close()
for _,backlink in ipairs(BACKLINKS[input_file]) do end
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 end

View File

@ -6,6 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
$if(description-meta)$ $if(description-meta)$
<meta name="description" content="$description-meta$" /> <meta name="description" content="$description-meta$" />
$else$
<meta name="description" content="bavbavhaus.net" />
$endif$ $endif$
<title>bavbavhaus.net/$title$</title> <title>bavbavhaus.net/$title$</title>
<link rel="icon" href="favicon.svg" /> <link rel="icon" href="favicon.svg" />
@ -14,8 +16,8 @@ $endif$
<body> <body>
<main> <main>
$if(sitemap)$ $if(sitemap)$
<article class="sitemap"> <article>
<nav id="sitemap"> <nav class="sitemap">
<h1><a href="index.html#start">bavbavhaus.net</a></h1> <h1><a href="index.html#start">bavbavhaus.net</a></h1>
<ul> <ul>
$for(sitemap)$ $for(sitemap)$
@ -35,7 +37,7 @@ $endif$
<h1><a href="$url$">$title$</a></h1> <h1><a href="$url$">$title$</a></h1>
$endif$ $endif$
$if(toc)$ $if(toc)$
<nav> <nav class="toc">
$if(toc-title)$ $if(toc-title)$
<h2>$toc-title$</h2> <h2>$toc-title$</h2>
$endif$ $endif$

View File

@ -2,7 +2,7 @@ $if(title)$
<h1><a href="$url$">$title$</a></h1> <h1><a href="$url$">$title$</a></h1>
$endif$ $endif$
$if(toc)$ $if(toc)$
<nav> <nav class="toc">
$if(toc-title)$ $if(toc-title)$
<h2>$toc-title$</h2> <h2>$toc-title$</h2>
$endif$ $endif$