pg.lua 2.1 KB

123456789101112131415161718192021222324252627
  1. local header = "<div id=\"preamble\" class=\"status\">\n<header id=\"banner\">\n <h1><a href=\"/home.html\">Kevin \"The Nuclear\" Bloom</a></h1>\n <hr />\n <nav><ul>\n <li><a href=\"/contact.html\">Contact</a></li>\n <li><a href=\"/blog.html\">Blog</a></li>\n <li><a href=\"/projects.html\">Projects</a></li>\n <li><a href=\"/about-me.html\">About Me</a></li>\n </ul></nav>\n</header>\n</div>\n"
  2. local footer = "<div id=\"footer\">\n <hr />\n <a href=\"https://anybrowser.org/campaign/\">\n <img src=\"/img/any-browser.png\" alt=\"Viewable with any browser! No JS, no cookies, no bullshit!\" />\n </a>\n <p>\n Copyright \194\169 2017-2020 Kevin \"The Nuclear\" Bloom\n </p>\n</div>\n"
  3. local function top_stuff(title)
  4. return ("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n<head>\n" .. title .. "<link rel=\"shortcut icon\" type=\"image/png\" href=\"/img/guy-in-space.png\"/>\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />\n<meta name=\"generator\" content=\"Org mode\" />\n<meta name=\"author\" content=\"Kevin &quot;The Nuclear&quot; Bloom\" />\n<link rel='stylesheet' href='/styles/main.css' />\n</head>\n")
  5. end
  6. local function drop(s, ind)
  7. return string.sub(s, ind)
  8. end
  9. local function take(s, ind)
  10. return string.sub(s, 1, ind)
  11. end
  12. local function substring_between(s, fir, lst)
  13. local fir_pos = string.find(s, fir)
  14. local up_to_fir = drop(s, fir_pos)
  15. local lst_pos = string.find(up_to_fir, lst)
  16. return take(up_to_fir, lst_pos)
  17. end
  18. local function generate_page(file_name)
  19. local file_port = io.open(file_name, "r")
  20. local full_file = file_port:read("*a")
  21. local title = (substring_between(full_file, "<title>", "</title>") .. "/title>\n")
  22. local body = substring_between(full_file, "<body>", "\n</body>")
  23. file_port:close()
  24. return print((top_stuff(title) .. header .. body .. footer .. "</body>\n" .. "</html>"))
  25. end
  26. return generate_page(arg[1])