Yesod and Hakyll together (part 2)

2016-03-20

Go to part 1 of this series

There’s no code today. Just lots and lots of words. Code will follow soon!

Both Yesod and Hakyll are well-documented and have reasonable tutorials: both Michael Snoyman’s book and Jasper Van der Jeugt’s site are great resources.

Template system mismatches

What is not documented is how to combine the two. Part 1 of this series describes my Apache configuration for serving content from the two parts of the web site. After figuring that out, the most difficult challenge was making the two parts of the sites look and feel as if they were part of a single coherent site. The single biggest complexity is that both frameworks employ different templating systems by default. Yesod employs Shakespearean templates, specifically Hamlet, Lucius and Cassius. Hakyll has its own straightforward, but effective, system. I enumerate some of the interesting characteristics below:

Philosophical thoughts

Both systems have their pros and cons. However, on a personal note, I have a soft spot for Hamlet’s syntax. However, I don’t object to using real HTML. Ultimately, the question came down to the following: do I adapt my Yesod app to consume Hakyll templates or do I adapt my Hakyll site generator to handle the templates from my Yesod app. Given my unwillingness to compromise the type safety of my Yesod app, I decided to do the latter.

Possible approaches

There were three main approaches I considered:

I toyed with the first approach briefly and then decided that this was not personally very satisfying. Both Yesod and Hakyll are highly modular and configurable frameworks, so I decided to power through things and simply use the shakespeare in my Hakyll app.

As I’ll describe in future instalments of this series, this was not entirely straightforward, but did ultimately result in a reasonably elegant solution to the problem.

Related posts

Yesod and Hakyll together (part 1)
Installing Yesod on Windows

Tags

Haskell
Yesod
Hakyll
Keter
Apache
Ruby on Rails

Content © 2024 Richard Cook. All rights reserved.