added a homepage generator
This commit is contained in:
parent
60c2013872
commit
63ab3b285f
50
home.lua
Executable file
50
home.lua
Executable 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()
|
Loading…
Reference in New Issue
Block a user