update `pandoc` data dir

master
urosm 2024-05-17 15:26:37 +02:00
parent 3f4a70a435
commit 493fc63f31
8 changed files with 94 additions and 80 deletions

View File

@ -11,6 +11,7 @@ local data = f:read("a")
f:close()
local visited = {}
read(data):walk({ Link = function (link)
if not link.target:find(".%.md$") then return end
local f = io.open(link.target)
if f == nil then return else f:close() end
if visited[link.target] then return end

View File

@ -12,6 +12,7 @@ local function collect (fp)
local data = f:read("a")
f:close()
read(data):walk({ Link = function (link)
if not link.target:find(".%.md$") then return end
local f = io.open(link.target)
if f == nil then return else f:close() end
if visited[link.target] then return end

View File

@ -1,8 +1,12 @@
---
from: markdown
toc: true
citeproc: true
csl: chicago-fullnote-sl
filters:
- insert_bodypart.lua
- insert_linkparts.lua
- localize_quotes.lua
- update_internal_targets.lua
- insert_parts.lua
template: bavbavhaus.net.html5
to: html
...

View File

@ -1,16 +0,0 @@
local RawBlock = pandoc.RawBlock
SCRIPT_NAME = "insert_bodypart.lua"
os.setlocale("C")
return {
{ Meta = function (meta)
if not meta["bodypart"] then return end
local fp = meta["bodypart"]
local f = assert(io.open(fp), "\n" ..
"[ERROR] could not open " .. fp .. " for reading.")
meta["bodypart"] = RawBlock("html5", f:read("a"))
f:close()
return meta
end }
}

View File

@ -7,18 +7,18 @@ os.setlocale("C")
return {
{ Meta = function (meta)
if not meta["linkparts"] then return end
if type(meta["linkparts"]) == "string" then
meta["linkparts"] = { meta["linkparts"] }
if not meta["parts"] then return end
if type(meta["parts"]) == "string" then
meta["parts"] = { meta["parts"] }
end
local links = MetaList({})
for _,fp in ipairs(meta["linkparts"]) do
for _,fp in ipairs(meta["parts"]) do
local f = assert(io.open(fp), "\n" ..
"[ERROR] could not open " .. fp .. " for reading.")
links:insert(RawBlock("html5", f:read("a")))
f:close()
end
meta["linkparts"] = links
meta["parts"] = links
return meta
end }
}

View File

@ -1,44 +1,46 @@
local l = require("pandoc.logging")
-- local l = require("pandoc.logging")
local read = pandoc.read
assert(#arg == 2, "\n" ..
"[ERROR] usage: pandoc lua sitemap.lua <index file> <output file>")
local index_file, output_file = table.unpack(arg)
local node_list = {}
local graph_map = {}
local node_list, node_map = {}, {}
local function collect (fp)
local f = assert(io.open(fp), "\n" ..
"[ERROR] could not open " .. fp .. " for reading.")
table.insert(node_list, fp)
graph_map[fp] = { order = #node_list, nodes = {} }
node_map[fp] = { order = #node_list, nodes = {} }
local data = f:read("a")
f:close()
local visited = {}
read(data):walk({ Link = function (link)
if not link.target:find(".%.md$") then return end
local f = io.open(link.target)
if f == nil then return else f:close() end
if visited[link.target] then return end
visited[link.target] = true
table.insert(graph_map[fp]["nodes"], link.target)
if not graph_map[link.target] then collect(link.target) end
table.insert(node_map[fp]["nodes"], link.target)
if not node_map[link.target] then collect(link.target) end
end })
end
collect(arg[1])
collect(index_file)
local L = {
SW = ".", L = "<", W = "-", NW = ".",
S = "|", X = " ", N = "|",
SE = "'", R = ">", E = "-", NE = "'",
L = "<",
R = ">",
NW = ",", N = "-", NE = ".",
W = "|", X = " ", E = "|",
SW = "'", S = "-", SE = "'",
}
local layout = {}
local r_wing = {}
local l_wing = {}
local arma = {}
local list = {}
local armb = {}
for i,node in ipairs(node_list) do
r_wing[i] = {}
layout[i] = node
l_wing[i] = {}
arma[i] = {}
list[i] = node
armb[i] = {}
end
local function reverse (t)
@ -53,7 +55,7 @@ local function find_free_col(wing, a, b)
while true do
for i=a,b do
local cell = wing[i][col]
if cell ~= nil and cell ~= L["X"] then
if cell ~= nil and cell ~= L.X then
goto continue
end
end
@ -65,80 +67,98 @@ local function find_free_col(wing, a, b)
end
for _,node in ipairs(node_list) do
local a_node = graph_map[node]
local a_node = node_map[node]
for _,node in ipairs(a_node["nodes"]) do
local a = a_node["order"]
local b = graph_map[node]["order"]
local b = node_map[node]["order"]
local i1 = 1
local ia = math.min(a,b)
local ib = math.max(a,b)
local iz = #node_list
local wing = a < b and r_wing or l_wing
local r_first, l_first = true, true
local first = a < b and r_first or l_first
local wing = a < b and arma or armb
local col = find_free_col(wing, ia, ib)
local col = 1
while true do
for i=ia,ib do
local cell = wing[i][col]
if cell ~= nil and cell ~= L.X then
goto continue
end
end
break
::continue::
col = col + 1
end
if col == 1 then col = 2 end
local a_row = wing[ia]
if a_row[1] == nil or a_row[1] == " " then
a_row[1] = a < b and "-" or "<"
if a_row[1] == nil or a_row[1] == L.X then
a_row[1] = a < b and L.N or L.L
end
for i=1,col-1 do
if a_row[i] == nil or a_row[i] == L["X"] then a_row[i] = "-" end
if a_row[i] == nil or a_row[i] == L.X then a_row[i] = L.N end
end
a_row[col] = "."
a_row[col] = a < b and L.NW or L.NE
for i=ia+1,ib-1 do
for j=1,col-1 do
if wing[i][j] == nil then wing[i][j] = " " end
if wing[i][j] == nil then wing[i][j] = L.X end
end
wing[i][col] = "|"
wing[i][col] = L.W
end
local b_row = wing[ib]
if b_row[1] == nil or b_row[1] == " " then
b_row[1] = a < b and ">" or "-"
if b_row[1] == nil or b_row[1] == L.X then
b_row[1] = a < b and L.R or L.S
end
for i=1,col-1 do
if b_row[i] == nil or b_row[i] == L["X"] then b_row[i] = "-" end
if b_row[i] == nil or b_row[i] == L.X then b_row[i] = L.S end
end
b_row[col] = "'"
b_row[col] = L.SW
end
end
-- write
local data = {}
table.insert(data, "<nav id=\"sitemap\">")
table.insert(data, "<header>")
table.insert(data, "<h1>sitemap</h1>")
table.insert(data, "</header>")
table.insert(data, "<pre>")
-- construct data lines
local lines = {}
table.insert(lines, "<article id=\"sitemap\" class=\"post tail\">")
table.insert(lines, "<header>")
table.insert(lines, "<h1>sitemap</h1>")
table.insert(lines, "</header>")
table.insert(lines, "<pre>")
-- pad right wing
local r_wing_pad = 1
for _,len in pairs(r_wing) do
if #len > r_wing_pad then r_wing_pad = #len end
local arma_pad = 1
for _,len in pairs(arma) do
if #len > arma_pad then arma_pad = #len end
end
-- pad node names
local node_pad = 1
for _,s in pairs(layout) do
for _,s in pairs(list) do
if s:len() > node_pad then node_pad = s:len() end
end
for i,v in ipairs(layout) do
for i,v in ipairs(list) do
local row = {}
local v = ("%-"..node_pad.."s"):format(v)
local a = v:gsub("(.+)%.md", "<a href=\"%1.html\">%0</a>")
table.insert(row,(("%"..r_wing_pad.."s"):format(table.concat(reverse(r_wing[i])))))
table.insert(row,((" %s "):format(a)))
table.insert(row,(table.concat(l_wing[i])))
table.insert(row, (("%"..arma_pad.."s"):format(table.concat(reverse(arma[i])))))
table.insert(row, ((" %s "):format(a)))
table.insert(row, (table.concat(armb[i])))
table.insert(data,table.concat(row))
table.insert(lines, table.concat(row))
end
table.insert(lines, "</pre>")
table.insert(lines, "</article>")
local data = table.concat(lines, "\n")
table.insert(data, "</pre>")
table.insert(data, "</nav>")
local f = assert(io.open(arg[2], "w"), "\n" ..
"[ERROR] could not open " .. arg[2] .. " for writing.")
f:write(table.concat(data, "\n"))
-- read existing data from output_file
local f = assert(io.open(output_file), "\n" ..
"[ERROR] could not open " .. output_file .. " for reading.")
local data_old = f:read("a")
f:close()
-- write to output_file if data changed
if data ~= data_old then
local f = assert(io.open(output_file, "w"), "\n" ..
"[ERROR] could not open " .. output_file .. " for writing.")
f:write(data)
f:close()
end

View File

@ -24,7 +24,9 @@ $endif$
<header>
<h1><a href="$url$">$pagetitle$</a></h1>
$if(abstract)$
<div class="abstract">
$abstract$
</div>
$endif$
</header>
$if(toc)$
@ -37,7 +39,7 @@ $table-of-contents$
$endif$
$body$
</article>
$for(linkparts)$
$for(parts)$
$it$
$endfor$
</main>

View File

@ -2,7 +2,9 @@
<header>
<h1><a href="$url$">$pagetitle$</a></h1>
$if(abstract)$
<div class="abstract">
$abstract$
</div>
$endif$
</header>
$if(toc)$