Skip to main content

title_to_slug

Function title_to_slug 

Source
pub fn title_to_slug(title: &str) -> String
Expand description

Convert a bean title into a URL-safe kebab-case slug for use in filenames.

Algorithm:

  1. Trim whitespace
  2. Lowercase all characters
  3. Replace spaces with hyphens
  4. Remove non-alphanumeric characters except hyphens
  5. Collapse consecutive hyphens into single hyphen
  6. Remove leading/trailing hyphens
  7. Truncate to 50 characters
  8. Return “unnamed” if empty

§Examples

  • “My Task” → “my-task”
  • “Build API v2.0” → “build-api-v20”
  • “Foo Bar” → “foo-bar”
  • “Implement bn show to render Markdown” → “implement-bn-show-to-render-markdown”
  • “Update Bean parser to read .md + YAML frontmatter” → “update-bean-parser-to-read-md-yaml-frontmatter”
  • “My-Task!!!” → “my-task”
  • “ Spaces “ → “spaces”
  • “” (empty) → “unnamed”
  • “a” (single char) → “a”