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

Function write_indexes

scripts/generate_english_articles.py:318–347  ·  view source on GitHub ↗
(article_map: dict[str, dict[str, str]])

Source from the content-addressed store, hash-verified

316
317
318def write_indexes(article_map: dict[str, dict[str, str]]) -> None:
319 lines = [
320 "# AI Articles",
321 "",
322 "English mirror of the Chinese AI article collection. The Chinese originals remain available in the main `ai-articles` directory.",
323 "",
324 "| Category | Description |",
325 "| --- | --- |",
326 ]
327
328 for category, meta in CATEGORY_META.items():
329 lines.append(f"| [{meta['title']}](./{category}/README.md) | {meta['description']} |")
330
331 lines.extend(["", "## All Articles", ""])
332
333 for category, meta in CATEGORY_META.items():
334 lines.extend([f"### {meta['title']}", ""])
335 write_category_index(category, meta, article_map)
336 source_items = parse_index_items(SOURCE_ROOT / category / "README.md")
337 for date, _title, href in source_items:
338 source_path = (SOURCE_ROOT / category / unquote(href.split("?")[0].split("#")[0].replace("./", ""))).resolve()
339 source_rel = source_path.relative_to(ROOT).as_posix()
340 mapped = article_map.get(source_rel)
341 if not mapped:
342 continue
343 article_href = "./" + str(Path(mapped["english_path"]).relative_to("en/ai-articles")).replace("\\", "/")
344 lines.append(f"- {date} - [{mapped['english_title']}]({article_href})")
345 lines.append("")
346
347 (TARGET_ROOT / "README.md").write_text("\n".join(lines).rstrip() + "\n", encoding="utf-8")
348
349
350def write_category_index(category: str, meta: dict[str, str], article_map: dict[str, dict[str, str]]) -> None:

Callers 1

mainFunction · 0.85

Calls 2

write_category_indexFunction · 0.85
parse_index_itemsFunction · 0.85

Tested by

no test coverage detected