Netlify-cms: Keep title and slug in sync

Created on 3 Aug 2018  ·  21Comments  ·  Source: netlify/netlify-cms

- Do you want to request a feature or report a bug? Not sure

- What is the current behaviour? Slug is not changing if I update the title

- If the current behaviour is a bug, please provide the steps to reproduce. When I created a new post with the title "A B C" and hit save, the slug is "date-a-b-c" and when I changed the title to "A C B" the slug didn't get changed.

- What is the expected behaviour? It should change as we change or update the title.

- Please mention your versions where applicable.
Netlify CMS version: 2.0.8
Browser version: Chrome 68.0.3440.84

- Please link or paste your config.yml below if applicable.

publish_mode: editorial_workflow
media_folder: "assets/img/uploads"

collections:
  - name: "business"
    label: "Business Blog"
    folder: "_posts/business/"
    create: true
    delete: true
    filter:
      - field: "categories"
        value: "business"
    slug: "{{year}}-{{month}}-{{day}}-{{slug}}"
    fields:
      - label: "Layout"
        name: "layout"
        widget: "hidden"
        default: "post"

      - label: "Author"
        name: "author"
        widget: "string"

      - label: "Title"
        name: "title"
        widget: "string"

      - label: "Date"
        name: "date"
        widget: "datetime"

      - label: "Category"
        name: "categories"
        widget: "select"
        options: 
          - label: "Business"
            value: "business"

      - label: "Description"
        name: "description"
        widget: "text"

      - label: "Image"
        name: "image"
        widget: "string"

      - label: "Body"
        name: "body"
        widget: "markdown"
discussion feature

Most helpful comment

Having a possibility to edit the slug could also be cool.

All 21 comments

Having a possibility to edit the slug could also be cool.

Having a possibility to edit the slug could also be cool.

True.

If someone doesn't want to get into the mess of editing slug, keeping the slug into sync with the title would be a lifesaver.

What I meant by keeping title and slug in sync?

Whenever we change the title, the slug will automatically change accordingly.

Sure editing the slug would also give greater control, 👍 for that.

What could be even better is to make the slug sync with the title BUT only as long as the article is not published (is in draft state). Once the article gets published the slug would never change. This is to make sure that links which point to the old slug will not lead to an error page. But as long as an article is in draft state it is relatively safe to change the slug because ideally no one would link to it. What do you think about this?

This is to make sure that links which point to the old slug will not lead to an error page.

Can you explain this in more detail?

Once the article gets published the slug would never change.

But changing the state of the article from published to draft, changing the slug and then changing the state back _(this is possible)_.

What's your idea to restrict users from not allowing to change slug in the published state?

@mittalyashu
Here is the use-case I have in mind:

When I write a somewhat longer article I usually work on it for a couple of hours or even days. During this time I rewrite/reword most parts of the article even the title. Since the article is not published yet it would be safe to change the slug/filename in sync with the title. Otherwise the slug always represents the first draft of the title and not the one I am going to publish.

After an article has been published changing the title would not update the slug anymore. Because at this time there are potentially many external links pointing to that slug. I would like to avoid dead links. If I felt confident to publish the article with this title then I will usually be OK with the slug even if it differs from the title. Keeping URLs stable are more important.

If I decide to unpublish an article I am fine with changing the slug again in sync with the title. To be honest it has never happened to me that I unpublished an article and then re-published it with a different title. For me this sounds like an edge-case.

TLDR: keeping slugs in sync with title is desired as long as the article is not published. Once it is published I would like to keep the slug stable because of incoming links.

I hope I could clarify your question.

When I write a somewhat longer article I usually work on it for a couple of hours or even days. During this time I rewrite/reword most parts of the article even the title.

Since this can only be achieved by editorial_workflow _(draft and published)_ and it only supports github yet.

If I decide to unpublish an article I am fine with changing the slug again in sync with the title. To be honest it has never happened to me that I unpublished an article and then re-published it with a different title. For me, this sounds like an edge-case.

Yeah, this can be a use-case too. _(same as I have told earlier)_ But as I have mentioned about editorial_workflow changing the state of article from publised to draft and then changing the slug is not so good idea.

So, what can be done:

  1. Wait until NetlifyCMS support both GitLab and BitBucket.
  2. Allow changing slug regardless of published or draft state.

keeping slugs in sync with the title are desired as long as the article is not published. Once it is published I would like to keep the slug stable because of incoming links.

I understand that it is important for SEO and referral links.

This should be more or less addressed as a part of #445.

In the issue #445, it is related to slug, where as issue #1576 is related to update the slug _(url of the post)_ according to the title or editing it.

Right, but we're not sure what this looks like without first seeing how #445 pans out. At a minimum #445 needs to happen first so the behavior is visible - most folks won't want the filename to change, so we need to make sure it's obvious if it does.

most folks won't want the filename to change, so we need to make sure it's obvious if it does.

I understand, but renaming the filename is required since optimizing the file name for SEO is a good practice.

When I change the title of post, I do change the file name too.

Google shows the search related to the search query and if our heading and filename matches the search query there are more changes that we rank higher.

I'd definitely like the filename to change/sync along with editing the title or whatever is in the slug. Waiting to see what #445 will bring but this issue quite important for my use case. Broken links is a non-issue for me. I'm currently trying to work around it by using Git hooks, which is less than ideal.

Being able to name/edit the post slug independent of the post title, should be a feature, as this is a basic SEO practice that every SEO recommends.

For example, if you have a long title for a post:

“A Clear Performance Comparison between Gatsby and WordPress”

Then you’d name the slug something _short_, like: /gatsby-vs-wordpress-performance

Edit-slug is a built-in feature in WordPress (they call it Permalink), and it's a dealbreaker that I can't offer my clients this basic SEO tool with NetlifyCMS.

Other than that NetlifyCMS is really awesome (fast & simple) I just can't recommend it over WordPress to client's that need to follow best SEO practices (which most do), which is a shame.

@TechStacker I handle this in Gatsby using NetlifyCMS by providing a Permalink editable text box and setup the page nodes prior by using this field. Another way I handle this is to take the title on new created pages and build the initial permalink for previews and drafts (more complicated, but works like a charm). The second option makes it less work, but SEO gets built based on other entries during build and allows for permalink change later if needed. The issue with permalink changes for SEO is making sure you are creating _redirects for the broken links already indexed. Creating the SEO strategy for SSG's is not as hard as everyone is making it out to be, just takes time. I tell clients that SEO only needs to be defined to be successful.

That said, I would recommend Static over Wordpress for SEO every time, because I can fix the SEO pieces that are static. I can't fix the Wordpress speed issues as easily or cost effectively. Not to mention the gains of being able to test SEO with Netlify's A/B branch testing that would be cost prohibitive or cost effective on WP.

@TechStacker Netlify CMS isn't stopping you from doing that - just make an additional field to use for url creation, then configure your static site generator to use that. This looks different depending on the generator you use.

For example, let's say you have a Hugo site, a blog post frontmatter might look like this:

---
title: A Clear Performance Comparison between Gatsby and WordPress
slug: gatsby-vs-wordpress-performance
---

And your Hugo config would include something like:

permalinks:
  posts: /:year/:month/:slug/

@erquhart Indeed an extra field to rewrite the slug is possible. But still, Netlify-CMS will continue to sort all the posts by filename with the original {{slug}} that you can't rewrite in the netlify-cms interface, is that right?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Any updates with this feature?

Hi @necheporenko, we try to get to the most upvoted features first. Here is the current status:
https://github.com/netlify/netlify-cms/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc

Just upvoted this. I think this functionality is necessary for a modern CMS.

Regarding the renaming of the file name due to the slug change concern, we could only sync with the title on create, afterward if the entry is edited, the slug would need to be manually updated if the title is updated to preserve the url that has existed unless the change is intentional.

Any updates on this folks? Currently running into this ourselves!

Closing this issue in favor of https://github.com/netlify/netlify-cms/issues/445 to make it easier to track.
See also https://github.com/netlify/netlify-cms/issues/445#issuecomment-621700949

Was this page helpful?
0 / 5 - 0 ratings