Skip to content

Commit fad761b

Browse files
fslongjinBrahmaMantra
authored andcommitted
doc: 添加在github上编辑的按钮,以及扩展footer (DragonOS-Community#940)
Signed-off-by: longjin <[email protected]>
1 parent a1fb4ea commit fad761b

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

docs/Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ SPHINXBUILD ?= sphinx-build
88
SOURCEDIR = .
99
BUILDDIR = _build
1010

11+
LANGUAGE = zh_CN
12+
13+
SPHINXOPTS += -D language=$(LANGUAGE)
14+
15+
export CURRENT_GIT_COMMIT_HASH := $(shell git rev-parse --short HEAD)
16+
17+
GIT_STATUS := $(shell git status --porcelain --untracked-files=no)
18+
19+
ifeq ($(strip $(GIT_STATUS)),)
20+
export CURRENT_GIT_COMMIT_DIRTY = 0
21+
else
22+
export CURRENT_GIT_COMMIT_DIRTY = 1
23+
endif
24+
1125
# Put it first so that "make" without argument is like "make help".
1226
help:
1327
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@@ -21,4 +35,4 @@ help:
2135

2236
.PHONY:
2337
html-multiversion:
24-
rm -rf ./$(BUILDDIR) && sphinx-multiversion "$(SOURCEDIR)" ./$(BUILDDIR)/html && cp -rf ./$(BUILDDIR)/html/master/* ./$(BUILDDIR)/html/
38+
rm -rf ./$(BUILDDIR) && CURRENT_GIT_COMMIT_DIRTY=0 sphinx-multiversion $(SPHINXOPTS) "$(SOURCEDIR)" ./$(BUILDDIR)/html && cp -rf ./$(BUILDDIR)/html/master/* ./$(BUILDDIR)/html/

docs/_templates/footer.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{% extends "!footer.html" %}
2+
3+
{% block extrafooter %}
4+
<div>
5+
<br>
6+
官网 <a href="https://dragonos.org">https://dragonos.org</a> | 论坛 <a href="https://bbs.dragonos.org.cn">https://bbs.dragonos.org.cn</a> | <a href="https://dragonos.org">赞助DragonOS,成就未来!</a>
7+
</div>
8+
{% endblock %}

docs/conf.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
project = 'DragonOS'
2020
copyright = '2022-2024, DragonOS Community'
2121
author = 'longjin'
22+
github_org = 'DragonOS-Community'
23+
github_repo = 'DragonOS'
2224

2325
# The full version, including alpha/beta/rc tags
2426
release = 'dev'
@@ -97,9 +99,20 @@
9799

98100
if os.environ.get("SPHINX_MULTIVERSION_GIT_COMMIT", "") != "":
99101
html_context["commit"] = os.environ["SPHINX_MULTIVERSION_GIT_COMMIT"]
100-
102+
elif os.environ.get("CURRENT_GIT_COMMIT_HASH", "") != "":
103+
html_context["commit"] = os.environ["CURRENT_GIT_COMMIT_HASH"]
101104

102105

103106
# 截取前 7 位 commit hash,如果长度不足则不截取
104107
if "commit" in html_context:
105108
html_context["commit"] = html_context["commit"][:7]
109+
if os.environ.get("CURRENT_GIT_COMMIT_DIRTY", "") == "1":
110+
html_context["commit"] += "-dirty"
111+
112+
113+
# -- Set GitHub URL for Edit on GitHub links ---
114+
html_context['display_github'] = True
115+
html_context['github_user'] = github_org
116+
html_context['github_repo'] = github_repo
117+
html_context['github_version'] = html_context['commit'] if 'commit' in html_context else 'master'
118+
html_context['conf_py_path'] = '/docs/'

0 commit comments

Comments
 (0)