Browse Source

Configuration de sphinx-multiversion

Installation : pip install sphinx-multiversion
Utilisation : make html_versions
prod
Youen 1 year ago
parent
commit
c5a2a6e495
  1. 1
      .gitignore
  2. 6
      Makefile
  3. 27
      source/_templates/versions.html
  4. 28
      source/conf.py
  5. 14
      source/exts/rtd_current_version.py

1
.gitignore vendored

@ -3,3 +3,4 @@
/.metadata/
/_local/
*.pyc

6
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)"

27
source/_templates/versions.html

@ -0,0 +1,27 @@
{%- if current_version %}
<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="versions">
<span class="rst-current-version" data-toggle="rst-current-version">
<span class="fa fa-book">Autres versions</span>
v: {{ current_version.name }}
<span class="fa fa-caret-down"></span>
</span>
<div class="rst-other-versions">
{%- if versions.tags %}
<dl>
<dt>Versions</dt>
{%- for item in versions.tags %}
<dd><a href="{{ item.url }}">{{ item.name }}</a></dd>
{%- endfor %}
</dl>
{%- endif %}
{%- if versions.branches %}
<dl>
<dt>Branches</dt>
{%- for item in versions.branches %}
<dd><a href="{{ item.url }}">{{ item.name }}</a></dd>
{%- endfor %}
</dl>
{%- endif %}
</div>
</div>
{%- endif %}

28
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/.*$'

14
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'
Loading…
Cancel
Save