我正在尝试构建一个有7个页面的网站。每个页面都是使用.markdown输入定义的。在每个页面上,我希望与所有其他页面的链接标题。
现在,这似乎是不可能的,因为Hakyll告诉我我有一个递归依赖。
[ERROR] Hakyll.Core.Runtime.chase: Dependency cycle detected: posts/page1.markdown depends on posts/page1.markdown我已经确定了此代码片段的递归依赖关系。
match "posts/*" $ do
route $ setExtension "html"
compile $ do
posts <- loadAll "posts/*"
let indexCtx =
listField "posts" postCtx (return posts) `mappend`
constField "title" "Home" `mappend`
defaultContext
pandocCompiler >>= loadAndApplyTemplate "templates/post.html" indexCtx
>>= loadAndApplyTemplate "templates/default.html" indexCtx
>>= relativizeUrls我想问题是我不允许我在同一模板上进行匹配,而a在同一模板上做了大量加载。
那么,如何为生成帖子时使用的所有帖子构造一个具有listField的上下文。
我猜另一种选择是首先生成链接,以某种方式存储它们,然后将它们包含在帖子中。但是我该怎么做呢?
发布于 2016-02-26 20:07:02
通过调用loadAll "posts/*",您可以在编译当前帖子之前加载每个完全编译的帖子,因此它是一个循环依赖。
最直接的解决方案是定义你的帖子的另一个版本:
match "posts/*" $ version "titleLine" $ do
-- route
-- compiler, maybe generate a link to real page here from file path然后,您可以在不触发循环依赖的情况下加载它们:
match "posts/*" $ do
-- route
compile $ do
postList <- loadAll ("posts/*" .&&. hasVersion "titleLine")
-- render the page但你可能不得不从文件路径手动生成正确的url,毕竟不同的版本是具有不同url的不同页面。如果您为多个页面设置相同的路由,则最后编译的页面将覆盖所有其他页面。
在您的情况下,这是可以的,因为非标记版本依赖于"titleLine“版本,所以在以后编译,但通常情况下,对于不同的页面有相同的路由是危险的,没有这样的依赖version标记的页面总是在以后编译。
https://stackoverflow.com/questions/35645525
复制相似问题