Fork me on GitHub
#sci
<
2021-12-26
>
teodorlu23:12:30

I've been playing around with a data-driven approach to static sites lately. Write Hiccup in EDN, then make HTML out of it. I needed some kind of templating, so I figured, why not just pipe the EDN through SCI. So far, I'm really liking it! This EDN:

^{:teod.subcons/filewriter :teod.subcons.filewriter/hiccup-html
  :teod.subcons/transformers [teod.subcons.sci/eval]}
(let [title "A data-driven approach to static sites"]
  [:html [:head [:title title]
          [:body [:main [:section
                         [:h1 {:style "color: #252525"} title]
                         [:p "Hello, world! 1+1 is " (+ 1 1) "!"]]]]]])
Turns into this HTML:

<html>
  <head>
    <title>A data-driven approach to static sites</title>
    <body>
      <main>
        <section>
          <h1 style="color: #252525">A data-driven approach to static sites</h1>
          <p>Hello, world! 1+1 is 2!</p>
        </section>
      </main>
    </body>
  </head>
</html>
I figure providing a SCI environment with some default functions could be a nice extension point. Slightly larger example: https://subcons.teod.eu/data-driven-site/

🎉 3