Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permalinks and filters do not work with pagination #3241

Open
tryoxiss opened this issue Apr 3, 2024 · 0 comments
Open

Permalinks and filters do not work with pagination #3241

tryoxiss opened this issue Apr 3, 2024 · 0 comments

Comments

@tryoxiss
Copy link

tryoxiss commented Apr 3, 2024

Operating system

Fedora 38 Workstation, 64-bit with GNOME 44.3 on Wayland, kernel linux 6.4.9-200.fc38.x86_64

Eleventy

2.0.1

Describe the bug

When attempting to set a permalink structure with pagination, it will always say that it cannot proceed due to them overlapping, even if the format takes care of that.

en
|- some dirs with files in them
|- en.json

I am adding internationalization to my website, but I want to preserve the existing URL structure, having enlish be the implied default language (making it /posts/ rather than /en/posts/ for example). I could do this with redirects, but I really would rather it just output this way for various reasons. So things in the /en/ directory, which I am using to set the language for all english pages in one place (I could override it in other languages, but as my website has grown bigger it makes an increasing amount of sense to sort by language, human or machine, so this seemed like a good oppourtunity to do that).

en.json is a simpler folkder utilizing a filter I found in #1072 (Comment).

{
	"permalink": "{{ page.filePathStem | dropEnFolder }}/index.html"
}

The filter code itself is mostly unmodified, but even the provided version did not work when testing it.

	eleventyConfig.addFilter("dropEnFolder", function (path) {
		if (path.endsWith("/index")) {
			path = path.substring(0, -6);
		}

		const pathToDrop = "/en"
		if (path.indexOf(pathToDrop) !== 0) {
			return path
		}
		return path.slice(pathToDrop.length)
	});

When attempting to build the website, I get the following error:

[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] Output conflict: multiple input files are writing to `target/posts/index/{{ pagination.pageNumber }}/index.html`. Use distinct `permalink` values to resolve this conflict.
[11ty]   1. ./source/en/posts/index.webc
[11ty]   2. ./source/en/posts/index.webc
[11ty]   3. ./source/en/posts/index.webc
[11ty]   4. ./source/en/posts/index.webc
[11ty]   5. ./source/en/posts/index.webc
[11ty]   6. ./source/en/posts/index.webc
[11ty]   7. ./source/en/posts/index.webc
[11ty]   8. ./source/en/posts/index.webc
[11ty]   9. ./source/en/posts/index.webc
[11ty]   10. ./source/en/posts/index.webc
[11ty]   11. ./source/en/posts/index.webc
[11ty]   12. ./source/en/posts/index.webc (via DuplicatePermalinkOutputError)
[11ty] 
[11ty] Original error stack trace: (Repeated output has been truncated…)
[11ty]     at TemplateMap.checkForDuplicatePermalinks (/home/madeline/projects/website/node_modules/@11ty/eleventy/src/TemplateMap.js:803:13)
[11ty]     at TemplateMap.cache (/home/madeline/projects/website/node_modules/@11ty/eleventy/src/TemplateMap.js:488:10)
[11ty]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[11ty]     at async TemplateWriter._createTemplateMap (/home/madeline/projects/website/node_modules/@11ty/eleventy/src/TemplateWriter.js:330:5)
[11ty]     at async TemplateWriter.generateTemplates (/home/madeline/projects/website/node_modules/@11ty/eleventy/src/TemplateWriter.js:360:5)
[11ty]     at async TemplateWriter.write (/home/madeline/projects/website/node_modules/@11ty/eleventy/src/TemplateWriter.js:407:23)
[11ty]     at async Eleventy.executeBuild (/home/madeline/projects/website/node_modules/@11ty/eleventy/src/Eleventy.js:1191:13)
[11ty]     at async Eleventy.watch (/home/madeline/projects/website/node_modules/@11ty/eleventy/src/Eleventy.js:1014:18)
[11ty] Wrote 0 files in 0.28 seconds (v2.0.1)

it's odd, considering all it does is stip /en from the start if present.

I simillarly tried eleventyConfig.addUrlTransform() with my own custom solutoon, which produces the same error but has console logs to show its working and achiving the desired result, before 11ty shuts it down.


Slightly unrelated but another approach I tried that also fails.

	eleventyConfig.addUrlTransform(({ url }) => {
		console.log("---");
		console.log(url);
		// `url` is guaranteed to be a string here even if you’re using `permalink: false`
		
		if (url.startsWith("/en/")) {
			const newUrl = url.replace("/en/", "/");
			console.log(newUrl);
			// return newUrl;
			// return url.replace("/en/", "/");
			console.log("/cats" + url)
			return "/cats" + url
		}

		console.log("---");

		// Returning undefined skips the url transform.
	});

This one does nothing with permalinks in en.json as its handled by the JS. This one actually does run, however it does not produce the desired result -- no URL transform occurs.

---
/404.html
---
---
/da/meow/
---
---
/da/
---
---
/en/
/
/cats/en/
---
/en/posts/
/posts/
/cats/en/posts/
---
/en/posts/1/
/posts/1/
/cats/en/posts/1/
---
/en/posts/2/
/posts/2/
/cats/en/posts/2/
---
/en/posts/3/
/posts/3/
/cats/en/posts/3/
---
/en/posts/4/
/posts/4/
/cats/en/posts/4/
---
/en/posts/5/
/posts/5/
/cats/en/posts/5/
---
/en/posts/6/
/posts/6/
/cats/en/posts/6/
---
/en/posts/7/
/posts/7/
/cats/en/posts/7/
---
/en/posts/8/
/posts/8/
/cats/en/posts/8/
---
/en/posts/9/
/posts/9/
/cats/en/posts/9/
---
/en/posts/10/
/posts/10/
/cats/en/posts/10/
---
/en/posts/11/
/posts/11/
/cats/en/posts/11/
---
/en/posts/post1/
/posts/post1/
/cats/en/posts/post1/
---
/en/posts/post2/
/posts/post2/
/cats/en/posts/post2/
---
/en/posts/post3/
/posts/post3/
/cats/en/posts/post3/
---
/en/posts/post4/
/posts/post4/
/cats/en/posts/post4/
---
/en/posts/post5/
/posts/post5/
/cats/en/posts/post5/
---
/en/somedir/cat/
/somedir/cat/
/cats/en/somedir/cat/
---
/en/somedir/
/somedir/
/cats/en/somedir/
---
/en/meow/
/meow/
/cats/en/meow/
---
/feeds/atom/all.en.xml
---
[11ty] Writing target/404.html from ./source/internal/404.html (liquid)
[11ty] Writing target/feeds/atom/all.en.xml from ./source/feeds/atom/all.en.njk
[11ty] Writing target/da/meow/index.html from ./source/da/meow.md (liquid)
[11ty] Writing target/da/index.html from ./source/da/index.md (liquid)
[11ty] Writing target/en/index.html from ./source/en/en.webc
[11ty] Writing target/en/posts/index.html from ./source/en/posts/index.webc
[11ty] Writing target/en/posts/1/index.html from ./source/en/posts/index.webc
[11ty] Writing target/en/posts/2/index.html from ./source/en/posts/index.webc
[11ty] Writing target/en/posts/3/index.html from ./source/en/posts/index.webc
[11ty] Writing target/en/posts/4/index.html from ./source/en/posts/index.webc
[11ty] Writing target/en/posts/5/index.html from ./source/en/posts/index.webc
[11ty] Writing target/en/posts/6/index.html from ./source/en/posts/index.webc
[11ty] Writing target/en/posts/7/index.html from ./source/en/posts/index.webc
[11ty] Writing target/en/posts/8/index.html from ./source/en/posts/index.webc
[11ty] Writing target/en/posts/9/index.html from ./source/en/posts/index.webc
[11ty] Writing target/en/posts/10/index.html from ./source/en/posts/index.webc
[11ty] Writing target/en/posts/11/index.html from ./source/en/posts/index.webc
[11ty] Writing target/en/posts/post1/index.html from ./source/en/posts/post1.md (liquid)
[11ty] Writing target/en/posts/post2/index.html from ./source/en/posts/post2.md (liquid)
[11ty] Writing target/en/posts/post3/index.html from ./source/en/posts/post3.md (liquid)
[11ty] Writing target/en/posts/post4/index.html from ./source/en/posts/post4.md (liquid)
[11ty] Writing target/en/posts/post5/index.html from ./source/en/posts/post5.md (liquid)
[11ty] Writing target/en/somedir/cat/index.html from ./source/en/somedir/cat.md (liquid)
[11ty] Writing target/en/somedir/index.html from ./source/en/somedir/index.md (liquid)
[11ty] Writing target/en/meow/index.html from ./source/en/meow.md (liquid)
[11ty] Wrote 25 files in 0.30 seconds (12.0ms each, v2.0.1)
[11ty] Watching…
[11ty] Server at http://localhost:8080/

Reproduction steps

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

Expected behavior

  1. Have a page that does pagination
  2. Attempt to set a permalink that would not lead to conflicting URLs
  3. 11ty will say it does

Reproduction URL

No response

Screenshots

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant