From 5f48f8f2d3c18b4db9628d7ec2a835d6b56089ab Mon Sep 17 00:00:00 2001 From: Youen Date: Thu, 18 May 2023 00:08:39 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20d'un=20m=C3=A9canisme=20pour=20d=C3=A9f?= =?UTF-8?q?inir=20des=20donn=C3=A9es=20diff=C3=A9rentes=20dans=20chaque=20?= =?UTF-8?q?version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Possibilité de définir un lien vers le PDF différent dans chaque version --- Makefile | 2 +- source/_static/custom.css | 10 ++++++++++ source/_templates/versions.html | 10 ++++++++-- source/conf.py | 1 + source/exts/version_data.py | 21 +++++++++++++++++++++ 5 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 source/exts/version_data.py diff --git a/Makefile b/Makefile index 88a6fd1..360c427 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ html: html_versions: rm -rf $(BUILDDIR)/html_versions/* - sphinx-multiversion "$(SOURCEDIR)" "$(BUILDDIR)/html_versions" $(SPHINXOPTS) $(O) + 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..602ca87 100644 --- a/source/_static/custom.css +++ b/source/_static/custom.css @@ -39,3 +39,13 @@ 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; + border: 1px solid grey; +} \ No newline at end of file diff --git a/source/_templates/versions.html b/source/_templates/versions.html index fb3355f..d6a963f 100644 --- a/source/_templates/versions.html +++ b/source/_templates/versions.html @@ -1,8 +1,8 @@ {%- if current_version %}
- Autres versions - v: {{ current_version.name }} + Autres versions + {{ current_version.name }}
@@ -23,5 +23,11 @@ {%- endif %}
+ + {%- if current_version_data.pdf_url %} + + {% endif %}
{%- endif %} \ No newline at end of file diff --git a/source/conf.py b/source/conf.py index b33db6e..1f9862d 100644 --- a/source/conf.py +++ b/source/conf.py @@ -25,6 +25,7 @@ extensions = [ 'sphinxcontrib.inkscapeconverter', 'sphinx_multiversion', 'rtd_current_version', + 'version_data' ] myst_enable_extensions = [ 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