Youen 2 years ago
parent
commit
fbaae25899
  1. 1
      .gitignore
  2. 6
      Makefile
  3. 9
      source/_static/custom.css
  4. 18
      source/_templates/page.html
  5. 33
      source/_templates/versions.html
  6. 30
      source/conf.py
  7. 14
      source/exts/rtd_current_version.py
  8. 21
      source/exts/version_data.py

1
.gitignore vendored

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

6
Makefile

@ -22,8 +22,12 @@ help:
# We clear the html folder before rebuilding, otherwise some things are # We clear the html folder before rebuilding, otherwise some things are
# not updated (like static files) # not updated (like static files)
html: html:
rm -rf "$(BUILDDIR)/html/*" rm -rf $(BUILDDIR)/html/*
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) @$(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 pdf: weasyprint
python3 sphinx-tools/make_pdf.py "$(SOURCEDIR)" "$(BUILDDIR)" python3 sphinx-tools/make_pdf.py "$(SOURCEDIR)" "$(BUILDDIR)"

9
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 { h3 span.section-number, h4 span.section-number, h5 span.section-number, h6 span.section-number {
display: none; display: none;
} }
.rst-downloads {
padding: 12px;
padding-top: 0;
}
.rst-downloads a {
color: #fcfcfc;
}

18
source/_templates/page.html

@ -0,0 +1,18 @@
{% extends "!page.html" %}
{% block body %}
{% if current_version and latest_version and current_version != latest_version %}
<div class="warning admonition">
<p class="admonition-title">Attention</p>
<p>
{% if current_version.is_released %}
Ceci est une ancienne version de la documentation.
La dernière version est la <a href="{{ vpathto(latest_version.name) }}">{{latest_version.name}}</a>.
{% else %}
Ceci est une version en cours de développement.
La dernière version stable est la <a href="{{ vpathto(latest_version.name) }}">{{latest_version.name}}</a>.
{% endif %}
</p>
</div>
{% endif %}
{{ super() }}
{% endblock %}

33
source/_templates/versions.html

@ -0,0 +1,33 @@
{%- 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>
{{ 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>
{%- 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 %}

30
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 information
project = 'Guide de montage Vheliotech' project = 'Guide de montage Vhéliotech'
copyright = '2023, Velo solaire pour tous' copyright = '2023, Vélo solaire pour tous'
author = 'Association Velo Solaire Pour Tous' author = 'Association Vélo Solaire Pour Tous'
release = '1.0.0' html_context = dict()
version = '1.0.0' html_context['version'] = 'test'
# -- General configuration # -- General configuration
@ -19,6 +23,9 @@ extensions = [
'sphinx.ext.intersphinx', 'sphinx.ext.intersphinx',
'myst_parser', 'myst_parser',
'sphinxcontrib.inkscapeconverter', 'sphinxcontrib.inkscapeconverter',
'sphinx_multiversion',
'rtd_current_version',
'version_data'
] ]
myst_enable_extensions = [ myst_enable_extensions = [
@ -55,5 +62,12 @@ html_css_files = [
'html-version.css' 'html-version.css'
] ]
# -- Options for EPUB output html_theme_options = {
epub_show_urls = 'footnote' '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'

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'

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