0

我想向 中添加一个字段defaultContext,这将使所有页面都可以使用链接列表。因为我不认为我可以改变defaultContext自己,所以我创建了一个函数,它添加一个listFieldtodefaultContext并用它替换所有引用defaultContext。虽然程序符合要求,但我的新程序listField是空的。

这是我最近的尝试。

-- site.hs
match "index.html" $ do
    route idRoute
    compile $ do
        links <- sortByTitle =<< loadAll "links/*"
        let indexCtx =
                listField "links" linkCtx (return links) `mappend`
                constField "title" "Home"                `mappend`
                myCtx

        getResourceBody
            >>= applyAsTemplate indexCtx
            >>= loadAndApplyTemplate "templates/default.html" indexCtx
            >>= relativizeUrls

match "templates/*" $ compile templateBodyCompiler

myCtx =
  listField "navItems" defaultContext (loadAll "nav/*") `mappend`
  defaultContext

-- nav/item.markdown
---
title: nav item 1
---

-- templates/default.html
<ul>
    $for(navItems)$
        $title$
    $endfor$
</ul>
4

1 回答 1

1

当您加载一个项目时,您需要使用该项目指定一个编译目标 - 请参阅加载函数。

load :: (Binary a, Typeable a) => Identifier -> Compiler (Item a)

加载在别处编译的项目。如果所需的项目尚未编译,构建系统将自动处理。

添加一个简单的(route不需要)编译器应该可以修复它:

match "nav/*" $ compile pandocCompiler
于 2016-09-19T06:58:58.243 回答