11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
https://www.11ty.dev/
MIT License
17.1k stars 494 forks source link

permalink output conflict when more than 2 pages are added to a collection #3113

Closed wcDogg closed 11 months ago

wcDogg commented 11 months ago

Operating system

Windows 11

Eleventy

2.0.1

Describe the bug

Hello - I'm having the strangest issue with permalinks and could use some help.

Repo: https://github.com/wcDogg/eleventy-test

I discovered this in a larger project and reproduced it in the repo above:

This works as expected for the index.html, test-a.md, and test-b.md. However, once a test-c.md is added to either collection, I get this:

[11ty] Output conflict: multiple input files are writing to `public/blog/index.html`. Use distinct `permalink` values to resolve this conflict.
[11ty]   1. ./src/c_blog/index.html
[11ty]   2. ./src/c_blog/index.html (via DuplicatePermalinkOutputError)

I'm not sure what's going on or how to investigate further - any help would be much appreciated :)

Reproduction steps

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See an error

Expected behavior

No response

Reproduction URL

No response

Screenshots

No response

wcDogg commented 11 months ago

Okay, so I see this is happening because /blog/index.html/ is paginated. I know I need a permalink like:

  permalink: "{%- if pagination.pageNumber == 0 -%}/blog/{%- else -%}/blog/{{- pagination.pageNumber -}}/{%- endif -%}"

Sadly, this and variations of it aren't working - maybe I have the syntax wrong?

pdehaan commented 11 months ago

Does anything in this help? https://www.11ty.dev/docs/pagination/#remapping-with-permalinks

Not sure what template syntax you're using, but in case you're using some defaults/LiquidJS, this Note is probably semi-relevant:

[!NOTE] that the above example works in Nunjucks but {{ pagination.pageNumber + 1 }} is not supported in Liquid. Use {{ pagination.pageNumber | plus: 1 }} instead.

wcDogg commented 11 months ago

Figured it out - my permalink above does solve the issue - I had it indented in the YAML :P

BayuAngora commented 6 months ago

I have the same problem with my "blog" section and "quote" section.

blog.json

{
  "tags": "blog",
  "layout": "single",
  "permalink" : "{{ title | slug }}"
}

quote.json

{
  "tags": "quote",
  "layout": "single",
  "permalink" : "{{ title | slug }}"
}
Run npm run build-ghpages

> build-ghpages
> npx @11ty/eleventy

[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] Output conflict: multiple input files are writing to `_site/undefined/index.html`. Use distinct `permalink` values to resolve this conflict.
[11ty]   1. ./content/quote/index.md
[11ty]   2. ./content/blog/index.md (via DuplicatePermalinkOutputError)
[11ty] 
[11ty] Original error stack trace: (Repeated output has been truncated…)
[11ty]     at TemplateMap.checkForDuplicatePermalinks (/home/runner/work/11ty/11ty/node_modules/@11ty/eleventy/src/TemplateMap.js:799:13)
[11ty]     at TemplateMap.cache (/home/runner/work/11ty/11ty/node_modules/@11ty/eleventy/src/TemplateMap.js:[4](https://github.com/BayuAngora/11ty/actions/runs/8506589357/job/23297044915#step:7:5)84:10)
[11ty]     at async TemplateWriter._createTemplateMap (/home/runner/work/11ty/11ty/node_modules/@11ty/eleventy/src/TemplateWriter.js:330:[5](https://github.com/BayuAngora/11ty/actions/runs/8506589357/job/23297044915#step:7:6))
[11ty]     at async TemplateWriter.generateTemplates (/home/runner/work/11ty/11ty/node_modules/@11ty/eleventy/src/TemplateWriter.js:3[6](https://github.com/BayuAngora/11ty/actions/runs/8506589357/job/23297044915#step:7:7)0:5)
[11ty]     at async TemplateWriter.write (/home/runner/work/11ty/11ty/node_modules/@11ty/eleventy/src/TemplateWriter.js:40[7](https://github.com/BayuAngora/11ty/actions/runs/8506589357/job/23297044915#step:7:8):23)
[11ty]     at async Eleventy.executeBuild (/home/runner/work/11ty/11ty/node_modules/@11ty/eleventy/src/Eleventy.js:1160:13)
[11ty] Copied 5 files / Wrote 0 files in 0.12 seconds (v2.0.0)
Error: Process completed with exit code 1.

I got an error because of that permalink part. Even when my single posts has different title.