update `pandoc` data dir
parent
214ac615d2
commit
40b3eff98f
|
@ -3,232 +3,238 @@ 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
|
||||
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 insert = table.insert
|
||||
local output_files = {}
|
||||
for _,filename in ipairs(INPUT_FILES) do
|
||||
local basename = path.split_extension(filename)
|
||||
insert(output_files, (pattern):format(basename))
|
||||
end
|
||||
return 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:")
|
||||
do
|
||||
for i,input_file in ipairs(INPUT_FILES) do
|
||||
print(" " .. INPUT_FILES[i] .. " -> " .. OUTPUT_FILES[i])
|
||||
end
|
||||
end
|
||||
|
||||
print("[INFO] bavbavhaus.net: reading pages")
|
||||
PAGES = (function()
|
||||
local input_format = "markdown+wikilinks_title_before_pipe"
|
||||
local reader_options = pandoc.ReaderOptions({})
|
||||
local pages = MetaList({})
|
||||
function pages:get(input_file)
|
||||
return self:find_if(function(page)
|
||||
return page["meta"]["input_file"] == input_file
|
||||
end)
|
||||
end
|
||||
for i,input_file in ipairs(INPUT_FILES) do
|
||||
local f = io.open(input_file)
|
||||
if not f then goto continue end
|
||||
local page = pandoc.read(f:read("*a"), input_format, reader_options)
|
||||
f:close()
|
||||
pages:insert(page)
|
||||
::continue::
|
||||
end
|
||||
return pages
|
||||
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
|
||||
end)()
|
||||
|
||||
print("[INFO] bavbavhaus.net: updating metadata (initial)")
|
||||
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 pandoc.Inlines(pandoc.Str(input_file))
|
||||
return meta
|
||||
end,
|
||||
})
|
||||
end
|
||||
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
|
||||
|
||||
print("[INFO] bavbavhaus.net: scanning pages for internal links")
|
||||
BACKLINKS, FORELINKS = (function(pages)
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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: generating sitemap")
|
||||
SITEMAP = (function()
|
||||
local sitemap = MetaList({})
|
||||
for _,page in ipairs(PAGES) do
|
||||
local meta = page["meta"]
|
||||
sitemap:insert(Link(meta["title"], meta["url"]))
|
||||
end
|
||||
return sitemap
|
||||
end)()
|
||||
|
||||
|
||||
print("[INFO] bavbavhaus.net: processing citations")
|
||||
do
|
||||
local csl = "pandoc/csl/chicago-fullnote-sl"
|
||||
for i,page in ipairs(PAGES) do
|
||||
PAGES[i] = page:walk({
|
||||
Meta = function(meta)
|
||||
meta["csl"] = csl
|
||||
return meta
|
||||
end,
|
||||
Pandoc = function(doc)
|
||||
return pandoc.utils.citeproc(doc)
|
||||
end
|
||||
})
|
||||
end
|
||||
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: updating metadata (sitemap)")
|
||||
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
|
||||
end)()
|
||||
|
||||
do
|
||||
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 metadata (sitemap)")
|
||||
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")
|
||||
function get_template(path)
|
||||
local f = io.open(path)
|
||||
if not f then return end
|
||||
local template = f:read("*a")
|
||||
f:close()
|
||||
return pandoc.template.compile(template)
|
||||
end
|
||||
local write = pandoc.write
|
||||
local output_format = "html5"
|
||||
local WriterOptions = pandoc.WriterOptions
|
||||
local template = get_template("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
|
||||
local backlink_page = PAGES:get(backlink)
|
||||
local writer_options = WriterOptions({
|
||||
identifier_prefix = "back/" .. backlink,
|
||||
template = template
|
||||
})
|
||||
local text = pandoc.write(backlink_page, output_format, writer_options)
|
||||
backlinks:insert(RawBlock("html5", text))
|
||||
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)
|
||||
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
|
||||
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
|
||||
local forelink_page = PAGES:get(forelink)
|
||||
local writer_options = WriterOptions({
|
||||
identifier_prefix = "fore/" .. forelink,
|
||||
template = template
|
||||
})
|
||||
local text = pandoc.write(forelink_page, output_format, writer_options)
|
||||
forelinks:insert(RawBlock("html5", text))
|
||||
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
|
||||
PAGES[i] = page:walk({
|
||||
Meta = function(meta)
|
||||
meta["forelinks"] = forelinks
|
||||
return meta
|
||||
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")
|
||||
})
|
||||
::continue::
|
||||
end
|
||||
print("[INFO] bavbavhaus.net: writing pages")
|
||||
for _,page in ipairs(PAGES) do
|
||||
local f = io.open(page["meta"]["output_file"], "w")
|
||||
f:write(pandoc.write(page, output_format, WriterOptions({
|
||||
template = get_template("pandoc/templates/bavbavhaus.net.html5")
|
||||
})))
|
||||
f:close()
|
||||
end
|
||||
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
|
||||
|
|
|
@ -4,28 +4,14 @@
|
|||
<meta charset="utf-8" />
|
||||
<meta name="generator" content="pandoc" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
|
||||
$for(author-meta)$
|
||||
<meta name="author" content="$author-meta$" />
|
||||
$endfor$
|
||||
$if(date-meta)$
|
||||
<meta name="dcterms.date" content="$date-meta$" />
|
||||
$endif$
|
||||
$if(keywords)$
|
||||
<meta name="keywords" content="$for(keywords)$$keywords$$sep$, $endfor$" />
|
||||
$endif$
|
||||
$if(description-meta)$
|
||||
<meta name="description" content="$description-meta$" />
|
||||
$endif$
|
||||
<title>$if(title-prefix)$$title-prefix$ – $endif$$pagetitle$</title>
|
||||
<link rel="stylesheet" href="css/style.css" />
|
||||
$for(header-includes)$
|
||||
$header-includes$
|
||||
$endfor$
|
||||
<title>bavbavhaus.net/$title$</title>
|
||||
<link rel="icon" href="favicon.svg" />
|
||||
<link rel="stylesheet" href="css/style.css" />
|
||||
</head>
|
||||
<body>
|
||||
$for(include-before)$
|
||||
$include-before$
|
||||
$endfor$
|
||||
<main>
|
||||
$if(sitemap)$
|
||||
<article class="sitemap">
|
||||
|
@ -64,8 +50,5 @@ $endfor$
|
|||
</article>
|
||||
$endfor$
|
||||
</main>
|
||||
$for(include-after)$
|
||||
$include-after$
|
||||
$endfor$
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue