我已设置 Hakyll 以从博客文章中生成基本标签页面,如下所示:
main = do
hakyll $ do
match "preambles/*.md" $ compile $ pandocCompiler >>= relativizeUrls
tags <- buildTags "posts/*.md" (fromCapture "tags/*.html")
tagsRules tags $ \tag pattern -> do
let title = "Posts tagged \"" ++ tag ++ "\""
route idRoute
compile $ do
posts <- recentFirst =<< loadAll pattern
preamble <- loadBody $ fromFilePath ("preambles/" ++ tag ++ ".html")
let ctx = constField "title" title
`mappend` listField "posts" postCtx (return posts)
`mappend` bodyField preamble
`mappend` defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/tag.html" ctx
>>= loadAndApplyTemplate "templates/default.html" ctx
>>= relativizeUrls
...
我希望能够为每一页提供一个可选的序言。
为此,我希望在preambles目录中的每个标签都有一个降价文件,并在构建标签页面时尝试使用这些文件。但是,我不知道如何使它成为可选的,因为loadSnapshot
如果fail
没有找到。
这是一种合适的方法吗?如果是,我将如何处理丢失的数据?
另外,我不确定这bodyField
是将数据传递给模板的适当方式。