0

在 Jekyll 中,可以有一个看起来像的文件

---
title: Whatever
layout: null
---

<h1>{{ title }}</h1>

{{ title }}被插值,但这layout: null意味着文件内容不会被包装在任何类型的模板中。

Hakyll 中的等价物是什么?换句话说,如果我有一个独立的文件,比如

<h1>$title$</h1>

我需要传递什么样的块才能compile插入$title$值,而不将页面的内容包装在某个模板中?

4

1 回答 1

0

答案(感谢#hakyll 频道中的erasmas!)是使用

getResourceBody >>= applyAsTemplate theContext

包含您想要的字段theContext的实例在哪里。Context String

这是一个关于如何使用此编译器的玩具示例:

main :: IO ()
main = hakyll $ do
    match "index.html" $ do
        route idRoute
        compile $ getResourceBody >>= applyAsTemplate indexContext

indexContext :: Context String
indexContext = mconcat
    [ constField "title" "My Website"
    , defaultContext
    ]
于 2017-10-15T23:16:41.700 回答