Discussion:
[hakyll] Good way to have "watch" (or similar) to also rebuild the blog Haskell code and rebuild site when .hs files change?
Janne Hellsten
2018-05-29 18:56:29 UTC
Permalink
I found a pretty decent way to accomplish what I want (ie., quickly
recompile Haskell when any .hs source file changes + rebuild of the site).

I added this function into my site.hs:

Instead of just the "main :: IO ()" entry point with

main :: IO ()
main = do
E.setLocaleEncoding E.utf8
hakyllWith config buildRules

..I added another entrypoint:

-- For starting with ghcid site.hs --test ghcidEntry
-- forces site recompilation when the .hs source changes.
ghcidEntry :: IO ()
ghcidEntry = do
void $ hakyllWithExitCodeAndArgs config (Options False Clean) buildRules
void $ hakyllWithExitCodeAndArgs config (Options False (Watch
"127.0.0.1" 8000 False)) buildRules

This way I can start my blog with:

ghcid site.hs --test ghcidEntry

Ghcid will reload any changed Haskell code and run the blog. As I added a
"clean" invocation into ghcidEntry, caches are blown so that any outputs
that might depend on my Haskell code will be regen'd.

I'm generating a bunch of SVG outputs (incl. animation) with blaze-svg and
rebuilding the site with "stack build" takes FOREVER, killing any
productivity gains I'd get from developing in Haskell as opposed to say
using Javascript with webpack (the webpack-dev-server supports quick
iteration really well). But ghcid with the added ghcidEntry entry point
makes this a pretty decent experience.

Janne


On Sun, May 20, 2018 at 8:09 PM, Kyle Marek-Spartz <
Making your site.hs executable and deferring type errors to runtime might
https://docs.haskellstack.org/en/stable/GUIDE/#script-interpreter
https://downloads.haskell.org/~ghc/7.10.1/docs/html/users_
guide/defer-type-errors.html
I'd like to embed some SVG diagrams that are generated using Haskell
(either using Diagrams or most probably just dumping svg). I do this by
just adding a module called "Diagrams" which has a bunch of functions that
just output an SVG string. Then I hook these into my blog by adding a
constField into my postCtx. E.g., something like
postCtx :: Context String
postCtx = mconcat
[ modificationTimeField "mtime" "%U"
, dateField "date" "%B %e, %Y"
, snippetField
, constField "diagram1" diagram1Svg
, defaultContext
]
in markdown I can just do $diagram1$ to extract the SVG into my HTML
output.
However, when I edit the Haskell source for diagram1Svg, the blog doesn't
get rebuild when I save the file. This is when using "blog preview".
Is there a way for these to somehow get updated with preview?
I could of course add a watch script myself that calls "stack build &&
stack exec blog build" when any of the .hs files change. But as you all
are probably painfully aware, Haskell builds are slooooow.
I probably could use "ghcid --test" to auto reload the blog and run a
command on each compile. Not sure how I can give command line options for
the "--test" switch in Ghcid though. And it feels like this is something
that'd be better supported by Hakyll out of the box.
Janne
--
You received this message because you are subscribed to the Google Groups
"hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the
Google Groups "hakyll" group.
To unsubscribe from this topic, visit https://groups.google.com/d/
topic/hakyll/49hossx0TFA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...