eleventy icon indicating copy to clipboard operation
eleventy copied to clipboard

Better error messaging for permalinks with missing trailing slash

Open zachleat opened this issue 1 year ago • 1 comments

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

zachleat avatar Aug 01 '24 17:08 zachleat

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?

rdela avatar Aug 01 '24 17:08 rdela

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 :)

hejchristiandev avatar Sep 05 '24 20:09 hejchristiandev

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 avatar Sep 17 '24 22:09 zachleat

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 avatar Sep 17 '24 22:09 zachleat

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

zachleat avatar Sep 27 '24 20:09 zachleat

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

zachleat avatar Sep 27 '24 22:09 zachleat

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

groenroos avatar Oct 01 '24 13:10 groenroos

@groenroos done!

zachleat avatar Oct 01 '24 16:10 zachleat