Generator for my site.

sitelib.lua 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. local sitelib = {}
  2. sitelib.srcpath = "src"
  3. sitelib.outpath = "out"
  4. sitelib.includepath = "include"
  5. sitelib.staticpath = "static"
  6. sitelib.header, sitelib.footer = "", ""
  7. local f = io.open("include/header.html")
  8. if f then
  9. sitelib.header = f:read("*a")
  10. f:close()
  11. end
  12. local f = io.open("include/footer.html")
  13. if f then
  14. sitelib.footer = f:read("*a")
  15. f:close()
  16. end
  17. function sitelib.parsepage(s)
  18. local page={}
  19. page.md = ""
  20. for l in s:gmatch("(.-)\n") do
  21. if l:sub(1,3) == "-- " then
  22. k,v=l:match("%-%- (.-) (.+)")
  23. page[k] = v
  24. else
  25. page.md=page.md..l.."\n"
  26. end
  27. end
  28. local fn="/tmp/md"..tostring(math.random(1,2^24))
  29. f=io.open(fn,"wb")
  30. f:write(page.md)
  31. f:close()
  32. page.html = io.popen("markdown "..fn):read("*a")
  33. os.execute("rm "..fn)
  34. -- SKS specific stuff starts here
  35. page.html=page.html:gsub("++leftcol",'<div class="left-column">')
  36. page.html=page.html:gsub("++colbreak",'</div><div class="left-column">')
  37. page.html=page.html:gsub("++colend",'</div>')
  38. -- and ends here
  39. return page
  40. end
  41. return sitelib