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..360c427 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" -D 'version_sourcedir=$${sourcedir}' $(SPHINXOPTS) $(O) + pdf: weasyprint python3 sphinx-tools/make_pdf.py "$(SOURCEDIR)" "$(BUILDDIR)" diff --git a/source/_static/custom.css b/source/_static/custom.css index dadf769..31c03e9 100644 --- a/source/_static/custom.css +++ b/source/_static/custom.css @@ -39,3 +39,12 @@ section#guide-de-montage h1 { h3 span.section-number, h4 span.section-number, h5 span.section-number, h6 span.section-number { display: none; } + +.rst-downloads { + padding: 12px; + padding-top: 0; +} + +.rst-downloads a { + color: #fcfcfc; +} \ No newline at end of file diff --git a/source/_templates/page.html b/source/_templates/page.html new file mode 100644 index 0000000..5ab4d45 --- /dev/null +++ b/source/_templates/page.html @@ -0,0 +1,18 @@ +{% extends "!page.html" %} +{% block body %} +{% if current_version and latest_version and current_version != latest_version %} +
+

Attention

+

+ {% if current_version.is_released %} + Ceci est une ancienne version de la documentation. + La dernière version est la {{latest_version.name}}. + {% else %} + Ceci est une version en cours de développement. + La dernière version stable est la {{latest_version.name}}. + {% endif %} +

+
+{% endif %} +{{ super() }} +{% endblock %} diff --git a/source/_templates/versions.html b/source/_templates/versions.html new file mode 100644 index 0000000..d6a963f --- /dev/null +++ b/source/_templates/versions.html @@ -0,0 +1,33 @@ +{%- if current_version %} +
+ + Autres versions + {{ 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 %} +
+ + {%- if current_version_data.pdf_url %} +
+ Télécharger au format PDF +
+ {% endif %} +
+{%- endif %} \ No newline at end of file diff --git a/source/conf.py b/source/conf.py index c2cc528..4ff7bf0 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,9 @@ extensions = [ 'sphinx.ext.intersphinx', 'myst_parser', 'sphinxcontrib.inkscapeconverter', + 'sphinx_multiversion', + 'rtd_current_version', + 'version_data' ] myst_enable_extensions = [ @@ -55,5 +62,12 @@ 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[\d\.]+$' +smv_released_pattern = r'.*tags/v[\d\.]+' +smv_latest_version = 'v0.01' 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' diff --git a/source/exts/version_data.py b/source/exts/version_data.py new file mode 100644 index 0000000..483b434 --- /dev/null +++ b/source/exts/version_data.py @@ -0,0 +1,21 @@ +# This module can read data from a python file in the source folder. This will read data from the version being built (as opposed to standard sphinx-multiversion behavior that executes python from the working copy) +# All global variables defined in file current_version_data.py will be put in html_context['current_version_data'] which allows to use them in HTML templates. + +import sys + +current_version_data = {} + +def setup(app): + app.add_config_value("version_sourcedir", '', "html") + app.connect('config-inited', config_inited) + +def config_inited(app, config): + app.connect('html-page-context', html_page_context) + try: + exec(open(app.config.version_sourcedir + '/current_version_data.py').read(), globals(), current_version_data) + except: + print('No file current_version_data.py found') + pass + +def html_page_context(app, pagename, templatename, context, doctree): + context['current_version_data'] = current_version_data