pg.fnl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. &nbsp;
  26. <a href=\"http://NetBSD.org/\"><img
  27. src=\"https://www.netbsd.org/images/powered-by-NetBSD.png\" alt=\"NetBSD\" width=\"88\" /></a>
  28. </p>
  29. <p>
  30. Copyright © 2017-2022 Kevin \"The Nuclear\" Bloom
  31. </p>
  32. </div>
  33. ")
  34. (fn top-stuff [title]
  35. (..
  36. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  37. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
  38. <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">
  39. <head>
  40. "
  41. title
  42. "<link rel=\"shortcut icon\" type=\"image/png\" href=\"/img/guy-in-space.png\"/>
  43. <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />
  44. <meta name=\"generator\" content=\"Org mode\" />
  45. <meta name=\"author\" content=\"Kevin &quot;The Nuclear&quot; Bloom\" />
  46. <meta http-equiv=\"cache-control\" content=\"no-cache, must-revalidate, post-check=0, pre-check=0\" />
  47. <meta http-equiv=\"cache-control\" content=\"max-age=0\" />
  48. <meta http-equiv=\"expires\" content=\"0\" />
  49. <meta http-equiv=\"expires\" content=\"Tue, 01 Jan 1980 1:00:00 GMT\" />
  50. <meta http-equiv=\"pragma\" content=\"no-cache\" />
  51. <link rel='stylesheet' href='/styles/main.2.css' />
  52. </head>
  53. "))
  54. ;; -- From my str.fnl lib -----------------------
  55. (fn drop [s ind]
  56. (string.sub s ind))
  57. (fn take [s ind]
  58. (string.sub s 1 ind))
  59. (fn substring-between [s fir lst]
  60. "Returns a substring of S defined by 2 strings, FIR and LST.
  61. The benefit of this is that if there are other instances of LST before the
  62. instance you want, they won't get caught.
  63. I.e.: You wish to get the value of the second line of \"this \n is a \n test\",
  64. You would just use (string-between str \"is a\" \"\n\")"
  65. (let [fir-pos (string.find s fir)
  66. up-to-fir (drop s fir-pos)
  67. lst-pos (string.find up-to-fir lst)]
  68. (take up-to-fir lst-pos)))
  69. ;; -- end -----------------------------------------
  70. (fn generate-page [file-name]
  71. (let [file-port (io.open file-name "r")
  72. full-file (file-port:read "*a")
  73. title (.. (substring-between full-file "<title>" "</title>") "/title>\n")
  74. body (drop (substring-between full-file "<body>" "\n</body>") 7)]
  75. (file-port:close)
  76. (print (.. (top-stuff title)
  77. "<body>\n"
  78. header
  79. body
  80. footer
  81. "</body>\n"
  82. "</html>"))))
  83. (generate-page (. arg 1))