bavbavhaus.net/pandoc/collect_notes.lua

25 lines
649 B
Lua

local read = pandoc.read
assert(#arg == 1, "\n" ..
"[ERROR] usage: pandoc lua collect_all.lua <index file>")
local visited = {}
local function collect (fp)
local f = assert(io.open(fp), "\n" ..
"[ERROR] could not open " .. fp .. " for reading.")
visited[fp] = true
io.write(fp .. "\n")
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
visited[link.target] = true
collect(link.target)
end })
end
collect(arg[1])