From f3a78ccf4213c2814a17257841d5e54748fb3106 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Tue, 15 Jan 2019 15:02:46 +1100 Subject: [PATCH] added an RSS feed generator finally --- blog.lua | 2 +- genall.sh | 3 +++ genrss.lua | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100755 genrss.lua diff --git a/blog.lua b/blog.lua index b246258..31d4487 100755 --- a/blog.lua +++ b/blog.lua @@ -34,7 +34,7 @@ for i = #ftab, 1, -1 do f:write("

Next

") end if ftab[i-1] then - f:write("

Previous

") + f:write("

Previous

") end f:write("") end diff --git a/genall.sh b/genall.sh index 2155f08..0d1781e 100755 --- a/genall.sh +++ b/genall.sh @@ -3,3 +3,6 @@ ./blog.lua ./tags.lua ./home.lua +./genrss.lua +./gengopher.lua +./gopher-home.lua diff --git a/genrss.lua b/genrss.lua new file mode 100755 index 0000000..8a7bd3a --- /dev/null +++ b/genrss.lua @@ -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 + %s + %s + %s + %s + %s + +]] +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=[[ + + + ShadowKat Studios + https://shadowkat.net + ShadowKat Studios Blog Entries +]]..index + +local f = io.open(sitelib.outpath.."/rss.xml","wb") +f:write(index) +f:write([[ +]]) +f:close()