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.

gengopher.lua 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env lua
  2. local sitelib = require "sitelib"
  3. local fs = require "lfs"
  4. print("Copying static content...")
  5. --os.execute("cp -rv static/* out/")
  6. for k,v in pairs({"jpg","jpeg","png","gif"}) do
  7. os.execute("find static/ -name '*."..v.."' -exec echo '{}' \\;")
  8. end
  9. print("Building list of markdown files")
  10. local mdfiles = {}
  11. local dqueue = {sitelib.srcpath}
  12. for k,path in pairs(dqueue) do
  13. for file in fs.dir(path) do
  14. if file:sub(1,1) ~= "." then
  15. local attr = fs.attributes(path.."/"..file)
  16. if attr.mode == "directory" then
  17. dqueue[#dqueue+1] = path.."/"..file
  18. elseif file:sub(-3) == ".md" then
  19. mdfiles[#mdfiles+1] = path.."/"..file
  20. end
  21. end
  22. end
  23. end
  24. if not fs.attributes(sitelib.gopherpath) then
  25. fs.mkdir(sitelib.outpath)
  26. end
  27. print("Creating directories")
  28. for k,v in pairs(dqueue) do
  29. local path = sitelib.outpath..v:sub(sitelib.srcpath:len()+1)
  30. fs.mkdir(path)
  31. print(path)
  32. end
  33. print("Generating output files")
  34. for k,infile in pairs(mdfiles) do
  35. local outfile = (sitelib.gopherpath..infile:sub(sitelib.srcpath:len()+1))
  36. print(infile,outfile)
  37. local f = io.open(infile,"rb")
  38. local c = f:read("*a")
  39. f:close()
  40. local page = sitelib.parsepage(c)
  41. local f = io.open(outfile,"wb")
  42. if page.title then
  43. f:write("# "..page.title.."\n")
  44. end
  45. if page.author then
  46. f:write("By "..page.author.."\n")
  47. end
  48. if page.date then
  49. f:write(page.date.."\n")
  50. end
  51. f:write(page.md)
  52. if page.tags then
  53. f:write("Tags: "..page.tags)
  54. end
  55. f:close()
  56. end