55 lines
1.5 KiB
Lua
Executable File
55 lines
1.5 KiB
Lua
Executable File
#!/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)..".md"}
|
|
end
|
|
|
|
print("Reading template...")
|
|
local f = io.open(sitelib.includepath.."/gheader-home","rb")
|
|
local header = f:read("*a")
|
|
f:close()
|
|
local f = io.open(sitelib.includepath.."/gfooter-home","rb")
|
|
local footer = f:read("*a")
|
|
f:close()
|
|
|
|
print("Writing index...")
|
|
local f = io.open(sitelib.gopherpath.."/.gopherdir","wb")
|
|
f:write(header)
|
|
while #pages > 0 do
|
|
local article = table.remove(pages,1)
|
|
f:write(string.format("0%s\t%s\t%s\t%d\n",article[1],article[2],sitelib.hostname,sitelib.gopherport))
|
|
--[[
|
|
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()
|