Say I have a 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, which is displayed in HTML by Hakyll and include it in the template, for example:
$intro$
<ul id="archive">
$partial("templates/post-list.html")$
</ul>
I found a similar question on the Internet , but this is for an older version of Hakyll.
My main idea would be to change the part of mine site.hsthat generates archive.htmlto include another constField, called "intro", and pass the processed MarkDown file to it:
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 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 fragment?
source
share