Generate slug from title or entry ID.
(title: str, eid: str)
| 18 | |
| 19 | |
| 20 | def title_to_slug(title: str, eid: str) -> str: |
| 21 | """Generate slug from title or entry ID.""" |
| 22 | h = hashlib.md5(eid.encode()).hexdigest()[:6] |
| 23 | clean = re.sub(r'[^\w\-]', '-', title[:30]).strip('-').lower() |
| 24 | clean = re.sub(r'-+', '-', clean) |
| 25 | if not clean: |
| 26 | clean = eid[:20] |
| 27 | return f"nmpa-gp-{clean}-{h}" |
| 28 | |
| 29 | |
| 30 | def strip_year_revision(title: str) -> str: |