update `pandoc` data dir
parent
3f4a70a435
commit
493fc63f31
|
@ -11,6 +11,7 @@ local data = f:read("a")
|
||||||
f:close()
|
f:close()
|
||||||
local visited = {}
|
local visited = {}
|
||||||
read(data):walk({ Link = function (link)
|
read(data):walk({ Link = function (link)
|
||||||
|
if not link.target:find(".%.md$") then return end
|
||||||
local f = io.open(link.target)
|
local f = io.open(link.target)
|
||||||
if f == nil then return else f:close() end
|
if f == nil then return else f:close() end
|
||||||
if visited[link.target] then return end
|
if visited[link.target] then return end
|
||||||
|
|
|
@ -12,6 +12,7 @@ local function collect (fp)
|
||||||
local data = f:read("a")
|
local data = f:read("a")
|
||||||
f:close()
|
f:close()
|
||||||
read(data):walk({ Link = function (link)
|
read(data):walk({ Link = function (link)
|
||||||
|
if not link.target:find(".%.md$") then return end
|
||||||
local f = io.open(link.target)
|
local f = io.open(link.target)
|
||||||
if f == nil then return else f:close() end
|
if f == nil then return else f:close() end
|
||||||
if visited[link.target] then return end
|
if visited[link.target] then return end
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
---
|
---
|
||||||
from: markdown
|
from: markdown
|
||||||
|
toc: true
|
||||||
|
citeproc: true
|
||||||
|
csl: chicago-fullnote-sl
|
||||||
filters:
|
filters:
|
||||||
- insert_bodypart.lua
|
- localize_quotes.lua
|
||||||
- insert_linkparts.lua
|
- update_internal_targets.lua
|
||||||
|
- insert_parts.lua
|
||||||
template: bavbavhaus.net.html5
|
template: bavbavhaus.net.html5
|
||||||
to: html
|
to: html
|
||||||
...
|
...
|
||||||
|
|
|
@ -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 }
|
|
||||||
}
|
|
|
@ -7,18 +7,18 @@ os.setlocale("C")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
{ Meta = function (meta)
|
{ Meta = function (meta)
|
||||||
if not meta["linkparts"] then return end
|
if not meta["parts"] then return end
|
||||||
if type(meta["linkparts"]) == "string" then
|
if type(meta["parts"]) == "string" then
|
||||||
meta["linkparts"] = { meta["linkparts"] }
|
meta["parts"] = { meta["parts"] }
|
||||||
end
|
end
|
||||||
local links = MetaList({})
|
local links = MetaList({})
|
||||||
for _,fp in ipairs(meta["linkparts"]) do
|
for _,fp in ipairs(meta["parts"]) do
|
||||||
local f = assert(io.open(fp), "\n" ..
|
local f = assert(io.open(fp), "\n" ..
|
||||||
"[ERROR] could not open " .. fp .. " for reading.")
|
"[ERROR] could not open " .. fp .. " for reading.")
|
||||||
links:insert(RawBlock("html5", f:read("a")))
|
links:insert(RawBlock("html5", f:read("a")))
|
||||||
f:close()
|
f:close()
|
||||||
end
|
end
|
||||||
meta["linkparts"] = links
|
meta["parts"] = links
|
||||||
return meta
|
return meta
|
||||||
end }
|
end }
|
||||||
}
|
}
|
|
@ -1,44 +1,46 @@
|
||||||
local l = require("pandoc.logging")
|
-- local l = require("pandoc.logging")
|
||||||
local read = pandoc.read
|
local read = pandoc.read
|
||||||
|
|
||||||
assert(#arg == 2, "\n" ..
|
assert(#arg == 2, "\n" ..
|
||||||
"[ERROR] usage: pandoc lua sitemap.lua <index file> <output file>")
|
"[ERROR] usage: pandoc lua sitemap.lua <index file> <output file>")
|
||||||
|
local index_file, output_file = table.unpack(arg)
|
||||||
|
|
||||||
local node_list = {}
|
local node_list, node_map = {}, {}
|
||||||
local graph_map = {}
|
|
||||||
local function collect (fp)
|
local function collect (fp)
|
||||||
local f = assert(io.open(fp), "\n" ..
|
local f = assert(io.open(fp), "\n" ..
|
||||||
"[ERROR] could not open " .. fp .. " for reading.")
|
"[ERROR] could not open " .. fp .. " for reading.")
|
||||||
table.insert(node_list, fp)
|
table.insert(node_list, fp)
|
||||||
graph_map[fp] = { order = #node_list, nodes = {} }
|
node_map[fp] = { order = #node_list, nodes = {} }
|
||||||
local data = f:read("a")
|
local data = f:read("a")
|
||||||
f:close()
|
f:close()
|
||||||
local visited = {}
|
local visited = {}
|
||||||
read(data):walk({ Link = function (link)
|
read(data):walk({ Link = function (link)
|
||||||
|
if not link.target:find(".%.md$") then return end
|
||||||
local f = io.open(link.target)
|
local f = io.open(link.target)
|
||||||
if f == nil then return else f:close() end
|
if f == nil then return else f:close() end
|
||||||
if visited[link.target] then return end
|
if visited[link.target] then return end
|
||||||
visited[link.target] = true
|
visited[link.target] = true
|
||||||
table.insert(graph_map[fp]["nodes"], link.target)
|
table.insert(node_map[fp]["nodes"], link.target)
|
||||||
if not graph_map[link.target] then collect(link.target) end
|
if not node_map[link.target] then collect(link.target) end
|
||||||
end })
|
end })
|
||||||
end
|
end
|
||||||
|
collect(index_file)
|
||||||
collect(arg[1])
|
|
||||||
|
|
||||||
local L = {
|
local L = {
|
||||||
SW = ".", L = "<", W = "-", NW = ".",
|
L = "<",
|
||||||
S = "|", X = " ", N = "|",
|
R = ">",
|
||||||
SE = "'", R = ">", E = "-", NE = "'",
|
NW = ",", N = "-", NE = ".",
|
||||||
|
W = "|", X = " ", E = "|",
|
||||||
|
SW = "'", S = "-", SE = "'",
|
||||||
}
|
}
|
||||||
|
|
||||||
local layout = {}
|
local arma = {}
|
||||||
local r_wing = {}
|
local list = {}
|
||||||
local l_wing = {}
|
local armb = {}
|
||||||
for i,node in ipairs(node_list) do
|
for i,node in ipairs(node_list) do
|
||||||
r_wing[i] = {}
|
arma[i] = {}
|
||||||
layout[i] = node
|
list[i] = node
|
||||||
l_wing[i] = {}
|
armb[i] = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function reverse (t)
|
local function reverse (t)
|
||||||
|
@ -53,7 +55,7 @@ local function find_free_col(wing, a, b)
|
||||||
while true do
|
while true do
|
||||||
for i=a,b do
|
for i=a,b do
|
||||||
local cell = wing[i][col]
|
local cell = wing[i][col]
|
||||||
if cell ~= nil and cell ~= L["X"] then
|
if cell ~= nil and cell ~= L.X then
|
||||||
goto continue
|
goto continue
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -65,80 +67,98 @@ local function find_free_col(wing, a, b)
|
||||||
end
|
end
|
||||||
|
|
||||||
for _,node in ipairs(node_list) do
|
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
|
for _,node in ipairs(a_node["nodes"]) do
|
||||||
local a = a_node["order"]
|
local a = a_node["order"]
|
||||||
local b = graph_map[node]["order"]
|
local b = node_map[node]["order"]
|
||||||
|
|
||||||
local i1 = 1
|
local i1 = 1
|
||||||
local ia = math.min(a,b)
|
local ia = math.min(a,b)
|
||||||
local ib = math.max(a,b)
|
local ib = math.max(a,b)
|
||||||
local iz = #node_list
|
local iz = #node_list
|
||||||
local wing = a < b and r_wing or l_wing
|
local wing = a < b and arma or armb
|
||||||
local r_first, l_first = true, true
|
|
||||||
local first = a < b and r_first or l_first
|
|
||||||
|
|
||||||
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
|
if col == 1 then col = 2 end
|
||||||
local a_row = wing[ia]
|
local a_row = wing[ia]
|
||||||
if a_row[1] == nil or a_row[1] == " " then
|
if a_row[1] == nil or a_row[1] == L.X then
|
||||||
a_row[1] = a < b and "-" or "<"
|
a_row[1] = a < b and L.N or L.L
|
||||||
end
|
end
|
||||||
for i=1,col-1 do
|
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
|
end
|
||||||
a_row[col] = "."
|
a_row[col] = a < b and L.NW or L.NE
|
||||||
for i=ia+1,ib-1 do
|
for i=ia+1,ib-1 do
|
||||||
for j=1,col-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
|
end
|
||||||
wing[i][col] = "|"
|
wing[i][col] = L.W
|
||||||
end
|
end
|
||||||
local b_row = wing[ib]
|
local b_row = wing[ib]
|
||||||
if b_row[1] == nil or b_row[1] == " " then
|
if b_row[1] == nil or b_row[1] == L.X then
|
||||||
b_row[1] = a < b and ">" or "-"
|
b_row[1] = a < b and L.R or L.S
|
||||||
end
|
end
|
||||||
for i=1,col-1 do
|
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
|
end
|
||||||
b_row[col] = "'"
|
b_row[col] = L.SW
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- write
|
-- construct data lines
|
||||||
local data = {}
|
local lines = {}
|
||||||
table.insert(data, "<nav id=\"sitemap\">")
|
table.insert(lines, "<article id=\"sitemap\" class=\"post tail\">")
|
||||||
table.insert(data, "<header>")
|
table.insert(lines, "<header>")
|
||||||
table.insert(data, "<h1>sitemap</h1>")
|
table.insert(lines, "<h1>sitemap</h1>")
|
||||||
table.insert(data, "</header>")
|
table.insert(lines, "</header>")
|
||||||
table.insert(data, "<pre>")
|
table.insert(lines, "<pre>")
|
||||||
|
|
||||||
-- pad right wing
|
-- pad right wing
|
||||||
local r_wing_pad = 1
|
local arma_pad = 1
|
||||||
for _,len in pairs(r_wing) do
|
for _,len in pairs(arma) do
|
||||||
if #len > r_wing_pad then r_wing_pad = #len end
|
if #len > arma_pad then arma_pad = #len end
|
||||||
end
|
end
|
||||||
-- pad node names
|
-- pad node names
|
||||||
local node_pad = 1
|
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
|
if s:len() > node_pad then node_pad = s:len() end
|
||||||
end
|
end
|
||||||
|
|
||||||
for i,v in ipairs(layout) do
|
for i,v in ipairs(list) do
|
||||||
local row = {}
|
local row = {}
|
||||||
local v = ("%-"..node_pad.."s"):format(v)
|
local v = ("%-"..node_pad.."s"):format(v)
|
||||||
local a = v:gsub("(.+)%.md", "<a href=\"%1.html\">%0</a>")
|
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, (("%"..arma_pad.."s"):format(table.concat(reverse(arma[i])))))
|
||||||
table.insert(row, ((" %s "):format(a)))
|
table.insert(row, ((" %s "):format(a)))
|
||||||
table.insert(row,(table.concat(l_wing[i])))
|
table.insert(row, (table.concat(armb[i])))
|
||||||
|
|
||||||
table.insert(data,table.concat(row))
|
table.insert(lines, table.concat(row))
|
||||||
end
|
end
|
||||||
|
table.insert(lines, "</pre>")
|
||||||
|
table.insert(lines, "</article>")
|
||||||
|
local data = table.concat(lines, "\n")
|
||||||
|
|
||||||
table.insert(data, "</pre>")
|
-- read existing data from output_file
|
||||||
table.insert(data, "</nav>")
|
local f = assert(io.open(output_file), "\n" ..
|
||||||
|
"[ERROR] could not open " .. output_file .. " for reading.")
|
||||||
local f = assert(io.open(arg[2], "w"), "\n" ..
|
local data_old = f:read("a")
|
||||||
"[ERROR] could not open " .. arg[2] .. " for writing.")
|
|
||||||
f:write(table.concat(data, "\n"))
|
|
||||||
f:close()
|
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
|
||||||
|
|
|
@ -24,7 +24,9 @@ $endif$
|
||||||
<header>
|
<header>
|
||||||
<h1><a href="$url$">$pagetitle$</a></h1>
|
<h1><a href="$url$">$pagetitle$</a></h1>
|
||||||
$if(abstract)$
|
$if(abstract)$
|
||||||
|
<div class="abstract">
|
||||||
$abstract$
|
$abstract$
|
||||||
|
</div>
|
||||||
$endif$
|
$endif$
|
||||||
</header>
|
</header>
|
||||||
$if(toc)$
|
$if(toc)$
|
||||||
|
@ -37,7 +39,7 @@ $table-of-contents$
|
||||||
$endif$
|
$endif$
|
||||||
$body$
|
$body$
|
||||||
</article>
|
</article>
|
||||||
$for(linkparts)$
|
$for(parts)$
|
||||||
$it$
|
$it$
|
||||||
$endfor$
|
$endfor$
|
||||||
</main>
|
</main>
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
<header>
|
<header>
|
||||||
<h1><a href="$url$">$pagetitle$</a></h1>
|
<h1><a href="$url$">$pagetitle$</a></h1>
|
||||||
$if(abstract)$
|
$if(abstract)$
|
||||||
|
<div class="abstract">
|
||||||
$abstract$
|
$abstract$
|
||||||
|
</div>
|
||||||
$endif$
|
$endif$
|
||||||
</header>
|
</header>
|
||||||
$if(toc)$
|
$if(toc)$
|
||||||
|
|
Loading…
Reference in New Issue