web / lib/utils/slug
lib/utils/slug
Provides utility functions for generating and validating URL-friendly slugs.
This module contains helpers for creating unique, SEO-friendly slugs from a given string (like a title or name). It includes functionality to:
- Sanitize a string into a basic slug format.
- Check for the uniqueness of a slug within a specific collection to prevent duplicates.
- Generate a unique slug by appending a random suffix if a conflict is found.
- A factory function (
createSlugHook
) to easily integrate this logic into Payload CMS collection field hooks.