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 size causes error: Use distinct `permalink` values

madsem opened this issue · comments

Describe the bug
I've recently built a site with 11ty and i am super happy, great site builder :)

So I've "amassed" 6 posts, finished another post (a.k.a the 7th) and hit publish in my Netlify CMS.
All of a sudden I see the build failed, with this error:

11:21:37 AM: [success] [webpackbar] Mix: Compiled successfully in 1.03m
11:21:37 AM: webpack compiled successfully
11:21:42 AM: Problem writing Eleventy templates: (more in DEBUG output)
11:21:42 AM: > Output conflict: multiple input files are writing to `dist/index.html`. Use distinct `permalink` values to resolve this conflict.
11:21:42 AM:   1. ./site/index.njk
11:21:42 AM:   2. ./site/index.njk
11:21:42 AM: `DuplicatePermalinkOutputError` was thrown:

So I wonder, why would it list the same file twice, ehhh?

After a git pull and some testing, I realize that my homepage layout, the one index.njk is referring to,
has pagination size 6 set, and I remember I have 6 posts, and the new one is my 7th... Could it have anything to do with that?
And yes, after adjusting size to 7, it builds without issues.

index.njk

---
permalink: "/"
layout: home
---

home layout

---
layout: base
pagination:
 data: collections.products
 size: 7
 reverse: true
 alias: lists
---

Now, I do not have any pagination built into my site, yet. I just wanted to list the 6 latest pages/posts on my homepage
for the moment.

To Reproduce
I don't know how, except the way I wrote above

Expected behavior
That it builds all 7 posts, but lists only 6 on homepage.

Environment:

  • OS and Version: macOS 11.5
  • Eleventy Version 0.12.1

This sounds like your "base" layout has a permalink that is not unique when building multiple pages.
If you could link you git, someone could take an exact look at it and tell you what is wrong.
For now you could set pagination.size to be infinitely large until you build the pagination.

Thanks @Snapstromegon , sadly can't link to the repo as it is private.

So I assume if I add pagination code, 11ty would be able to build index.html files that are paginated?
But shouldn't it simply stop trying to build paginated pages after hitting size?

Because I expected that it's possible to only show XY items on homepage, but still have all pages be built?

11ty automatically does pagination with urls that don't clash, but if your layout sets a permalink, this is overwritten and the problem reoccurs. You can look at the examples from the documentation on how to set permalinks which honor the current page.

The size attribute in pagination just tells 11ty to build pages with 6 items each max, so 15 items total would give you 3 pages (with 6, 6 and 3 items).

If you want to build a preview of x Items, pagination is not what you want to do, but to use collections and filters of the language of your choice (e.g. collections.posts | slice: 0, 6 in liquid) .

Okay, that actually makes a lot of sense haha.

I was using pagination, because sometime in the future I plan on adding this, I just did not think it through as it seems.
Will change the homepage to slice 6 posts and report back