[web-devel] Using Hamlet for a static website
michael at snoyman.com
Mon May 30 22:28:09 CEST 2011
On Mon, May 30, 2011 at 10:17 PM, Neil Mitchell <ndmitchell at gmail.com> wrote:
> My website at http://community.haskell.org/~ndm/ is based on lots of
> template files, for example:
> http://community.haskell.org/~ndm/darcs/website/pages/catch.html (not
> a real HTML file, but a partial HTML file).
> These files all start with some metadata, and then have some templated
> language below, which gets combined with headers/footers to produce my
> website. I did this all using custom code, but I'd like to move to
> using Hamlet with YAML, so I can throw away lots of my custom code and
> so I get lots of additional features I'm currently missing because I
> have to hand-roll the framework myself. I couldn't find any examples
> of anything else doing this, so two questions:
> 1) I couldn't find any easy way to say "run hamlet on each of the
> files in this directory"? Will I have to do a getDirectoryContents in
> IO, lift that into Q, and then statically call hamletFile on a list?
> Then I'll output the HTML to file.
Yes, that sounds like the most likely-to-succeed approach.
> 2) Is there an existing example of this? Writing a static site in
> terms of Hamlet seems like a nice idea, and I can't be the first to
> have thought of it.
> Thanks, Neil
You may have been the first to discuss static Hamlet, but there have
been some emails off-list about creating static Yesod sites, which
would overlap quite a bit. I think creating such a system would be
fairly easy actually: just spider a live site and download all the
necessary files. With Warp/http-enumerator (or even just going
straight against WAI), it should be possible to write that very
trivially. In fact, I don't think it would even be Yesod-specific, so
if you set up your Hamlet code as a WAI app, I would imagine it would
work with such a system as well.
But I'll also agree with Jasper that Hakyll is very nice. I know it
has (or at least had) some level of Hamlet support, though I'm not
sure what that's like today.
More information about the web-devel