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.

39 lines
1.0KB

  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. print("Generating index")
  19. for k,infile in ipairs(mdfiles) do
  20. local fpath = "/blog/"..infile
  21. local infile = sitelib.srcpath.."/blog/"..infile
  22. print(infile,fpath)
  23. local f = io.open(infile,"rb")
  24. local c = f:read("*a")
  25. f:close()
  26. local page = sitelib.parsepage(c)
  27. if page.date then page.title = string.format("%s (%s)",page.title,page.date) end
  28. local fline = page.md:match("\n\n(.-)\n")
  29. index = string.format("0%s\t%s\t%s\t%d\ni%s\n%s",page.title,fpath,sitelib.hostname,sitelib.gopherport,fline,index)
  30. end
  31. index=sitelib.gheader .. index .. sitelib.gfooter
  32. local f = io.open(sitelib.gopherpath.."/blog/.gopherdir","wb")
  33. f:write(index)
  34. f:close()