-
-
Notifications
You must be signed in to change notification settings - Fork 494
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
Easier global Support for urls without trailing slashes #213
Comments
It’s a matter of constructing your links across your page to not include a trailing slash. Eleventy (or any other static site generator for that matter) does not redirect anything on its own, it just helps generating a file structure of documents and resources. That redirecting bit is done by your web server. Checking out my site, I see that my web server seems to opt for a trailing slash at the end even if the requested URL doesn’t contain one. I suppose that could be configured to not display a trailing slash for such requests. (A little bit more details. Not sure if you know this, but for the sake of documentation, I’ll leave it here.) One thing that comes into play here is the way most static site generators construct permalinks: For a file slug |
Here’s what I found when doing a little more specific research on this: Relative URLsSlashes are better if you’re using relative URLs: Avoid duplicate contentNo matter which style you choose, you need to avoid duplicate content (SEO and Canonical URLs): This blog post doesn’t necessarily take a side, however it does espouse that servers should be configured so that a canonical version of the URL is specified and consistency is enforced throughout your site. So if you prefer slashless, this means server configuration to redirect from slash versions to slashless. Or if you prefer slashes, server configuration to redirect from slashless to use slashes. This does suggest that Eleventy sites may need additional configuration (in our current slash setup) to 301 redirect to slash versions of urls if slashless are requested. For example if
While you can use However, that’d be an extra nicety that I’m comfortable not including in the core package. since we don’t redirect—there is no danger of duplicate content out of the box. Server ConfigurationLet’s go through the hypothetical of creating a slash-less resource in Eleventy. What might that look like? For example, you can do this in Eleventy today: test.md:
If I run Eleventy, it generates a resource like this: So it makes a resource at It doesn’t have the right Certainly you could setup your server to serve these resources as HTML content-types but that requires server specific configuration (maybe an The current behavior for a What would happen if you’d used test2.md:
Because So Hope that helps explain it. I think slashless would create a lot more support tickets and maintenance issues than I’d like. I don’t see very many upsides to it other than cosmetic preferences but I see a lot of downsides. Does that make sense to you? |
I thought this tweet was good for understanding some of the issue: I do want to weigh in and say that I’m not saying no to this. I’m fine putting it in the enhancement queue and letting people upvote on it as a non-default feature request. I think it’s a fairly common thing that exists in the wild. I just noticed GitHub gets this wrong though
…with no canonical HTML tag or 301 redirect. They both return 200’s. ¯_(ツ)_/¯ |
Thanks for the detailed response. It's not a major thing for me - very much a nice to have. Happy to see if others are interested in it. |
I think the implementation would probably be closer to using It's probably also worth noting that you can do this yourself today using directory data files to set a permalink for a group of templates in a single place. That might be worth documenting as an example somewhere. |
This repository is now using lodash style issue management for enhancements. This means enhancement issues will now be closed instead of leaving them open. The enhancement backlog can be found here: https://github.com/11ty/eleventy/issues?utf8=%E2%9C%93&q=label%3Aneeds-votes+sort%3Areactions-%2B1-desc+ Don’t forget to upvote the top comment with 👍! |
I've had another look at this - you're right it looks like we can rely on the server (eg Netlify) to sort this, and use permalinks. However it's hard to develop as the local server doesn't do this, so in local development my link to |
Hey @edwardhorsford I opened #239 which I think would help with this—what do you think? If you link to input files then you can avoid hardcoding URLs in your templates. |
I think it could work? FWIW I think if I wanted to keep slashless, I could actually change my internal links to point to For now, I've just moved my site over to using trailing slashes. |
What @edwardhorsford said. Users are already able to use or not use trailing slashes by making sure their paths (e.g. in |
i would like the option to ensure that my servers (both local and live) are set up to not have trailing slashes, so currently its a bit of a pain having to manually set urls or run regex on them in my templates |
For what it's worth, the |
@Ryuno-Ki im not sure how thats related? its not the use of |
Ah, my quote wasn't posted >_<
The „by default” is not strictly correct here. |
I've been having a hard time with this issue in general. I'm porting an existing site, with an existing static server in production, that doesn't use trailing slashes. So any opinions on the best URL structure is irrelevant, because I'm only trying to replace Jekyll with Eleventy without other changes. So far the problem is that I either have to choose a permalink without the I think there should be some separation between the output path and the canonical URL for a file, since servers can handle these in a number of ways, ie |
Hey @justinfagnani, |
@Ryuno-Ki no. I'm not having a problem setting the permalink, I already set it globally. The problem is that permalink and page.url are the same - both have the file extension or not. So when I use page.url in collections I have to run it though a filter to remove the extension, and have to remember to do that any place I want to generate a link. |
If you're using Eleventy 2.x.x, you can create the file module.exports = {
// Remove trailing slashes
permalink: (data) =>
data.permalink
? data.permalink
: data.page.outputFileExtension === "html" && data.page.filePathStem
? `${data.page.filePathStem}.html`
: "",
}; |
Is it possible for Eleventy to support sites without trailing slashes? At the moment it looks like it adds them / redirects to the url version with the slash.
My existing site does not use them. Since Eleventy redirects
foo
tofoo/
, urls will all still work, but I have a slight preference for the former.I know some static site generators support this, though not all.
The text was updated successfully, but these errors were encountered: