Generator for my site.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.6KB

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