Blogging in Lisp
I rewrote my blog engine is lisp! Why? Why not!
Specifically I used hy which I've had fun with before. My day job uses a lot of python, and it's fun to be able to make the most of the ecosystem but still play with new language concepts.
It's not been a particularly big project, but it's still easily the most heavy lifting I've done in any lisp. I was expecting it to be a bit of a silly project that would be more effort that it was worth, but actually, writing a blog engine designed just for my use (and not a general purpose one) made it a really small, managable project.
My main take aways are: - macros are really cool! They solved some annoying bits I hit into where the python/hy interaction left some uglyness. - htpy is a great library (I already new this, but I prefer it to working with templating so much) - static site generators aren't so hard if you're building a specific site - parenthesese aren't so scary, in fact, lisp having just one thing (s-expressions) made the whole thing quite a lot easier. - seriously, macros are really cool
Here's a snipper of the code used to render this page:
(defn render_element [element]
(->
(!html html
(!html head
(!html title "Hi, I'm Ben")
((. htpy meta)
:charset "utf-8")
((. htpy link)
:rel "stylesheet"
:href "/style.css")
((. htpy link)
:rel "stylesheet"
:href "/code.css"))
(!html body
(!html nav
(!html ul
(!html li ((!html a
(!html h2 "Hi, I'm Ben 🐚"))
:href "/")))
(!html ul
(!html li
((!html a "Blog")
:href "/posts/content.html"))
(!html li
((!html a "Code")
:href "https://codeberg.org/benrutter/"))
(!html li
((!html a "Feed")
:href "/posts/feed.rss"))
(!html li
((!html a "Mastodon")
:href "https://mastodon.green/@benrutter"))))
(. htpy hr)
(!html main element)))
(.encode _)
(.decode _)))