浏览代码

doc: add commit revision to footer while build with sphinx-multiversion (#939)

Signed-off-by: longjin <longjin@DragonOS.org>
LoGin 6 月之前
父节点
当前提交
09dacded09
共有 2 个文件被更改,包括 13 次插入2 次删除
  1. 12 1
      docs/conf.py
  2. 1 1
      docs/requirements.txt

+ 12 - 1
docs/conf.py

@@ -54,6 +54,8 @@ source_suffix = ['.rst', '.md']
 #
 html_theme = 'sphinx_rtd_theme'
 
+html_context = dict()
+
 # Add any paths that contain custom static files (such as style sheets) here,
 # relative to this directory. They are copied after the builtin static files,
 # so a file named "default.css" will overwrite the builtin "default.css".
@@ -91,4 +93,13 @@ html_baseurl = os.environ.get("READTHEDOCS_CANONICAL_URL", "")
 
 # Tell Jinja2 templates the build is running on Read the Docs
 if os.environ.get("READTHEDOCS", "") == "True":
-    html_context["READTHEDOCS"] = True
+    html_context["READTHEDOCS"] = True
+
+if os.environ.get("SPHINX_MULTIVERSION_GIT_COMMIT", "") != "":
+    html_context["commit"] = os.environ["SPHINX_MULTIVERSION_GIT_COMMIT"]
+
+
+
+# 截取前 7 位 commit hash,如果长度不足则不截取
+if "commit" in html_context:
+    html_context["commit"] = html_context["commit"][:7]

+ 1 - 1
docs/requirements.txt

@@ -1,4 +1,4 @@
 sphinx==5.0.2
 myst-parser==0.18.0
 sphinx-rtd-theme
-sphinx-multiversion==0.2.4
+git+https://git.mirrors.dragonos.org.cn/DragonOS-Community/sphinx-multiversion.git@5858b75#egg=sphinx-multiversion