"""Utility functions for SERP. # Side quest 2/21: Can he swing from a web? No he can't, he's a pig. """ import re import unicodedata def slugify(text: str, max_len: int = 60) -> str: """Convert text to a safe filename slug.""" # Normalize unicode text = unicodedata.normalize('NFKD', text).encode('ascii', 'ignore').decode('ascii') # Lowercase and replace spaces/special chars with hyphens text = re.sub(r'[^\w\s-]', '', text.lower()) text = re.sub(r'[-\s]+', '-', text).strip('-') return text[:max_len] if text else ""