eleventy
eleventy copied to clipboard
Trying to paginate a custom collection throws an error
Hey guys,
Moving over from Jekyll and WordPress (to my shame) and I love Eleventy so far. I'm using the Eleventy/Netlify Boilerplate project. My repo is here.
Quick issue I'm facing:
I've added tags to all files in a folder called augmented
by creating a file titled augmented.json
. The file contains:
{
"layout": "layouts/augmented.njk",
"tags": [
"augmented"
]
}
It's my understanding that this will then create a custom collection titled augmented
. I then try to paginate this collection in the corresponding augmented.njk
template, like so:
---
layout: layouts/base.njk
templateClass: tmpl-post
pagination:
data: collections.augmented
size: 1
alias: augmented
---
I'm doing this so I can create a nextPage/previousPage link as per issue #221. However, when I attempt to build, I receive the following error:
Problem writing Eleventy templates: (more in DEBUG output)
> Dependency Cycle Found: ___TAG___all -> ./posts/augmented/and-he-weeps.md -> ___TAG___augmented -> ./posts/augmented/and-he-weeps.md (Error):
Error: Dependency Cycle Found: ___TAG___all -> ./posts/augmented/and-he-weeps.md -> ___TAG___augmented -> ./posts/augmented/and-he-weeps.md
at /usr/local/lib/node_modules/@11ty/eleventy/node_modules/dependency-graph/lib/dep_graph.js:28:17
at Array.forEach (<anonymous>)
at DFS (/usr/local/lib/node_modules/@11ty/eleventy/node_modules/dependency-graph/lib/dep_graph.js:22:24)
at /usr/local/lib/node_modules/@11ty/eleventy/node_modules/dependency-graph/lib/dep_graph.js:24:9
at Array.forEach (<anonymous>)
at DFS (/usr/local/lib/node_modules/@11ty/eleventy/node_modules/dependency-graph/lib/dep_graph.js:22:24)
at /usr/local/lib/node_modules/@11ty/eleventy/node_modules/dependency-graph/lib/dep_graph.js:24:9
at Array.forEach (<anonymous>)
at DFS (/usr/local/lib/node_modules/@11ty/eleventy/node_modules/dependency-graph/lib/dep_graph.js:22:24)
at /usr/local/lib/node_modules/@11ty/eleventy/node_modules/dependency-graph/lib/dep_graph.js:229:9
The .md
file which appears in the error is simply the first one in the folder. The error isn't thrown when I use collections.post but I want to create a next/previous link for this specific collection and not all my posts Any idea why this is happening?
Another weird part of this is that calling collections.augmented elsewhere does work. My index page has:
<ul id="collectionList">
{%- for post in collections.augmented -%}
<li><i class="far fa-moon"></i><a href="{{ post.url | url }}">{{ post.data.title }}</a></li>
{%- endfor -%}
</ul>
This works perfectly fine.
I am experience this same error:
Dependency Cycle Found: ___TAG___all -> ./src/about/the-team/team-members.njk -> ___TAG___teamMembers -> ./src/about/the-team/team-members.njk
I have a structure as follows:
- /about
- /the-team
- /member1
- member1.md
- member1.jpg
- /member2
- member2.md
- member2.jpg
- team-members.njk
- the-team.json
- about.njk
- about.json
about.json
{
"layout": "page"
}
the-team.json
{
"tags": "teamMembers",
"permalink": false
}
member1.md
---
firstName: Test
lastName: Member
titleOrPosition: President
leaderType: Director
---
Lorem ipsum...
team-members.njk
---
pagination:
data: collections.teamMembers
size: 1
alias: teamMember
filter:
- all
permalink: "about/the-team/{{ teamMember.fileSlug | slug }}/"
renderData:
title: "{{teamMember.data.firstName}} {{teamMember.data.lastName}}"
tags: []
---
<div>
<a>
<span style="background-image:url('{{ teamMember.fileSlug }}.jpg');"></span>
<span>{{ teamMember.data.firstName }}
{{ teamMember.data.lastName }}</span>
<span>{{ teamMember.data.leaderType }}</span>
</a>
<div>
<div>
{{ teamMember.templateContent | safe }}
</div>
</div>
</div>
What I'm expecting is for team-members.njk
to be used as the common 'local' layout for all member*.md
data since all the member*.md
files inherit the permalink: false
from the-team.json
.
I don't understand why this is an issue since team-members.njk
has tags: []
, isn't inheriting the teamMembers
tag from anywhere, and has all
in the pagination filter:
If I add eleventyExcludeFromCollections: true
to team-members.njk
, the cyclic dependency error is resolved, but it's not at all clear why this should be required.
An aside: Changes to the-team.json
, member*.md
files or my team-members.njk
file do not trigger rebuilds in --watch
mode, however changes to any of the other files do trigger rebuilds. Weird? Broken?
Hmm, just tested this out locally and currently we can't paginate a collection without the following error being thrown:
tannerdolby:11ty-tester TannerDolby$ eleventy
Problem writing Eleventy templates: (more in DEBUG output)
> Dependency Cycle Found: ___TAG___all -> ./src/quiz/page-two.md -> ___TAG___quiz -> ./src/quiz/page-two.md
`Error` was thrown:
Error: Dependency Cycle Found: ___TAG___all -> ./src/quiz/page-two.md -> ___TAG___quiz -> ./src/quiz/page-two.md
at /Users/TannerDolby/.nvm/versions/node/v11.0.0/lib/node_modules/@11ty/eleventy/node_modules/dependency-graph/lib/dep_graph.js:43:17
at /Users/TannerDolby/.nvm/versions/node/v11.0.0/lib/node_modules/@11ty/eleventy/node_modules/dependency-graph/lib/dep_graph.js:268:11
at Array.forEach (<anonymous>)
at DepGraph.overallOrder (/Users/TannerDolby/.nvm/versions/node/v11.0.0/lib/node_modules/@11ty/eleventy/node_modules/dependency-graph/lib/dep_graph.js:267:14)
at TemplateMap.getMappedDependencies (/Users/TannerDolby/.nvm/versions/node/v11.0.0/lib/node_modules/@11ty/eleventy/src/TemplateMap.js:122:18)
at TemplateMap.cache (/Users/TannerDolby/.nvm/versions/node/v11.0.0/lib/node_modules/@11ty/eleventy/src/TemplateMap.js:278:30)
at TemplateWriter._createTemplateMap (/Users/TannerDolby/.nvm/versions/node/v11.0.0/lib/node_modules/@11ty/eleventy/src/TemplateWriter.js:170:28)
Wrote 0 files in 0.16 seconds (v0.11.1)
---
pagination:
data: collections.quiz
size: 2
alias: quiz
permalink: "/quiz/{{ quiz.title | slug }}/"
---
Where there is a directory /quiz
that holds the markdown files with tags: quiz
in front matter. If I add eleventyExcludeFromCollections: true
then the build succeeds without errors but the template isn't transformed to HTML during the build.
TLDR; Paging an object or anything other than collection works as expected. But no matter how you slice it, something is breaking when we pass a collection to the data
key in pagination
.
@zachleat ping
I was getting the same error after upgrading from 0.12 -> 1.0
In my case, the collection that failed was caused by the same tag being included by both a directory data file, and in the frontmatter of individual pages. Using frontmatter solely to define tags worked as expected.
(That doesn't feel like a conclusive bug definition, but may be of interest to others debugging the same error message.)
Aha, because deep data merge is enabled by default in 1.0!
So be aware, if you're adding tags via directory data, be sure to override or at least don't add the same tag again in frontmatter.
I'm trying to achieve something similar, only difference is, that some of my posts are going to have sub pages, some are not. I have to sort them into collections, so the listing should be automatic. (I've explained my issue here)
However I'm stuck with using a specific tag only. I get the same error as OP did. I saw @tobystokes's reply about the deep data merge, and I set it to false in my .eleventy.js
but I keep getting the same error :/
You can check here what I'm having so far. My goal is: if the post has more pages, add a pagination, if not, hide it. Note, currently throws an error if you try to run it.
The pagination can be found under _includes/layouts/project.liquid
(this is my posts' layout file)
The post I want to have more pages chapters is under posts/bouquet-preview-app-case-study
Unfortunately this issue slipped under the radar—I’m finally circling back through some of the old issues on the tracker but I’d love a confirmation that this old one is still relevant before I start debugging! If I don’t hear anything in the next two weeks, I’ll likely close it as stale—sorry (and thank you!)
I can still recreate the same error message Dependency Cycle Found: ___TAG___all -> ./src/blog/index.njk -> ___TAG___blog -> ./src/blog/index.nj
(which is the page that does pagination) - not sure it's exactly the same situation as original poster, but quite likely connected.
given blog/a-post.md frontmatter:
---
tags:
- blog
- news
---
combined with data blog/blog.json:
{
"layout": "post.njk",
"tags": "blog",
}
Having the same tag from both sources causes the error. If I remove the duplicate tag from the frontmatter, all good. With data deep merge enabled, I would expect/hope the two sources to merged nicely* (* hmm ok fair enough I wouldn't expect a merged array to remove duplicates. But having a duplicate tag in either the frontmatter or data source alone doesn't cause the cyclical error.)
(but mostly, thanks for 11ty @zachleat !)
I'm getting the same error, for me even if I don't have the same tag in the frontmatter.
posts/post.md
---
layout: layouts/default.njk
pagination:
data: collections.post
size: 1
---
posts/post.json
{
"layout": "layouts/post.njk",
"tags": [ "post" ]
}
@lolaodelola I was able to get your example working (after renaming posts/post.json to a plural posts/posts.json) and adding eleventyExcludeFromCollections: true
to the posts/post.md front matter (I'm guessing it didn't like trying to recursively paginate over a collection that it is a part of).
---
layout: layouts/default.njk
pagination:
data: collections.post
size: 1
alias: p
eleventyExcludeFromCollections: true
---
<pre>{{ p.data.title }}</pre>
[11ty] Wrote 8 files in 0.06 seconds (v1.0.1)
Thanks so much @pdehaan!! I had changed the filename but hadn't added the eleventyExcludeFromCollections: true
. The error is gone now but the pagination (seemingly) isn't working & no errors. I'll continue to debug, thanks again 😊
@lolaodelola If you post a public repo, I can take a look and help debug.
@pdehaan Thanks for the offer, I got it working (not sure how lol).
This is an automated message to let you know that a helpful response was posted to your issue and for the health of the repository issue tracker the issue will be closed. This is to help alleviate issues hanging open waiting for a response from the original poster.
If the response works to solve your problem—great! But if you’re still having problems, do not let the issue’s closing deter you if you have additional questions! Post another comment and we will reopen the issue. Thanks!