diff --git a/genpages.lua b/genpages.lua new file mode 100755 index 0000000..2e4d955 --- /dev/null +++ b/genpages.lua @@ -0,0 +1,60 @@ +#!/usr/bin/env lua +local sitelib = require "sitelib" +local fs = require "lfs" + +print("Copying static content...") +os.execute("cp -rv static/* out/") + +print("Building list of markdown files") +local mdfiles = {} +local dqueue = {sitelib.srcpath} +for k,path in pairs(dqueue) do + for file in fs.dir(path) do + if file:sub(1,1) ~= "." then + local attr = fs.attributes(path.."/"..file) + if attr.mode == "directory" then + dqueue[#dqueue+1] = path.."/"..file + elseif file:sub(-3) == ".md" then + mdfiles[#mdfiles+1] = path.."/"..file + end + end + end +end + +if not fs.attributes(sitelib.outpath) then + fs.mkdir(sitelib.outpath) +end + +print("Creating directories") +for k,v in pairs(dqueue) do + local path = sitelib.outpath..v:sub(sitelib.srcpath:len()+1) + fs.mkdir(path) + print(path) +end + +print("Generating output files") +for k,infile in pairs(mdfiles) do + local outfile = (sitelib.outpath..infile:sub(sitelib.srcpath:len()+1)):sub(1,-4)..".html" + print(infile,outfile) + local f = io.open(infile,"rb") + local c = f:read("*a") + f:close() + local page = sitelib.parsepage(c) + local f = io.open(outfile,"wb") + f:write(""..(page.title or "").."\n") + f:write(sitelib.header) + f:write(page.html) + if page.author and page.date then + f:write('

By '..(page.author or "")..'
'..(page.date or "")..'

\n') + end + if page.tags then + f:write("

Tags: ") + for w in page.tags:gmatch("%S+") do + f:write(''..w.." ") + end + f:write("

") + end + f:write(sitelib.footer) + f:close() +end +