added a homepage generator

This commit is contained in:
Izaya 2018-10-09 18:18:35 +11:00
parent 60c2013872
commit 63ab3b285f
2 changed files with 51 additions and 0 deletions

View File

@ -2,3 +2,4 @@
./genpages.lua
./blog.lua
./tags.lua
./home.lua

50
home.lua Executable file
View File

@ -0,0 +1,50 @@
#!/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('<div class="wrapper">')
f:write(' <div class="left-column">')
f:write(' <h2><a href="'..lp[2]..'">'..lp[1]..'</a></h2>')
f:write(' </div>')
f:write(' <div class="right-column">')
f:write(' <h2><a href="'..rp[2]..'">'..rp[1]..'</a></h2>')
f:write(' </div>')
f:write('</div>')
end
f:write(footer)
f:write(sitelib.footer)
f:close()