MCPcopy Create free account
hub / github.com/crisxuan/bestJavaer / slugify

Function slugify

scripts/generate_english_articles.py:134–148  ·  view source on GitHub ↗
(title: str, used: set[str], source_path: Path)

Source from the content-addressed store, hash-verified

132
133
134def 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
151def translate_markdown(source: str, title_en: str, chinese_href: str, english_href: str) -> str:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected