diff --git a/conf.py b/conf.py index fd1a8295..5b61b998 100644 --- a/conf.py +++ b/conf.py @@ -2,6 +2,8 @@ # Migrated off d2lbook to plain Sphinx + MyST-Parser + sphinx-book-theme. # Build: sphinx-build -b html . _build/html +from pathlib import Path + project = "Modern GPU Programming For MLSys" author = "MLC Community" copyright = "2026, MLC Community" @@ -76,7 +78,17 @@ def add_language_switch_button(app, pagename, templatename, context, doctree): if header_buttons is None: return - zh_url = context["pathto"]("zh/index.html", 1) + zh_source_root = Path(app.srcdir) / "zh" + has_translation = any( + (zh_source_root / f"{pagename}{suffix}").is_file() + for suffix in source_suffix + ) + target_page = ( + pagename + if has_translation or pagename in {"search", "genindex"} + else "index" + ) + zh_url = context["pathto"](f"zh/{target_page}.html", 1) header_buttons.append( { "type": "javascript", diff --git a/zh/conf.py b/zh/conf.py index a9014f81..9162f7ba 100644 --- a/zh/conf.py +++ b/zh/conf.py @@ -1,6 +1,8 @@ # Sphinx configuration for the Chinese edition. # Build: sphinx-build -b html zh _build/html/zh +from pathlib import Path + project = "面向 MLSys 的现代 GPU 编程" author = "MLC Community" copyright = "2026, MLC Community" @@ -58,7 +60,17 @@ def add_language_switch_button(app, pagename, templatename, context, doctree): if header_buttons is None: return - en_url = context["pathto"]("../index.html", 1) + en_source_root = Path(app.srcdir).parent + has_translation = any( + (en_source_root / f"{pagename}{suffix}").is_file() + for suffix in source_suffix + ) + target_page = ( + pagename + if has_translation or pagename in {"search", "genindex"} + else "index" + ) + en_url = context["pathto"](f"../{target_page}.html", 1) header_buttons.append( { "type": "javascript",