added an RSS feed generator finally

This commit is contained in:
Izaya 2019-01-15 15:02:46 +11:00
parent ca84af756c
commit f3a78ccf42
3 changed files with 68 additions and 1 deletions

View File

@ -34,7 +34,7 @@ for i = #ftab, 1, -1 do
f:write("<div class=\"right-column\"><h4><a href=\""..tostring(i+1)..".html\">Next</a></div>") f:write("<div class=\"right-column\"><h4><a href=\""..tostring(i+1)..".html\">Next</a></div>")
end end
if ftab[i-1] then if ftab[i-1] then
f:write("<div class=\"left-column\"><h4><a href=\""..tostring(i-1)..".html\">Previous</a></div>") f:write("<div class=\"left-column\" align='left'><h4><a href=\""..tostring(i-1)..".html\">Previous</a></div>")
end end
f:write("</div>") f:write("</div>")
end end

View File

@ -3,3 +3,6 @@
./blog.lua ./blog.lua
./tags.lua ./tags.lua
./home.lua ./home.lua
./genrss.lua
./gengopher.lua
./gopher-home.lua

64
genrss.lua Executable file
View File

@ -0,0 +1,64 @@
#!/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()