Hakyll说“检测到依赖性周期:...". [英] Hakyll says "Dependency cycle detected: ..."

查看:119
本文介绍了Hakyll说“检测到依赖性周期:...".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个包含7页的网站.每个页面都是使用.markdown输入定义的.在每个页面上,我都希望有一个带有所有其他页面链接的标题.

I'm trying to construct a site with 7 pages. Each page is defined using a .markdown input. On each page I want a header with links to all the other pages.

现在,这似乎是不可能的,因为Hakyll告诉我我有递归依赖项.

Now, this seems to be impossible since Hakyll tells me that I have a recursive dependency.

[ERROR] Hakyll.Core.Runtime.chase: Dependency cycle detected: posts/page1.markdown depends on posts/page1.markdown

我已经确定了对该代码段的递归依赖性.

I have identified the recursive dependency to this snippet.

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

我想问题是我不允许在加载模板的模板上进行匹配.

I guess the problem is that I'm not allowed to match on the same template that a do a load on.

因此,如何在生成帖子时使用所有要使用的帖子的listField构造上下文.

So how can I construct a context with a listField for all posts to be used when generating posts.

我想一种替代方法是先生成链接,以某种方式存储它们,然后将其包含在帖子中.但是我该怎么办?

I guess an alternative would be to generate the links first, store them somehow and then include them in the posts. But how would I do that?

推荐答案

通过调用loadAll "posts/*",您可以在编译当前帖子之前加载所有已完全编译的帖子,因此这是周期依赖性.

By calling loadAll "posts/*" you load every fully compiled post before compile the current one, so it's a cycle dependency.

最直接的解决方案是定义帖子的另一个版本:

The most straightforward solution is to define another version of your posts:

match "posts/*" $ version "titleLine" $ do
  -- route
  -- compiler, maybe generate a link to real page here from file path

然后,您可以加载它们而无需触发周期依赖性:

Then you can load them all without triggering a cycle dependency:

match "posts/*" $ do
  -- route
  compile $ do
    postList <- loadAll ("posts/*" .&&. hasVersion "titleLine")
    -- render the page

但是在所有不同的版本都是具有不同URL的不同页面之后,您可能必须从文件路径手动生成正确的URL.如果为多个页面设置相同的路由,则最后编译的页面将覆盖所有其他页面.

But you may have to manually generate the correct url from file path, after all a different version is a different page with different url. If you set the same routing for more than one page, the last one compiled will overwrite all the others.

您的情况还可以,因为未标记的版本取决于"titleLine"版本,因此稍后进行编译,但是对于不具有这种依赖性的version标记的页面始终进行编译,通常对于不同的页面具有相同的路由是很危险的以后.

It's OK in your case since the non-tagged version depends on the "titleLine" version so is compiled later, but generally it's dangerous to have same routing for different pages, without such a dependency version tagged page is always compiled later.

这篇关于Hakyll说“检测到依赖性周期:...".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆