Skip to content
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

Add ability to customize slug uniqueness resolution #611

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

viicslen
Copy link

This pull request introduces a new feature to allow for personalization of unique slugs. If the slug is not unique and you want to try to make it unique by replacing some other parts of the slug instead of adding a suffic, you can set the uniqueUsing configuration option to a closure which accepts the base slug, the separator, and a Collection of the other "similar" slugs as arguments. The closure should return the new unique slug to use, if the slug is still not unique, it will append a suffix to the returned slug.

Missing:

  • added tests
  • documented any change in behaviour (e.g. updated the README.md, etc.)

@cviebrock
Copy link
Owner

I like this idea ... but have a few thoughts:

Instead of making this a new configuration setting, we could just change the way the current unique setting works:

  • if unique is false, do nothing
  • if unique is true, add a suffix
  • if unique is a callable, use that

For something like this, I might extract all the existing code that handles suffixes into it's own class, and just make that the default value for unique, so we're always running a callable ... either the built-in one, or a custom one like you envisioned.

I'm also curious ... what was your use-case for this? And could we add some tests for your PR?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants