]==]
local function readfile(filename)
local file = io.open(filename)
local contents = file:read("*a")
file:close()
return contents
end
local function writefile(filename, contents)
local file = io.open(filename, "w+")
file:write(contents)
file:close()
end
local function gen_page(project, pages, p)
project.pages = function ()
for _, page in ipairs(pages) do
local namelink
if page.file == p.file then
namelink = cosmo.fill([[$name]], { name = page.name})
else
namelink = cosmo.fill([[$name]], { name = page.name, file = page.file})
end
cosmo.yield{ namelink = namelink, sections = function ()
for _, s in ipairs(page.sections) do
cosmo.yield{ name = s.name, anchor =
page.file .. ".html#" .. s.anchor }
end
end }
end
end
return (cosmo.fill(template, project))
end
for _, p in ipairs(pages) do
project.content = markdown(readfile(p.file .. ".md"))
writefile(p.file .. ".html", gen_page(project, pages, p))
end