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.

55 lines
1.5KB

  1. #!/usr/bin/env lua
  2. local sitelib = require "sitelib"
  3. local fs = require "lfs"
  4. local articles = 4
  5. print("Finding blog posts...")
  6. local ftab = {}
  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. ftab[index] = file
  12. end
  13. end
  14. end
  15. local pages = {}
  16. for i = #ftab, #ftab-(articles-1), -1 do
  17. local f = io.open(sitelib.srcpath.."/blog/"..ftab[i])
  18. local c = f:read("*a")
  19. f:close()
  20. local page = sitelib.parsepage(c)
  21. pages[#pages+1] = {page.title,"/blog/"..tostring(i)..".md"}
  22. end
  23. print("Reading template...")
  24. local f = io.open(sitelib.includepath.."/gheader-home","rb")
  25. local header = f:read("*a")
  26. f:close()
  27. local f = io.open(sitelib.includepath.."/gfooter-home","rb")
  28. local footer = f:read("*a")
  29. f:close()
  30. print("Writing index...")
  31. local f = io.open(sitelib.gopherpath.."/.gopherdir","wb")
  32. f:write(header)
  33. while #pages > 0 do
  34. local article = table.remove(pages,1)
  35. f:write(string.format("0%s\t%s\t%s\t%d\n",article[1],article[2],sitelib.hostname,sitelib.gopherport))
  36. --[[
  37. local lp, rp = table.remove(pages,1), table.remove(pages,1)
  38. f:write('<div class="wrapper">')
  39. f:write(' <div class="left-column">')
  40. f:write(' <h2><a href="'..lp[2]..'">'..lp[1]..'</a></h2>')
  41. f:write(' </div>')
  42. f:write(' <div class="right-column">')
  43. f:write(' <h2><a href="'..rp[2]..'">'..rp[1]..'</a></h2>')
  44. f:write(' </div>')
  45. f:write('</div>')
  46. ]]--
  47. end
  48. f:write(footer)
  49. --f:write(sitelib.footer)
  50. f:close()