| 132 | |
| 133 | |
| 134 | def slugify(title: str, used: set[str], source_path: Path) -> str: |
| 135 | slug = title.lower() |
| 136 | slug = slug.replace("&", " and ") |
| 137 | slug = re.sub(r"[^a-z0-9]+", "-", slug).strip("-") |
| 138 | slug = re.sub(r"-+", "-", slug) |
| 139 | if not slug: |
| 140 | slug = "article-" + hashlib.sha1(str(source_path).encode("utf-8")).hexdigest()[:8] |
| 141 | base = slug[:82].strip("-") or slug |
| 142 | slug = base |
| 143 | counter = 2 |
| 144 | while slug in used: |
| 145 | slug = f"{base}-{counter}" |
| 146 | counter += 1 |
| 147 | used.add(slug) |
| 148 | return slug + ".md" |
| 149 | |
| 150 | |
| 151 | def translate_markdown(source: str, title_en: str, chinese_href: str, english_href: str) -> str: |