Skip to main content

slugify

Function slugify 

Source
pub fn slugify(input: &str) -> String
Expand description

Converts a string to a URL-safe slug.

Lowercases ASCII letters, replaces non-alphanumeric runs with a single -, and trims leading/trailing separators. The result is truncated to 200 bytes on a character boundary, so a slug is always a legal path component on Linux filesystems.

§Examples

assert_eq!(ssg_core::slugify("Hello World!"), "hello-world");
assert_eq!(ssg_core::slugify("Rust & Web"), "rust-web");
assert_eq!(ssg_core::slugify("--leading--"), "leading");
// Long terms are capped in bytes, not characters.
assert!(ssg_core::slugify(&"ا".repeat(400)).len() <= 200);