61 lines
1.6 KiB
Lua
Executable File
61 lines
1.6 KiB
Lua
Executable File
#!/usr/bin/env lua
|
|
local sitelib = require "sitelib"
|
|
local fs = require "lfs"
|
|
|
|
print("Copying static content...")
|
|
os.execute("rsync -avzh --delete 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("<html><head><title>"..(page.title or "").."</title>\n")
|
|
f:write(sitelib.header)
|
|
f:write(page.html)
|
|
if page.author or page.date then
|
|
f:write('<h4><div class="wrapper"><div class="left-column">By '..(page.author or "")..'</div><div class="right-column">'..(page.date or "")..'</div></div></h4>\n')
|
|
end
|
|
if page.tags then
|
|
f:write("<h4>Tags: ")
|
|
for w in page.tags:gmatch("%S+") do
|
|
f:write('<a href="/tag/'..w..'.html">'..w.."</a> ")
|
|
end
|
|
f:write("</h4>")
|
|
end
|
|
f:write(sitelib.footer)
|
|
f:close()
|
|
end
|
|
|