Browse Source

Correction de la version HTML

Ajout d'un titre sur la première page, mais qui n'est pas pris en compte dans la hiérarchie globale
Ajout d'un fichier custom.css pour les règles communes à la version PDF et HTML
Limitation de la profondeur de titres affichés dans la table des matières sur la première page de la version HTML
pull/29/head
Youen 1 year ago
parent
commit
2d601e71b7
  1. 6
      Makefile
  2. 31
      source/_static/custom.css
  3. 5
      source/conf.py
  4. 32
      source/css/print-theme.css
  5. 8
      source/index.md
  6. 5
      sphinx-tools/make_pdf.py

6
Makefile

@ -19,5 +19,11 @@ help:
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
# We clear the html folder before rebuilding, otherwise some things are
# not updated (like static files)
html:
rm -rf "$(BUILDDIR)/html"
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
pdf: weasyprint
python3 sphinx-tools/make_pdf.py "$(SOURCEDIR)" "$(BUILDDIR)"

31
source/_static/custom.css

@ -0,0 +1,31 @@
.document-title {
width: 100%;
color: #fbbb15;
text-align: center;
font-size: 5em !important;
border-top: 2px solid black;
border-bottom: 2px solid black;
line-height: 1.2;
font-weight: bold;
}
.document-subtitle {
text-align: center;
font-size: 1.5em;
margin-top: 30px;
margin-bottom: 30px;
}
.title-page-footer {
text-align: center;
font-size: 1.2em !important;
margin-top: 30px;
}
/* displayed as a title, but doesn't count in numbering and doesn't appear in TOC */
.fake-title {
font-weight: 700;
font-size: 175% !important;
font-family: Roboto Slab,ff-tisa-web-pro,Georgia,Arial,sans-serif;
break-before: always;
}

5
source/conf.py

@ -48,6 +48,11 @@ templates_path = ['_templates']
# -- Options for HTML output
html_theme = 'sphinx_rtd_theme'
html_title = 'Vhéliotech'
html_static_path = ['_static']
html_css_files = [
'custom.css',
]
# -- Options for EPUB output
epub_show_urls = 'footnote'

32
source/css/print-theme.css

@ -39,38 +39,6 @@ div[role=navigation], .headerlink {
display: none;
}
.document-title {
width: 100%;
color: #fbbb15;
text-align: center;
font-size: 5em !important;
border-top: 2px solid black;
border-bottom: 2px solid black;
line-height: 1.2;
font-weight: bold;
}
.document-subtitle {
text-align: center;
font-size: 1.5em;
margin-top: 30px;
margin-bottom: 30px;
}
.title-page-footer {
text-align: center;
font-size: 1.2em !important;
margin-top: 30px;
}
/* displayed as a title, but doesn't count in numbering and doesn't appear in TOC */
.fake-title {
font-weight: 700;
font-size: 175% !important;
font-family: Roboto Slab,ff-tisa-web-pro,Georgia,Arial,sans-serif;
break-before: always;
}
h1 {
break-before: always;
}

8
source/index.md

@ -43,6 +43,7 @@ Copyright Vélo Solaire Pour Tous, Mai 2023, sous [licence CERN-OHL-S version 2]
</section>
```{toctree}
:maxdepth: 2
010_documentation
020_moyens_necessaires
030_plan_general
@ -57,3 +58,10 @@ Copyright Vélo Solaire Pour Tous, Mai 2023, sous [licence CERN-OHL-S version 2]
110_accessoires
120_tests_verifications
```
<div class="hidden">
<!-- This is only used to declare a title for this page (for the HTML version). It must be after the TOC otherwise the whole hierarchy is nested within this title. -->
# Guide de montage
</div>

5
sphinx-tools/make_pdf.py

@ -15,7 +15,8 @@ css_filename = source_dir + '/css/print-theme.css'
script_dir = os.path.dirname(__file__)
# Compile PDF
assert(subprocess.run(['weasyprint', build_dir + '/weasyprint/index.html', index_pdf_filename, '-s', css_filename]).returncode == 0)
pdf_compile_command = ['weasyprint', build_dir + '/weasyprint/index.html', index_pdf_filename, '-s', source_dir + '/_static/custom.css', '-s', css_filename]
assert(subprocess.run(pdf_compile_command).returncode == 0)
# Generate table of content (TOC)
assert(subprocess.run(['sh', '-c', script_dir + '/../pdftoc-to-latex "' + index_pdf_filename + '" > "' + build_dir + '/weasyprint/toc.tex"']).returncode == 0)
@ -49,7 +50,7 @@ if modified_css != original_css:
# We need to compile again with the modified CSS (this won't impact the TOC)
print('Number of pages has changed, rebuilding PDF...')
assert(subprocess.run(['weasyprint', build_dir + '/weasyprint/index.html', index_pdf_filename, '-s', css_filename]).returncode == 0)
assert(subprocess.run(pdf_compile_command).returncode == 0)
# Insert TOC in the PDF
assert(subprocess.run(['pdftk', 'A='+index_pdf_filename, 'B='+build_dir+'/weasyprint/toc.pdf', 'cat', 'A1-'+str(insert_toc_after_page), 'B', 'A'+str(insert_toc_after_page+1)+'-end', 'output', build_dir + '/weasyprint/vheliotech-without-bookmarks.pdf']).returncode == 0)

Loading…
Cancel
Save