Expand description
Unique, transliterated slugs for SeaORM entities.
Describe the slug once, and it is filled in on every save:
use sea_orm::entity::prelude::*;
use sea_orm_sluggable::{SlugConfig, Sluggable};
impl Sluggable for categories::ActiveModel {
fn slug_config() -> SlugConfig<Self> {
SlugConfig::new([categories::Column::Title], categories::Column::Slug)
}
}
#[async_trait::async_trait]
impl ActiveModelBehavior for categories::ActiveModel {
async fn before_save<C: ConnectionTrait>(self, db: &C, insert: bool) -> Result<Self, DbErr> {
// "Rust for PHP developers" -> "rust-for-php-developers",
// or "rust-for-php-developers-1" when that one is taken.
Ok(sea_orm_sluggable::fill_slug(self, db, insert).await?)
}
}Text is transliterated to ASCII first. The default, AnyAscii, handles any
script; enable a language feature (for example uk) for official national
rules, or implement Transliterator for your own language.
Modules§
- languages
- National romanization rules, one module per language, each behind its own feature so apps only compile the languages they use.
Structs§
- AnyAscii
- Generic transliteration for every script, via the
any_asciicrate. - Slug
Config - Which columns a slug is built from and stored in, and when it is generated.
- Slug
Options - How slugs are built: separator, length, suffix numbering and transliteration.
Enums§
- Slug
Error - Why a slug could not be generated.
Traits§
- Sluggable
- Gives an
ActiveModelan automatically generated slug. - Transliterator
- Turns text in any script into ASCII before it becomes a slug.
Functions§
- fill_
slug - Fills the slug column of
modelusingSluggable::slug_config. - fill_
slug_ with - Same as
fill_slug, with an explicit configuration. - find_
by_ slug - Finds the row of
Ewhosecolumnequalsslug. - slugify
- Builds a slug from
text, without checking the database. - unique_
slug - Builds a slug from
textthat no row ofEhas incolumnyet.