bavbavhaus.net/pandoc/sitemap.lua

20 lines
579 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 = arg[1]
local filepaths_arr = {}
for i = 2, #arg do
table.insert(filepaths_arr, arg[i])
end
local data = json.encode(filepaths_arr)
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