strapi-community / strapi-plugin-slugify

A plugin for Strapi Headless CMS that provides the ability to auto slugify a field for any content type.

Home Page:https://market.strapi.io/plugins/strapi-plugin-slugify

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

slugifyWithCount is non persistent between project restarts

selected-pixel-jameson opened this issue · comments

I don't want duplicate slugs to be allowed in any capacity. However, I'm noticing that when the first duplicate slug is generated it doesn't append the correct -1 to it. For example:

Title = "Test"
Slug = "test"

Title = "Test" ( In this case the slug should be generated as test-1, but it's not.)
Slug = "test"

Title = "Test" ( In this case the slug should come out as test-2)
Slug = "test-2"

So for some reason the first time a duplicate slug is generated the count is not getting attached to the generated slug. However, the next time a duplicate slug is generated the count is attached correctly.

These are the setting I have
``
slugify: {
enabled: true,
config: {
slugifyWithCount: true,
contentTypes: {
jam: {
field: 'slug',
references: 'title',
},
track: {
field: 'slug',
references: 'title'
},
},
},
},


I'm using the latest version `2.3.1`

This seems to be an issue with the slug not being normalized. The example provided above would actually work correctly. What would not work correctly would be.

Title = "test"
Slug = "test"

Title = "Test" ( In this case the slug should be generated as test-1, but it's not.)
Slug = "test"

Title = "test" ( In this case the slug should come out as test-2)
Slug = "test-2"

Well this is very strange now. I only can replicate this on my development and production environments. It does not seem to happen on my local environment. I know that all the versions are the same across these environments. I'm at a lose as to why this would be happening.

WOW! The count for any given slug is stored using a constant in the programming and is not calculated off the actual number of fields in the database that have a title with the slug. These means every time you restart your server the number will get reset, thus you will never have truly unique slugs. If you were running a scalable environment this would be hosed from the get go.

I cannot replicate the original reported behaviour of different casing resulting in a different count.

In regards to non persisten slug count that will be fixed by #82

Fixed in v2.3.2