Automatically generate URL-friendly slugs from other fields in Ecto schemas.
EctoAutoslugField is an Elixir library that automatically generates URL-friendly slugs from other fields in Ecto schemas. It simplifies creating consistent identifiers for database records by reducing manual boilerplate code. The library integrates seamlessly with Ecto changesets and supports unique constraints.
Elixir developers building applications with Ecto who need to generate slugs for records, such as those creating blog posts, articles, or any content requiring SEO-friendly URLs.
Developers choose EctoAutoslugField for its minimal design, extensibility, and lack of unnecessary dependencies, offering hooks for customization while handling slug generation automatically. It provides flexibility through customizable source fields and conditional regeneration, ensuring slugs are consistent and only updated when needed.
Automatically create slugs for Ecto schemas.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Directly works with Ecto changesets using functions like `maybe_generate_slug()` and supports unique constraints, as demonstrated in the example schema where slug generation is embedded in the changeset pipeline.
Allows overriding `get_sources/2` to define multiple source fields and `build_slug/2` for custom slug transformations, providing flexibility beyond basic options like `:from`.
The `always_change` option lets developers decide whether slugs should always be regenerated or only when source fields change, optimizing performance and consistency.
Depends only on the `ecto` package without `ecto_sql`, keeping the library lightweight and focused on slug generation without unnecessary bloat.
Only supports Ecto versions from 3.7 to below 4.0, making it incompatible with newer Ecto releases and potentially limiting future upgrades, as stated in the README.
Each slug field must be explicitly added to changesets with `maybe_generate_slug()` calls, which can be repetitive and error-prone in applications with many schemas, lacking automatic global triggers.
Relies on the `slugify` package by default, which may not handle all internationalization or edge cases without custom `build_slug/2` overrides, adding complexity for specific needs.