4

Let's say I have this Hakyll template:

<h2>The archive</h2>
<p>This is an archive of all posts.</p>

<ul id="archive">
$partial("templates/post-list.html")$
</ul>

Now, I would like to extract the static text and put it in a MarkDown file that is rendered to HTML by Hakyll and include it in the template, like so:

$intro$

<ul id="archive">
$partial("templates/post-list.html")$
</ul>

I found a similar question online, but it's for an older version of Hakyll.

My rough idea would be to modify the part of my site.hs that generates archive.html to include another constField called "intro" and passing it the processed MarkDown file:

    create ["archive.html"] $ do
    route idRoute
    compile $ do
        posts <- recentFirst =<< loadAll "posts/*"
        let archiveCtx =
                listField "posts" postCtx (return posts) `mappend`
                constField "title" "Archives"            `mappend`
                constField "intro" ???                   `mappend`
                defaultContext

        makeItem ""
            >>= loadAndApplyTemplate "templates/archive.html" archiveCtx
            >>= loadAndApplyTemplate "templates/default.html" archiveCtx
            >>= relativizeUrls

To process the MarkDown file, I'd probably have to do something like this:

 match "archive/intro.md" $ do
    -- route $ setExtension "html" -- No route necessary, we only want file contents
    compile $ pandocCompiler

But how can I load the processed file into the previous snippet?

Beerend Lauwers
  • 842
  • 5
  • 14

0 Answers0