pg.fnl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. (local header "<div id=\"preamble\" class=\"status\">
  2. <div id=\"banner\">
  3. <h1><a href=\"/home.html\">Kevin \"The Nuclear\" Bloom</a></h1>
  4. <hr />
  5. <div id=\"navit\">
  6. <a href=\"/contact.html\">Contact</a>
  7. &nbsp;
  8. <a href=\"/blog.html\">Blog</a>
  9. &nbsp;
  10. <a href=\"/projects.html\">Projects</a>
  11. &nbsp;
  12. <a href=\"/about-me.html\">About Me</a>
  13. </div>
  14. </div>
  15. </div>
  16. ")
  17. (local footer "<div id=\"footer\">
  18. <hr />
  19. <p>
  20. <a href=\"https://anybrowser.org/campaign/\">
  21. <img src=\"/img/any-browser.png\" alt=\"Viewable with any browser! No JS, no cookies, no bullshit!\"/></a>
  22. &nbsp;
  23. <a href=\"http://validator.w3.org/check?uri=nuclearkev.org\"><img
  24. src=\"http://www.w3.org/Icons/valid-xhtml10\" alt=\"Valid XHTML 1.0 Strict\" height=\"31\" width=\"88\" /></a>
  25. </p>
  26. <p>
  27. Copyright © 2017-2020 Kevin \"The Nuclear\" Bloom
  28. </p>
  29. </div>
  30. ")
  31. (fn top-stuff [title]
  32. (..
  33. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  34. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
  35. <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">
  36. <head>
  37. "
  38. title
  39. "<link rel=\"shortcut icon\" type=\"image/png\" href=\"/img/guy-in-space.png\"/>
  40. <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />
  41. <meta name=\"generator\" content=\"Org mode\" />
  42. <meta name=\"author\" content=\"Kevin &quot;The Nuclear&quot; Bloom\" />
  43. <meta http-equiv=\"cache-control\" content=\"no-cache, must-revalidate, post-check=0, pre-check=0\" />
  44. <meta http-equiv=\"cache-control\" content=\"max-age=0\" />
  45. <meta http-equiv=\"expires\" content=\"0\" />
  46. <meta http-equiv=\"expires\" content=\"Tue, 01 Jan 1980 1:00:00 GMT\" />
  47. <meta http-equiv=\"pragma\" content=\"no-cache\" />
  48. <link rel='stylesheet' href='/styles/main.2.css' />
  49. </head>
  50. "))
  51. ;; -- From my str.fnl lib -----------------------
  52. (fn drop [s ind]
  53. (string.sub s ind))
  54. (fn take [s ind]
  55. (string.sub s 1 ind))
  56. (fn substring-between [s fir lst]
  57. "Returns a substring of S defined by 2 strings, FIR and LST.
  58. The benefit of this is that if there are other instances of LST before the
  59. instance you want, they won't get caught.
  60. I.e.: You wish to get the value of the second line of \"this \n is a \n test\",
  61. You would just use (string-between str \"is a\" \"\n\")"
  62. (let [fir-pos (string.find s fir)
  63. up-to-fir (drop s fir-pos)
  64. lst-pos (string.find up-to-fir lst)]
  65. (take up-to-fir lst-pos)))
  66. ;; -- end -----------------------------------------
  67. (fn generate-page [file-name]
  68. (let [file-port (io.open file-name "r")
  69. full-file (file-port:read "*a")
  70. title (.. (substring-between full-file "<title>" "</title>") "/title>\n")
  71. body (drop (substring-between full-file "<body>" "\n</body>") 7)]
  72. (file-port:close)
  73. (print (.. (top-stuff title)
  74. "<body>\n"
  75. header
  76. body
  77. footer
  78. "</body>\n"
  79. "</html>"))))
  80. (generate-page (. arg 1))