diff --git a/pandoc/collect_links.lua b/pandoc/collect_links.lua index 22e507d..5b692fd 100644 --- a/pandoc/collect_links.lua +++ b/pandoc/collect_links.lua @@ -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 diff --git a/pandoc/collect_notes.lua b/pandoc/collect_notes.lua index c00e373..a7c670b 100644 --- a/pandoc/collect_notes.lua +++ b/pandoc/collect_notes.lua @@ -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 diff --git a/pandoc/defaults/bavbavhaus.net.yaml b/pandoc/defaults/bavbavhaus.net.yaml index d07c5d1..0a73554 100644 --- a/pandoc/defaults/bavbavhaus.net.yaml +++ b/pandoc/defaults/bavbavhaus.net.yaml @@ -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 ... diff --git a/pandoc/filters/insert_bodypart.lua b/pandoc/filters/insert_bodypart.lua deleted file mode 100644 index 6316cdf..0000000 --- a/pandoc/filters/insert_bodypart.lua +++ /dev/null @@ -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 } -} diff --git a/pandoc/filters/insert_linkparts.lua b/pandoc/filters/insert_parts.lua similarity index 67% rename from pandoc/filters/insert_linkparts.lua rename to pandoc/filters/insert_parts.lua index e50583d..9ead744 100644 --- a/pandoc/filters/insert_linkparts.lua +++ b/pandoc/filters/insert_parts.lua @@ -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 } } diff --git a/pandoc/sitemap.lua b/pandoc/sitemap.lua index d870296..1870988 100644 --- a/pandoc/sitemap.lua +++ b/pandoc/sitemap.lua @@ -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 ") +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, "") - -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 diff --git a/pandoc/templates/bavbavhaus.net.html5 b/pandoc/templates/bavbavhaus.net.html5 index 4fe200e..965a4ba 100644 --- a/pandoc/templates/bavbavhaus.net.html5 +++ b/pandoc/templates/bavbavhaus.net.html5 @@ -24,7 +24,9 @@ $endif$

$pagetitle$

$if(abstract)$ +
$abstract$ +
$endif$
$if(toc)$ @@ -37,7 +39,7 @@ $table-of-contents$ $endif$ $body$ -$for(linkparts)$ +$for(parts)$ $it$ $endfor$ diff --git a/pandoc/templates/bavbavhaus.net.part.html5 b/pandoc/templates/bavbavhaus.net.part.html5 index 6ecbc41..fd1c28f 100644 --- a/pandoc/templates/bavbavhaus.net.part.html5 +++ b/pandoc/templates/bavbavhaus.net.part.html5 @@ -2,7 +2,9 @@

$pagetitle$

$if(abstract)$ +
$abstract$ +
$endif$
$if(toc)$