Browse Source

added an RSS feed generator finally

master
XeonSquared 5 months ago
parent
commit
f3a78ccf42
3 changed files with 68 additions and 1 deletions
  1. 1
    1
      blog.lua
  2. 3
    0
      genall.sh
  3. 64
    0
      genrss.lua

+ 1
- 1
blog.lua View File

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

+ 3
- 0
genall.sh View File

@@ -3,3 +3,6 @@
3 3
 ./blog.lua
4 4
 ./tags.lua
5 5
 ./home.lua
6
+./genrss.lua
7
+./gengopher.lua
8
+./gopher-home.lua

+ 64
- 0
genrss.lua View File

@@ -0,0 +1,64 @@
1
+#!/usr/bin/env lua
2
+local sitelib = require "sitelib"
3
+local fs = require "lfs"
4
+
5
+print("Reading blog entries")
6
+local mdfiles = {}
7
+for file in fs.dir(sitelib.srcpath.."/blog/") do
8
+ if file:sub(1,1) ~= "." then
9
+  local index = tonumber(file:match("(%d+).md"))
10
+  if index then
11
+   mdfiles[index] = file
12
+  end
13
+ end
14
+end
15
+
16
+if not fs.attributes(sitelib.gopherpath) then
17
+ fs.mkdir(sitelib.gopherpath)
18
+end
19
+
20
+local index=""
21
+local itemtemplate = [[%s <item>
22
+  <title>%s</title>
23
+  <description>%s</description>
24
+  <link>%s</link>
25
+  <guid>%s</guid>
26
+  <pubDate>%s</pubDate>
27
+ </item>
28
+]]
29
+print("Generating index")
30
+for i = #mdfiles, #mdfiles - 9, -1 do
31
+ infile = mdfiles[i]
32
+ local fpath = "/blog/"..infile
33
+ local infile = sitelib.srcpath.."/blog/"..infile
34
+ local uuid = "https://"..sitelib.hostname..(fpath:sub(1,-3)).."html"
35
+ print(infile,fpath,uuid)
36
+--[[
37
+ local u = io.popen("./uuidfile.sh "..infile)
38
+ local uuid = u:read("*a"):match("[^\n]+")
39
+ u:close()
40
+]]--
41
+ local f = io.open(infile,"rb")
42
+ local c = f:read("*a")
43
+ f:close()
44
+ local page = sitelib.parsepage(c)
45
+ local fline = page.md:match("\n\n(.-)\n")
46
+ print(fline)
47
+ -- attempt to convert existing date to a dumb RFC 822 date
48
+ local d = io.popen("date --date='"..page.date.."' '+%a, %d %b %Y %H:%M:00 %z'"):read("*a"):match("(.+)\n")
49
+ index = string.format(itemtemplate,index,page.title,fline,uuid,uuid,d)
50
+end
51
+
52
+index=[[<?xml version="1.0" encoding="UTF-8" ?>
53
+<rss version="2.0">
54
+<channel>
55
+ <title>ShadowKat Studios</title>
56
+ <link>https://shadowkat.net</link>
57
+ <description>ShadowKat Studios Blog Entries</description>
58
+]]..index
59
+
60
+local f = io.open(sitelib.outpath.."/rss.xml","wb")
61
+f:write(index)
62
+f:write([[</channel>
63
+</rss>]])
64
+f:close()

Loading…
Cancel
Save