bavbavhaus.net/pandoc/sitemap.lua

24 lines
676 B
Lua

-- local l = require("pandoc.logging")
local json = pandoc.json
assert(#arg > 1, "\n" ..
"[ERROR] usage: pandoc lua sitemap.lua <destination file> <input file>...")
local destination_filepath
local input_filepaths = {}
for _, option in ipairs(arg) do
if destination_filepath == nil then
destination_filepath = option
else
table.insert(input_filepaths, option)
end
end
local data = json.encode(input_filepaths)
local f = io.open(destination_filepath)
if f == nil or f:read("a") ~= data then
local f = assert(io.open(destination_filepath, "w"), "\n" ..
"[ERROR] could not open " .. destination_filepath .. " for writing")
f:write(data)
f:close()
end