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

slugifyWithCount is non persistent between project restarts #81

Closed selected-pixel-jameson closed 1 year ago

selected-pixel-jameson commented 1 year ago

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`
selected-pixel-jameson commented 1 year ago

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"

selected-pixel-jameson commented 1 year ago

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.

selected-pixel-jameson commented 1 year ago

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.

ComfortablyCoding commented 1 year ago

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

ComfortablyCoding commented 1 year ago

Fixed in v2.3.2