63 lines
1.4 KiB
Lua
Executable File
63 lines
1.4 KiB
Lua
Executable File
#!/usr/bin/env lua
|
|
local sitelib = require "sitelib"
|
|
local fs = require "lfs"
|
|
|
|
print("Copying static content...")
|
|
--os.execute("cp -rv static/* out/")
|
|
for k,v in pairs({"jpg","jpeg","png","gif"}) do
|
|
os.execute("find static/ -name '*."..v.."' -exec echo '{}' \\;")
|
|
end
|
|
|
|
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.gopherpath) 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.gopherpath..infile:sub(sitelib.srcpath:len()+1))
|
|
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")
|
|
if page.title then
|
|
f:write("# "..page.title.."\n")
|
|
end
|
|
if page.author then
|
|
f:write("By "..page.author.."\n")
|
|
end
|
|
if page.date then
|
|
f:write(page.date.."\n")
|
|
end
|
|
f:write(page.md)
|
|
if page.tags then
|
|
f:write("Tags: "..page.tags)
|
|
end
|
|
f:close()
|
|
end
|
|
|