-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Make sluggification visible, customizable, and fail-safe #445
Comments
@erquhart how does the |
Yep, that's the default behavior, but date segments can be used for some light slug templating: https://github.com/netlify/netlify-cms/blob/e388ed1721576221523776bfcf25f7124b5f116c/src/backends/backend.js#L27-L44 |
May happen in tandem with #180. |
We currently overwrite any existing entry when a new entry is created that has the same slug. This is probably best fixed along with this issue. |
I also think we should throw an error if the slug is going to be blank. |
It is a bad idea to silently overwrite entries. If a user creates multiple entries on same day and does not bother about titles, then all entries except last will be lost without any notification. This is easily the worst imaginable behaviour. |
I wonder if we should change or prioritize how we visualize the 'title' field to imply it's importance |
We're actually looking to eliminate it's importance. Right now it's critical because it's used for automated slug creation, which the user can't see or influence. This issue calls for making slug creation interactive. We could pre-fill with whatever's in a title field, but if there's no field (or the slug is blank for any other reason), the entry would fail validation and could not be saved. |
Hi! What's the status on slug editing, anyone working on a suggestion? |
@bjrn no one is working this yet, definitely open to someone taking a stab at it. |
Here's the thing: Without keeping the filename in sync with the slug, it's impossible to look up a single post without parsing the frontmatter of all files in the same collection. E.g., if my app wants the post with slug For this reason—and since URL slugs must be unique anyway—I think it makes more sense to update the filename whenever the slug changes. Regarding how and when the slug changes, I like @hanneskuettner approach. The slug should stop auto-updating once the document is published (which happens at varying times depending on if you use the editorial workflow). After that, a notice is fair, as well as preventing a user from overwriting another file or making a change that would cause merge errors (if there are multiple editorial edits open on the file that would be renamed). Honestly, I think Wordpress really nails their slug behavior, especially in cases where extra bits are added to the complete path. #377 has a screenshot that at least partly shows this behavior. @hanneskuettner If you would, I'd very much appreciate seeing your work on that slug field. :) |
What's the progress on this? |
Hi @michalhudecek this issue is not an easy lift. Do you have a specific use case you're trying to solve? |
I would like to make the slug editable with a warning for editors that this might break already shared links. |
Will the approach in #445 (comment) satisfy your use case? |
Yes, that seems like a perfect solution. |
Just want to share. Problem in my case is that slug does not sync with the title. I use jekyll with netlify cms. When creating a page in Netlify "Hello World Page" this will be saved as "hello-world-page-md". In jekyll this will be generated to "/hello-world-page.html" when the site is built. Problem is when changing the title of the page to "Hello Again World", the markdown is still "hello-world-page.md and therfore the generated page will be "/hello-world-page.html". This causing problems with url not reflecting the page title. I think it is problematic to share a url not reflecting the content of the page. Jekyll can overwrite the generated url with slug variable provided in font matter. Problem is i cant use jekylls liquid variables in font matter. So it wont be dynamic. I could create a field "slug" in the netlify collection. But the only way that would work for me was if it mirrored title, and the field was hidden. So the solution described here might work for me aswell. |
Updating slugs has to be an explicit action. Otherwise, content authors would unknowingly break backlinks all the time. You’d have to account for the update by generating redirect rules for the web server. Traditional CMSs—which may have access to the web server and thus could generate redirects—don’t even do this. If you have access to the code (i.e. you’re not a non-technical content author), the most straightforward way is to just rename the file. |
@tylerbrostrom I think it should be explicit as well, but I'd much rather see this change happen in pieces than it be delayed another 4 years. The vast majority of users only have one content editor. |
@tylerbrostrom i agree. But this may result in a dillemma. Not having relevant keywords in domain / url could hurt your relevant search scoore, preventing you from getting the 1st spot in search lists. But as you mentions, broken backlinks may be a bigger problem. Backlinks also impact the search scoore. I cant prove that this is the case. If anyone can confirm that the url does not affect the search result, then I have no idea what is best. Something crossed my mind. With netlify you can create a _redirects file in root. May be complicated. But if Netlify CMS could manage a file like that. Then changing the slug wouldnt be a problem with already shared links. Just a crazy thought. |
@andreasbalevik I'd prefer a formerSlugs array on the documents themselves for the user to handle based on platform. Some will need redirects, some won't because they're the location of new documents. |
Not crazy at all, but I don't think this should be done by a content management system as it's very specific to how the site is built and deployed. Perhaps a Netlify Build Plugin. |
@hanneskuettner's solution looks great, but I'm guessing it's not implemented yet? When I tried it, I got this error in my editor:
Is this widget something I need to register separately? |
To further @hanneskuettner's example above, widget
config
comparison with hanneskuettner's implementation
➕ works with previously created entries Notes
|
Shopify does this behind the scenes pretty nicely. It edits a redirects file, adding a new entry every time a slug is changed. There's at least one 3rd party app that extends this by adding a redirects management UI. Scans for broken links or something like that and lets you manage multiple aliases for a single url. But I do agree with you that the CMS itself should remain divorced from that in order to support different setups. |
I think https://github.com/sw-yx/netlify-plugin-no-more-404 is supposed to do some of that, but seeking maintainers. |
Any update on this? It's a constant issue for editors for me that they can't go and control slugs of their blog posts for example. |
Not really, this is a complex feature and so far we haven't gotten to it. The best way to start would be a pull request :) |
Default sluggification is simplistic, relying on a title field and performing no inference whatsoever.
With no field named "title", entries currently fail to save.
The ideal fix is to simply make slugs editable in the editor UI.
Considerations:
The text was updated successfully, but these errors were encountered: