#!/usr/bin/lua local wikiparser = "/usr/local/bin/markdown2 -s escape" local source_dir = arg[1] local target_dir = arg[2] local pages = {} os.execute("rm -f " .. target_dir .. "/*.html") local template_fh = io.open(source_dir .. "/template.html") local template = template_fh:read("*a") template_fh:close() local function render(content, basename) local tmp = template:gsub("(\r?\n) *($content$) *(\r?\n)", function(m1, m2, m3) return m1 .. content .. m3 end) if basename then tmp = tmp:gsub("$page%$", basename) end return tmp end for filename in io.popen("ls " .. source_dir .. "/lemma"):lines() do print("Processing " .. filename) local basename = string.match(filename, "^([a-zA-Z0-9_.-]+)%.markdown$") if not basename then print("ignoring " .. filename) else table.insert(pages, basename) local content_fh = io.popen(wikiparser .. " " .. source_dir .. "/lemma/" .. filename) local content = content_fh:read("*a") content = content:gsub("%[([a-zA-Z0-9_.-]+)%]", '%1') content_fh:close() local page_fh = io.open(target_dir .. "/" .. basename .. ".html", "w") page_fh:write(render(content, basename)) page_fh:close() end end local index_parts = {} table.insert(index_parts, "

List of lemmata

") table.insert(index_parts, "") local index = table.concat(index_parts) local index_fh = io.open(target_dir .. "/all_lemmata.html", "w") index_fh:write(render(index)) index_fh:close() os.execute("rm -f " .. target_dir .. "/files/*") for filename in io.popen("ls " .. source_dir .. "/files"):lines() do if string.match(filename, "^([a-zA-Z0-9_.-]+)$") then os.execute("cp " .. source_dir .. "/files/" .. filename .. " " .. target_dir .. "/files/") end end