From 09dacded09985677779c835de554356c0df5176b Mon Sep 17 00:00:00 2001 From: LoGin Date: Wed, 25 Sep 2024 22:53:31 +0800 Subject: [PATCH] doc: add commit revision to footer while build with sphinx-multiversion (#939) Signed-off-by: longjin --- docs/conf.py | 13 ++++++++++++- docs/requirements.txt | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 6a28618a..29887615 100644 --- a/docs/conf.py +++ b/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 \ No newline at end of file + 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] diff --git a/docs/requirements.txt b/docs/requirements.txt index ecbd3ac6..ce664001 100644 --- a/docs/requirements.txt +++ b/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