Browse Source

Ajout d'un mécanisme pour définir des données différentes dans chaque version

Possibilité de définir un lien vers le PDF différent dans chaque version
main
Youen 2 years ago
parent
commit
5f48f8f2d3
  1. 2
      Makefile
  2. 10
      source/_static/custom.css
  3. 10
      source/_templates/versions.html
  4. 1
      source/conf.py
  5. 21
      source/exts/version_data.py

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

10
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;
}

10
source/_templates/versions.html

@ -1,8 +1,8 @@
{%- 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-book"> Autres versions</span>
{{ current_version.name }}
<span class="fa fa-caret-down"></span>
</span>
<div class="rst-other-versions">
@ -23,5 +23,11 @@
</dl>
{%- endif %}
</div>
{%- if current_version_data.pdf_url %}
<div class="rst-downloads">
<a href="{{current_version_data.pdf_url}}"><span class="fa fa-download"> Télécharger au format PDF</a></span>
</div>
{% endif %}
</div>
{%- endif %}

1
source/conf.py

@ -25,6 +25,7 @@ extensions = [
'sphinxcontrib.inkscapeconverter',
'sphinx_multiversion',
'rtd_current_version',
'version_data'
]
myst_enable_extensions = [

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