@codeberry/slugger
v1.0.3
Published
A simple and flexible Strapi plugin for automatically generating unique slugs based on configurable fields
Maintainers
Readme
Slugger - Strapi Plugin
🚀 Slugger is a Strapi plugin that automatically generates SEO-friendly slugs for your content entries based on specified fields.
✅ Compatible with Strapi v5.10.2 and above
✨ Features
- ✅ Automatic slug generation on
beforeCreateandbeforeUpdateevents - ✅ Per collection type configuration to specify source and slug fields
- ✅ Ensures unique slugs within a collection to avoid duplicates
- ✅ Custom slug field for each collection type
📦 Installation
Via npm:
npm install @codeberry/sluggerVia yarn:
yarn add @codeberry/slugger⚙️ Configuration
To configure Slugger, modify your config/plugins.ts file:
export default {
slugger: {
enabled: true,
config: {
slugConfig: {
article: { sourceField: "title", slugField: "slug" },
},
},
},
};Configuration Breakdown:
article→ The collection type where slug generation should be appliedsourceField: "title"→ Field from which the slug is generatedslugField: "slug"→ Field where the generated slug is stored
🔧 Adding the Slug Field to Your Collection
This plugin does not automatically add the slug field. You need to manually add it using the Strapi Admin Panel:
Steps to Add the Slug Field:
- Go to Strapi Admin Panel → Content-Type Builder
- Open the collection type where you want to generate slugs (e.g.,
article) - Click "Add another field"
- Navigate to the Custom Fields tab
- Select the field named "Slug"
- Enter a name for the field (e.g.,
slugHereorslug)- This name must match the
slugFieldvalue in your plugin configuration
- This name must match the
- Save and apply the changes
Now, the plugin will store the generated slugs in this field automatically.
🛠 Usage
Once configured, the plugin will automatically generate slugs before an entry is created or updated.
- If an entry in
articlehas a title, it will generate a slug from it. - If a slug already exists, a unique version will be created (e.g.,
my-title,my-title-1).
📌 Example Behavior
| Title | Generated Slug |
|----------------------------|------------------------|
| "Hello World" | hello-world |
| "Hello World" (duplicate) | hello-world-1 |
| "Strapi is Awesome!" | strapi-is-awesome |
🔍 Ensuring Slug Uniqueness
Slugs are made unique within the collection type by appending an incremental counter if necessary.
📝 Notes
- This plugin does not modify existing slugs unless the
sourceFieldis updated. - Ensure the slug field is added using the Custom Fields tab in Strapi Admin.
- The slug field name must match what is set in
slugFieldinside the plugin configuration.
🤝 Contributing
Want to contribute? Feel free to fork the repository, open issues, or submit PRs! 🚀
📄 License
This project is licensed under the MIT License.
