update `pandoc` data dir
parent
a412484b06
commit
ec34785d2c
|
@ -3,9 +3,9 @@ from: markdown
|
|||
toc: true
|
||||
citeproc: true
|
||||
csl: chicago-fullnote-sl
|
||||
filters:
|
||||
- localize_quotes.lua
|
||||
- update_internal_targets.lua
|
||||
template: bavbavhaus.net.part.html5
|
||||
to: html
|
||||
to: html5
|
||||
filters:
|
||||
- localize_quotes.lua
|
||||
- resolve_internal_links.part.lua
|
||||
...
|
||||
|
|
|
@ -3,10 +3,11 @@ from: markdown
|
|||
toc: true
|
||||
citeproc: true
|
||||
csl: chicago-fullnote-sl
|
||||
filters:
|
||||
- localize_quotes.lua
|
||||
- update_internal_targets.lua
|
||||
- insert_parts.lua
|
||||
reference-location: section
|
||||
template: bavbavhaus.net.html5
|
||||
to: html
|
||||
to: html5
|
||||
filters:
|
||||
- localize_quotes.lua
|
||||
- collect_internal_linked.lua
|
||||
- resolve_internal_links.lua
|
||||
...
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
assert(#arg == 2, "\n" ..
|
||||
"[ERROR] usage: pandoc lua bavbavhaus.lua <index file> <output file>")
|
||||
local index_file, output_file = table.unpack(arg)
|
||||
|
||||
local read = pandoc.read
|
||||
|
||||
NOTE_PATTERN = "^((.+)%.md)(#?.*)$"
|
||||
PAGE_REPL = "public_html/%2.html"
|
||||
PART_REPL = "public_html/%2.html.part"
|
||||
|
||||
local all = "all"
|
||||
local makefile = { [all] = {} }
|
||||
local function collect (fp)
|
||||
local f = assert(io.open(fp), "\n" ..
|
||||
"[ERROR] could not open " .. fp .. " for reading.")
|
||||
local data = f:read("a")
|
||||
f:close()
|
||||
|
||||
local page = fp:gsub(NOTE_PATTERN, PAGE_REPL)
|
||||
table.insert(makefile[all], page)
|
||||
makefile[page] = {}
|
||||
|
||||
read(data):walk({ Link = function (link)
|
||||
local fp, _slug, _anchor = link.target:match(NOTE_PATTERN)
|
||||
if not fp then return end
|
||||
local f = io.open(fp)
|
||||
if f == nil then return else f:close() end
|
||||
local target_page = link.target:gsub(NOTE_PATTERN, PAGE_REPL)
|
||||
if makefile[target_page] then return end
|
||||
local target_part = link.target:gsub(NOTE_PATTERN, PART_REPL)
|
||||
table.insert(makefile[page], target_part)
|
||||
collect(fp)
|
||||
end })
|
||||
end
|
||||
collect(index_file)
|
||||
|
||||
local lines = {}
|
||||
for k, v in pairs(makefile) do
|
||||
local parts = table.concat(v, " ")
|
||||
table.insert(lines, ("%s: %s"):format(k, parts))
|
||||
end
|
||||
|
||||
local f = assert(io.open(output_file, "w"), "\n" ..
|
||||
"[ERROR] could not open " .. output_file .. " for writing.")
|
||||
f:write(table.concat(lines, "\n"))
|
||||
f:close()
|
|
@ -0,0 +1,31 @@
|
|||
SCRIPT_NAME = "collect_internal_linked.lua"
|
||||
os.setlocale("C")
|
||||
|
||||
local RawBlock = pandoc.RawBlock
|
||||
local parts = pandoc.MetaList({})
|
||||
|
||||
return {
|
||||
{ Link = function(link)
|
||||
-- early return for external links
|
||||
if link.target:find("^https?%:%/%/") then return end
|
||||
if link.target:find("^mailto%:") then return end
|
||||
|
||||
local fp, anchor = link.target:match("^(.+%.md)#?(.*)$")
|
||||
-- early return for non markdown files
|
||||
if not fp then return end
|
||||
|
||||
local f = io.open(fp)
|
||||
-- early return for broken internal links
|
||||
if f == nil then return link.content else f:close() end -- @todo maybe log broken internal links
|
||||
|
||||
local part_fp = fp:gsub("^(.+)%.md$", "public_html/%1.html.part")
|
||||
local f = assert(io.open(part_fp), "\n" ..
|
||||
"[ERROR] could not open " .. part_fp .. " for reading.")
|
||||
local rawblock = RawBlock(FORMAT, f:read("a")); f:close()
|
||||
parts:insert(rawblock)
|
||||
end },
|
||||
{ Meta = function (meta)
|
||||
meta["parts"] = parts
|
||||
return meta
|
||||
end }
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
SCRIPT_NAME = "insert_parts.lua"
|
||||
os.setlocale("C")
|
||||
|
||||
local MetaList = pandoc.MetaList
|
||||
local RawBlock = pandoc.RawBlock
|
||||
|
||||
return {
|
||||
{ Meta = function (meta)
|
||||
if not meta["parts"] then return end
|
||||
if type(meta["parts"]) == "string" then
|
||||
meta["parts"] = MetaList({ meta["parts"] })
|
||||
end
|
||||
meta["parts"] = meta["parts"]:map(function (item)
|
||||
local f = assert(io.open(item), "\n" ..
|
||||
"[ERROR] could not open " .. item .. " for reading.")
|
||||
local raw_block = RawBlock("html5", f:read("a"))
|
||||
f:close()
|
||||
return raw_block
|
||||
end)
|
||||
return meta
|
||||
end }
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
SCRIPT_NAME = "resolve_internal_links.lua"
|
||||
os.setlocale("C")
|
||||
|
||||
local Inlines = pandoc.Inlines
|
||||
|
||||
return {
|
||||
{ Link = function(link)
|
||||
-- early return for external links
|
||||
if link.target:find("^https?%:%/%/") then return end
|
||||
if link.target:find("^mailto%:") then return end
|
||||
|
||||
local fp, slug, anchor = link.target:match("^((.+)%.md)#?(.*)$")
|
||||
-- early return for non markdown files
|
||||
if not fp then return end
|
||||
|
||||
local f = io.open(fp)
|
||||
-- early return for broken internal links
|
||||
if f == nil then return link.content else f:close() end -- @todo maybe log broken internal links
|
||||
|
||||
local internal_link = link:clone()
|
||||
internal_link.target = ("#%s%s"):format(slug, anchor)
|
||||
|
||||
link.content = "↪"
|
||||
link.target = ("%s.html#%s"):format(slug, anchor)
|
||||
|
||||
return Inlines({ internal_link, link })
|
||||
end }
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
SCRIPT_NAME = "resolve_internal_links.lua"
|
||||
os.setlocale("C")
|
||||
|
||||
local Inlines = pandoc.Inlines
|
||||
|
||||
local page_slug
|
||||
|
||||
return {
|
||||
{ Meta = function(meta)
|
||||
page_slug = meta["slug"]
|
||||
end },
|
||||
{ Link = function(link)
|
||||
-- early return for external links
|
||||
if link.target:find("^https?%:%/%/") then return end
|
||||
if link.target:find("^mailto%:") then return end
|
||||
|
||||
local fp, slug, anchor = link.target:match("^((.+)%.md)#?(.*)$")
|
||||
-- early return for non markdown files
|
||||
if not fp then return end
|
||||
|
||||
local f = io.open(fp)
|
||||
-- early return for broken internal links
|
||||
if f == nil then return link.content else f:close() end -- @todo maybe log broken internal links
|
||||
|
||||
link.target = ("%s.html#%s%s"):format(page_slug, slug, anchor)
|
||||
return link
|
||||
end }
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
SCRIPT_NAME = "update_internal_targets.lua"
|
||||
os.setlocale("C")
|
||||
|
||||
NOTE_PATTERN = "^((.+)%.md)(#?.*)$"
|
||||
LINK_REPL = "%2.html%3"
|
||||
|
||||
return {
|
||||
{ Link = function (link)
|
||||
local fp, _slug, _anchor = link.target:match(NOTE_PATTERN)
|
||||
if not fp then return end
|
||||
local f = io.open(fp)
|
||||
if f == nil then return link.content else f:close() end
|
||||
link.target = link.target:gsub(NOTE_PATTERN, LINK_REPL)
|
||||
return link
|
||||
end }
|
||||
}
|
Loading…
Reference in New Issue