JSPM

@codeberry/slugger

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 9
  • Score
    100M100P100Q43447F
  • License MIT

A simple and flexible Strapi plugin for automatically generating unique slugs based on configurable fields

Package Exports

  • @codeberry/slugger/package.json
  • @codeberry/slugger/strapi-admin
  • @codeberry/slugger/strapi-server

Readme

Slugger - Strapi Plugin

Slugger is a Strapi plugin that automatically generates SEO-friendly slugs for your content entries based on specified fields.

🚀 Features

  • Automatic slug generation on beforeCreate and beforeUpdate events.
  • Per collection type configuration to specify source and slug fields.
  • Ensures unique slugs within a collection to avoid duplicates.

📦 Installation

Install the plugin via npm:

npm install strapi-plugin-slugger

Or via yarn:

yarn add strapi-plugin-slugger

⚙️ Configuration

To configure Slugger, modify your config/plugins.ts file:

export default {
  slugger: {
    enabled: true,
    resolve: "./src/plugins/slugger",
    config: {
      slugConfig: {
        article: { sourceField: "title", slugField: "slug" },
      },
    },
  },
};

Explanation:

  • article → The collection type to apply slug generation.
  • sourceField: "title" → Field from which the slug is generated.
  • slugField: "slug" → Field where the generated slug is stored.

🛠 Usage

Once configured, the plugin will automatically generate slugs before an entry is created or updated.

  • If an entry in article has 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 sourceField is updated.
  • Ensure the slugField exists in the collection schema.

🤝 Contributing

Want to contribute? Feel free to fork, open issues, or submit PRs!

📄 License

This project is licensed under the MIT License.