Discussion:
[hakyll] Newbie issue: How to use partials inside a markdown post?
s***@vacationlabs.com
2016-11-21 04:45:40 UTC
Permalink
Cross-posted from https://github.com/jaspervdj/hakyll/issues/486:

I'm just starting out with Hakyll and am working with the default site that
comes with hakyll init. I tried putting the following in
2015-08-12.spqr.markdown:


$partial("includes/DB.hs")$


It didn't work as expected - the post just showed the literal text
$partial("includes/DB.hs")$. It didn't pull in the content of includes/DB.hs into
the post. Then I tried adding the following to site.hs, but even this
didn't work:


match "includes/*" $ compile templateBodyCompiler


What am I missing?


-- Saurabh.
--
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.
Jasper Van der Jeugt
2016-11-21 17:14:10 UTC
Permalink
Hello,

There are a few things you need to do.

1. Compile everything under includes as normal strings. This can be
done using just `getResourceBody`.

match "includes/*" $ compile getResourceBody

2. Make sure the posts context supports the `snippet` field (which is
better in this case than `partial`). This can be done by changing the
default `postCtx` to something like:

postCtx :: Context String
postCtx =
dateField "date" "%B %e, %Y" `mappend`
snippetField `mappend`
defaultContext

3. At this point, the posts don't really understand they need to be
rendered as templates. We can fix that by adding such a step. We
change the default compiler for posts into something like:

match "posts/*" $ do
route $ setExtension "html"
compile $ getResourceBody
Post by s***@vacationlabs.com
= applyAsTemplate postCtx
= renderPandoc
= loadAndApplyTemplate "templates/post.html" postCtx
= loadAndApplyTemplate "templates/default.html" postCtx
= relativizeUrls
This also replaces the `pandocCompiler` by `getResourceBody >>=
renderPandoc`, since you (presumably) want to render the splices
before calling out to pandoc (because then `$` could turn into math
etc.)

Hope this helps,
Peace,
Jasper
Post by s***@vacationlabs.com
I'm just starting out with Hakyll and am working with the default site that
comes with hakyll init. I tried putting the following in
$partial("includes/DB.hs")$
It didn't work as expected - the post just showed the literal text
$partial("includes/DB.hs")$. It didn't pull in the content of includes/DB.hs
into the post. Then I tried adding the following to site.hs, but even this
match "includes/*" $ compile templateBodyCompiler
What am I missing?
-- Saurabh.
--
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 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...