strapi-community / strapi-plugin-slugify

A plugin for Strapi Headless CMS that provides the ability to auto slugify a field for any content type.
https://market.strapi.io/plugins/strapi-plugin-slugify
MIT License
45 stars 21 forks source link

Changing titles back and forth to the original title causes the slug count to increase #58

Closed IHIutch closed 2 years ago

IHIutch commented 2 years ago

If I have a post titled A and change it to B and then back to A again, the slug will become a-2.

Continuing to change the titles back and forth continues the count.

This could be a problem if you change a title but later decide to change it back. (Or in my circumstance, debugging purposes)

IHIutch commented 2 years ago

Hm, actually, I seem to be having the same problem if I simply update a post at all.

Here's my config:


slugify: {
    enabled: true,
    config: {
      contentTypes: {
        post: {
          field: "slug",
          references: "title",
        },
        event: {
          field: "slug",
          references: "title",
        },
      },
      slugifyOptions: {
        lower: true,
        strict: true,
      },
      slugifyWithCount: true,
    },
  },
ComfortablyCoding commented 2 years ago

Yes, this is intended behaviour.

If you change the title back and forth or update the post with the title field present in the body it will treat it as a new title. We can potentially mitigate this by adding a check if the title is exactly the same for the entity in question. That will not account for other entity records that have the same number though.

The slugify with count is not an ideal way to uniquely identiy slugs. I would suggest using the entity id as part of the composite reference. At the moment adding the id as a reference does not work due to a bug that was in strapi (see #28). Now that the PR fix was merged I plan to fix the issue within the next week or so.