- Extract serp.py into serp/ package for better testability - serp/app.py: FastAPI app, LanguageMiddleware - serp/server.py: All route handlers - serp/i18n.py: Translations, LANG_NAMES with flags - serp/models.py: CrawlRequest model - serp/archive.py: Tarball handling - serp/logging.py: Job logging - serp/utils.py: slugify function - Add /eggs endpoint listing easter eggs: - #0: ?lang=XX forces language via middleware - #1: OVER_9000 pagination limit - #2: The 72 Rules of St. Benedict (A Way) - Fix test module import issue (app_module -> app_config) - LANG_NAMES includes flags and codes (e.g., 🇺🇸 EN English)
14 lines
481 B
Python
14 lines
481 B
Python
"""Utility functions for SERP."""
|
|
|
|
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 ""
|