glugify
Values
pub fn slugify(text: String) -> String
Converts text to a URL-friendly slug using default configuration. This is the simplest API that always returns a string.
Examples
slugify("Hello, World!")
// -> "hello-world"
slugify("Café & Restaurant")
// -> "cafe-and-restaurant"
If the input cannot be processed, returns an empty string.
For error handling, use try_slugify
instead.
pub fn slugify_with(
text: String,
config: config.Config,
) -> Result(String, errors.SlugifyError)
Converts text to a URL-friendly slug using custom configuration. This is the most flexible API that allows full control over the slugification process.
Examples
import glugify/config
let custom_config = config.default()
|> config.with_separator("_")
|> config.with_max_length(20)
slugify_with("A Very Long Title", custom_config)
// -> Ok("a_very_long_title")
Errors
EmptyInput
: When the input text is emptyConfigurationError
: When the configuration is invalidTransliterationFailed
: When a character cannot be transliterated
pub fn try_slugify(
text: String,
) -> Result(String, errors.SlugifyError)
Converts text to a URL-friendly slug with explicit error handling.
Returns Result(String, SlugifyError)
for cases where you need to handle errors.
Examples
try_slugify("My Blog Post")
// -> Ok("my-blog-post")
try_slugify("")
// -> Error(EmptyInput)