#!/usr/bin/env lua local sitelib = require "sitelib" local fs = require "lfs" local articles = 4 print("Finding blog posts...") local ftab = {} for file in fs.dir(sitelib.srcpath.."/blog") do if file:sub(1,1) ~= "." then local index = tonumber(file:match("(%d+).md")) if index then ftab[index] = file end end end local pages = {} for i = #ftab, #ftab-(articles-1), -1 do local f = io.open(sitelib.srcpath.."/blog/"..ftab[i]) local c = f:read("*a") f:close() local page = sitelib.parsepage(c) pages[#pages+1] = {page.title,"/blog/"..tostring(i)..".html"} end print("Reading template...") local f = io.open(sitelib.includepath.."/home-top.html","rb") local header = f:read("*a") f:close() local f = io.open(sitelib.includepath.."/home-end.html","rb") local footer = f:read("*a") f:close() print("Writing index...") local f = io.open(sitelib.outpath.."/index.html","wb") f:write(header) while #pages > 0 do local lp, rp = table.remove(pages,1), table.remove(pages,1) f:write('
') f:write('
') f:write('

'..lp[1]..'

') f:write('
') f:write('
') f:write('

'..rp[1]..'

') f:write('
') f:write('
') end f:write(footer) f:write(sitelib.footer) f:close()