From 99161b19d3f739acafd3cb5f2b2a6e27509df288 Mon Sep 17 00:00:00 2001 From: qinxuye Date: Tue, 9 Jun 2026 11:20:26 +0800 Subject: [PATCH] docs: hide Zhihu link from English docs --- doc/source/conf.py | 24 ++++++++++++++++++++++++ doc/source/index.rst | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index f3ae04cb39..98b96fb4da 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -14,6 +14,8 @@ # import sys # sys.path.insert(0, os.path.abspath('.')) +from docutils import nodes + # -- Project information ----------------------------------------------------- @@ -73,6 +75,8 @@ json_url = "https://inference.readthedocs.io/en/latest/_static/switcher.json" if not version_match: version_match = 'en' +if version_match == 'zh-cn': + tags.add("zh_cn") html_theme_options = { "show_toc_level": 2, @@ -130,3 +134,23 @@ ] html_favicon = "_static/favicon.svg" + + +def _remove_non_zh_cn_nodes(app, doctree, docname): + current_language = getattr(app.config, "language", None) + is_zh_cn = version_match == "zh-cn" or current_language in {"zh_CN", "zh-cn"} + if is_zh_cn: + return + + for node in list( + doctree.findall( + lambda n: isinstance(n, nodes.Element) + and "zh-cn-only" in n.get("classes", []) + ) + ): + if node.parent is not None and node in node.parent: + node.parent.remove(node) + + +def setup(app): + app.connect("doctree-resolved", _remove_non_zh_cn_nodes) diff --git a/doc/source/index.rst b/doc/source/index.rst index b6d608960a..3453caf49f 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -238,8 +238,9 @@ Getting Involved :fab:`twitter` Follow us on Twitter - .. grid-item-card:: + .. grid-item-card:: :link: https://zhihu.com/org/xorbits + :class-item: zh-cn-only :fab:`zhihu` Read our blogs