11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.

Home Page:https://www.11ty.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pagination fails on `collections['tag with spaces']` but not `collections.tag with spaces`

Aankhen opened this issue · comments

Operating system

Windows 10 64-bit

Eleventy

2.0.0

Describe the bug

Paginating collections['tag with spaces'] fails, but collections.tag with spaces works.

Reproduction steps

Given post.njk:

---
tags: ['tag with spaces']
---

This is a post.

Paginating collections['tag with spaces'] fails:

❯❯ cat posts.njk
---
pagination:
  data: "collections['tag with spaces']"
  size: 1
---

This is the tag page.

❯❯ npx @11ty/eleventy
[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] Could not find pagination data (./posts.njk), went looking for: collections['tag with spaces'] (via Error)
[11ty]
[11ty] Original error stack trace: Error: Could not find pagination data (./posts.njk), went looking for: collections['tag with spaces']
[11ty]     at Pagination._get (D:\Media\src\my\eleventy-pagination-test\node_modules\@11ty\eleventy\src\Plugins\Pagination.js:166:13)
[11ty]     at Pagination.setData (D:\Media\src\my\eleventy-pagination-test\node_modules\@11ty\eleventy\src\Plugins\Pagination.js:86:29)
[11ty]     at new Pagination (D:\Media\src\my\eleventy-pagination-test\node_modules\@11ty\eleventy\src\Plugins\Pagination.js:24:10)
[11ty]     at Template.getTemplates (D:\Media\src\my\eleventy-pagination-test\node_modules\@11ty\eleventy\src\Template.js:703:21)
[11ty]     at TemplateMap.initDependencyMap (D:\Media\src\my\eleventy-pagination-test\node_modules\@11ty\eleventy\src\TemplateMap.js:435:41)
[11ty]     at async TemplateMap.cache (D:\Media\src\my\eleventy-pagination-test\node_modules\@11ty\eleventy\src\TemplateMap.js:486:5)
[11ty]     at async TemplateWriter._createTemplateMap (D:\Media\src\my\eleventy-pagination-test\node_modules\@11ty\eleventy\src\TemplateWriter.js:330:5)
[11ty]     at async TemplateWriter.generateTemplates (D:\Media\src\my\eleventy-pagination-test\node_modules\@11ty\eleventy\src\TemplateWriter.js:360:5)
[11ty]     at async TemplateWriter.write (D:\Media\src\my\eleventy-pagination-test\node_modules\@11ty\eleventy\src\TemplateWriter.js:407:23)
[11ty]     at async Eleventy.executeBuild (D:\Media\src\my\eleventy-pagination-test\node_modules\@11ty\eleventy\src\Eleventy.js:1160:13)
[11ty] Wrote 0 files in 0.03 seconds (v2.0.0)

But collections.tag with spaces works:

❯❯ cat posts.njk
---
pagination:
  data: "collections.tag with spaces"
  size: 1
---

This is the tag page.

❯❯ npx @11ty/eleventy
[11ty] Writing _site/post/index.html from ./post.njk
[11ty] Writing _site/posts/index.html from ./posts.njk
[11ty] Wrote 2 files in 0.05 seconds (v2.0.0)

When I added

Expected behavior

No response

Reproduction URL

https://github.com/Aankhen/11ty-pagination-bug

Screenshots

No response

By fiddling with the local copy of Pagination.js, I noticed that setCollectionByTagName is called in the second (functional) case but not the first.

Successfully reproduced!

Fix will ship with 2.0.1