pg.fnl 2.4 KB

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