pg.lua 2.7 KB

123456789101112131415161718192021222324252627
  1. local header = "<div id=\"preamble\" class=\"status\">\n <div id=\"banner\">\n <h1><a href=\"/home.html\">Kevin \"The Nuclear\" Bloom</a></h1>\n <hr />\n <div id=\"navit\">\n <a href=\"/contact.html\">Contact</a>\n &nbsp;\n <a href=\"/blog.html\">Blog</a>\n &nbsp;\n <a href=\"/projects.html\">Projects</a>\n &nbsp;\n <a href=\"/about-me.html\">About Me</a>\n </div>\n </div>\n</div>\n"
  2. local footer = "<div id=\"footer\">\n <hr />\n <p>\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!\"/></a>\n &nbsp;\n <a href=\"http://validator.w3.org/check?uri=nuclearkev.org\"><img\n src=\"http://www.w3.org/Icons/valid-xhtml10\" alt=\"Valid XHTML 1.0 Strict\" height=\"31\" width=\"88\" /></a>\n &nbsp;\n <a href=\"http://NetBSD.org/\"><img\n src=\"https://www.netbsd.org/images/powered-by-NetBSD.png\" alt=\"NetBSD\" width=\"88\" /></a>\n </p>\n <p>\n Copyright \194\169 2017-2022 Kevin \"The Nuclear\" Bloom\n </p>\n</div>\n"
  3. local function top_stuff(title)
  4. return ("<!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<meta http-equiv=\"cache-control\" content=\"no-cache, must-revalidate, post-check=0, pre-check=0\" />\n<meta http-equiv=\"cache-control\" content=\"max-age=0\" />\n<meta http-equiv=\"expires\" content=\"0\" />\n<meta http-equiv=\"expires\" content=\"Tue, 01 Jan 1980 1:00:00 GMT\" />\n<meta http-equiv=\"pragma\" content=\"no-cache\" />\n<link rel='stylesheet' href='/styles/main.2.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 = drop(substring_between(full_file, "<body>", "\n</body>"), 7)
  23. file_port:close()
  24. return print((top_stuff(title) .. "<body>\n" .. header .. body .. footer .. "</body>\n" .. "</html>"))
  25. end
  26. return generate_page(arg[1])