sitegen/genrss.lua

65 lines
1.6 KiB
Lua
Raw Normal View History

2019-01-15 15:02:46 +11:00
#!/usr/bin/env lua
local sitelib = require "sitelib"
local fs = require "lfs"
print("Reading blog entries")
local mdfiles = {}
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
mdfiles[index] = file
end
end
end
if not fs.attributes(sitelib.gopherpath) then
fs.mkdir(sitelib.gopherpath)
end
local index=""
local itemtemplate = [[%s <item>
<title>%s</title>
<description>%s</description>
<link>%s</link>
<guid>%s</guid>
<pubDate>%s</pubDate>
</item>
]]
print("Generating index")
for i = #mdfiles, #mdfiles - 9, -1 do
infile = mdfiles[i]
local fpath = "/blog/"..infile
local infile = sitelib.srcpath.."/blog/"..infile
local uuid = "https://"..sitelib.hostname..(fpath:sub(1,-3)).."html"
print(infile,fpath,uuid)
--[[
local u = io.popen("./uuidfile.sh "..infile)
local uuid = u:read("*a"):match("[^\n]+")
u:close()
]]--
local f = io.open(infile,"rb")
local c = f:read("*a")
f:close()
local page = sitelib.parsepage(c)
local fline = page.md:match("\n\n(.-)\n")
print(fline)
-- attempt to convert existing date to a dumb RFC 822 date
local d = io.popen("date --date='"..page.date.."' '+%a, %d %b %Y %H:%M:00 %z'"):read("*a"):match("(.+)\n")
index = string.format(itemtemplate,index,page.title,fline,uuid,uuid,d)
end
index=[[<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>ShadowKat Studios</title>
<link>https://shadowkat.net</link>
<description>ShadowKat Studios Blog Entries</description>
]]..index
local f = io.open(sitelib.outpath.."/rss.xml","wb")
f:write(index)
f:write([[</channel>
</rss>]])
f:close()