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

Better error messaging for permalinks with missing trailing slash #3399

Closed
zachleat opened this issue Aug 1, 2024 · 8 comments
Closed

Better error messaging for permalinks with missing trailing slash #3399

zachleat opened this issue Aug 1, 2024 · 8 comments

Comments

@zachleat
Copy link
Member

zachleat commented Aug 1, 2024

This comes up fairly often, most recently at #3379.

@rdela
Copy link
Contributor

rdela commented Aug 1, 2024

Is it worth documenting?

Maybe in Working with Templates > Permalinks > Use template syntax in Permalink or Advanced Usage?

zachleat:

You need to use a trailing slash here or .html extension so that we know you’re outputting an html file

johannesrave:

leaving out the trailing slash from permalinks also leads to github pages delivering these transformed mds with content-type application/octet-stream because, like zach said, they don't get file-endings this way. so if that happens, check your permalinks.

The example in Dynamic permalinks for a directory of content templates does not have a trailing slash, but maybe that doesn’t matter because it is in a Directory Data File?

@aldrDev
Copy link

aldrDev commented Sep 5, 2024

Certainly a +1 for an error message or documentation regarding this (Maybe there is documentation now? but I didn't know what was wrong in order to seek it out);

I missed a trailing slash in my pagination of tags setup (Following this guide: https://www.11ty.dev/docs/quicktips/tag-pages/) and without it the Image plugin transform wouldn't work on these generated pages. I spent a while trying to figure out the problem because everything else on the page was seemingly working ok, like the name of the tag itself and the data was coming through.

I feel mighty silly for having missed a single "/", but some kind of error message would have helped narrow it down quicker :)

@zachleat
Copy link
Member Author

zachleat commented Sep 17, 2024

Eleventy v3.0.0-alpha.21 and v3.0.0-beta.2 will now ship with an error message when templates with a truthy outputPath are missing a file extension.

  • permalink: false fine
  • permalink: foo errors
  • permalink: foo/ fine
  • permalink: foo/index.html fine

Now, this isn’t always an error for every project so you can disable this new error message globally with eleventyConfig.configureErrorReporting({ allowMissingExtensions: true });

@zachleat
Copy link
Member Author

The error message looks like this:

[11ty] Problem writing Eleventy templates:
[11ty] The template at './index.html' attempted to write to './_site/foo' (via `permalink` value: 'foo'), which is a target on the file system that does not include a file extension.
[11ty] 
[11ty] You *probably* want to add a `.html` file extension to your permalink, so that most hosts will know how to correctly serve this file to web browsers. Without a file extension, this file may not be reliably deployed without additional hosting configuration (it won’t have a mime type) and may also cause local development issues if you later attempt to write to a subdirectory of the same name.
[11ty] 
[11ty] Learn more: https://www.zachleat.com/web/trailing-slash/
[11ty] 
[11ty] This is usually but not *always* an error so if you’d like to disable this error message, use `eleventyConfig.configureErrorReporting({ allowMissingExtensions: true });`

@zachleat zachleat added this to the Eleventy 3.0.0 milestone Sep 17, 2024
zachleat added a commit that referenced this issue Sep 17, 2024
@zachleat zachleat added the needs-documentation Documentation for this issue/feature is pending! label Sep 20, 2024
@zachleat
Copy link
Member Author

Added support for eleventyAllowMissingExtension: true data cascade option to skip this error on a per-template (or per-directory) basis.

zachleat added a commit that referenced this issue Sep 27, 2024
zachleat added a commit to 11ty/11ty-website that referenced this issue Sep 27, 2024
@zachleat
Copy link
Member Author

Temporary docs preview deploying to https://11ty-website-git-v3-11ty.vercel.app/docs/permalinks/#trailing-slashes

@zachleat zachleat removed the needs-documentation Documentation for this issue/feature is pending! label Sep 27, 2024
zachleat added a commit to 11ty/11ty-website that referenced this issue Sep 27, 2024
zachleat added a commit that referenced this issue Oct 1, 2024
zachleat added a commit that referenced this issue Oct 1, 2024
@groenroos
Copy link

Could we also add /_headers to the allowlist, as per Cloudflare Pages?

@zachleat
Copy link
Member Author

zachleat commented Oct 1, 2024

@groenroos done!

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

4 participants