From c5a2a6e4959b9a459fcb7c1928618c256cf3f532 Mon Sep 17 00:00:00 2001 From: Youen Date: Wed, 17 May 2023 20:25:31 +0200 Subject: [PATCH] Configuration de sphinx-multiversion Installation : pip install sphinx-multiversion Utilisation : make html_versions --- .gitignore | 1 + Makefile | 6 +++++- source/_templates/versions.html | 27 +++++++++++++++++++++++++++ source/conf.py | 28 ++++++++++++++++++++-------- source/exts/rtd_current_version.py | 14 ++++++++++++++ 5 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 source/_templates/versions.html create mode 100644 source/exts/rtd_current_version.py diff --git a/.gitignore b/.gitignore index 9553705..02432eb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /.metadata/ /_local/ +*.pyc diff --git a/Makefile b/Makefile index a17aca5..88a6fd1 100644 --- a/Makefile +++ b/Makefile @@ -22,8 +22,12 @@ help: # We clear the html folder before rebuilding, otherwise some things are # not updated (like static files) html: - rm -rf "$(BUILDDIR)/html/*" + rm -rf $(BUILDDIR)/html/* @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) +html_versions: + rm -rf $(BUILDDIR)/html_versions/* + sphinx-multiversion "$(SOURCEDIR)" "$(BUILDDIR)/html_versions" $(SPHINXOPTS) $(O) + pdf: weasyprint python3 sphinx-tools/make_pdf.py "$(SOURCEDIR)" "$(BUILDDIR)" diff --git a/source/_templates/versions.html b/source/_templates/versions.html new file mode 100644 index 0000000..fb3355f --- /dev/null +++ b/source/_templates/versions.html @@ -0,0 +1,27 @@ +{%- if current_version %} +
+ + Autres versions + v: {{ current_version.name }} + + +
+ {%- if versions.tags %} +
+
Versions
+ {%- for item in versions.tags %} +
{{ item.name }}
+ {%- endfor %} +
+ {%- endif %} + {%- if versions.branches %} +
+
Branches
+ {%- for item in versions.branches %} +
{{ item.name }}
+ {%- endfor %} +
+ {%- endif %} +
+
+{%- endif %} \ No newline at end of file diff --git a/source/conf.py b/source/conf.py index c2cc528..82f72ec 100644 --- a/source/conf.py +++ b/source/conf.py @@ -1,13 +1,17 @@ -# Configuration file for the Sphinx documentation builder. +# Configuration file for the Sphinx documentation builder. + +import sys, os + +sys.path.append(os.path.abspath('exts')) # -- Project information -project = 'Guide de montage Vheliotech' -copyright = '2023, Velo solaire pour tous' -author = 'Association Velo Solaire Pour Tous' +project = 'Guide de montage Vhéliotech' +copyright = '2023, Vélo solaire pour tous' +author = 'Association Vélo Solaire Pour Tous' -release = '1.0.0' -version = '1.0.0' +html_context = dict() +html_context['version'] = 'test' # -- General configuration @@ -19,6 +23,8 @@ extensions = [ 'sphinx.ext.intersphinx', 'myst_parser', 'sphinxcontrib.inkscapeconverter', + 'sphinx_multiversion', + 'rtd_current_version', ] myst_enable_extensions = [ @@ -55,5 +61,11 @@ html_css_files = [ 'html-version.css' ] -# -- Options for EPUB output -epub_show_urls = 'footnote' +html_theme_options = { + 'display_version': True +} + +# sphinx-multiversion settings +smv_branch_whitelist = r'^main$' +smv_tag_whitelist = r'^v[0-9\.]+$' +smv_released_pattern = r'^tags/.*$' diff --git a/source/exts/rtd_current_version.py b/source/exts/rtd_current_version.py new file mode 100644 index 0000000..5208d51 --- /dev/null +++ b/source/exts/rtd_current_version.py @@ -0,0 +1,14 @@ +# This tiny sphinx extension will simply copy the current_version (generated by sphinx_multiversion) to the 'version' entry in html_context, so that it is correctly displayed by the ReadTheDocs template +# You need to have the sphinx_multiversion extension as well + +def setup(app): + app.connect('config-inited', config_inited) + +def config_inited(app, config): + app.connect('html-page-context', html_page_context) + +def html_page_context(app, pagename, templatename, context, doctree): + try: + context['version'] = context['current_version'].name + except: + context['version'] = 'no_version_found'