Skip to content

Commit c2903a9

Browse files
committed
Add documentation for build target configuration
Add documentation detailing appropriate configuration of the smv_build_targets configuration setting including exemplars to illustrate the features and also limitations of this feature. Add documentation detailing appropriate configuration of the smv_clean_intermediate_files configuration setting. Add exemplar usage of the new artefacts object in the html context within template files. Closes sphinx-contrib#70.
1 parent 53c48a5 commit c2903a9

File tree

2 files changed

+185
-0
lines changed

2 files changed

+185
-0
lines changed

docs/configuration.rst

+164
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ This is what the default configuration looks like:
2929
# Determines whether remote or local git branches/tags are preferred if their output dirs conflict
3030
smv_prefer_remote_refs = False
3131
32+
# Specify build targets and whether the resulting artefacts should be downloadable
33+
smv_build_targets = {
34+
"HTML" : {
35+
"builder": "html",
36+
"downloadable": False,
37+
"download_format": "",
38+
},
39+
}
40+
41+
# Flag indicating whether the intermediate build directories should be removed after artefacts are produced
42+
smv_clean_intermediate_files = True
43+
44+
3245
You can override all of these values inside your :file:`conf.py`.
3346

3447
.. note::
@@ -105,6 +118,157 @@ Here are some examples:
105118

106119
Have a look at `PyFormat <python_format_>`_ for information how to use new-stye Python formatting.
107120

121+
Specify Additional Build Targets
122+
================================
123+
124+
In addition to generating static HTML documentation, it is also possible to specify additional build targets for each version of your documentation by providing a value for the ``smv_build_targets`` setting. This can be used to generate and package the documentation for download, or for post processing by an external program. The ``smv_build_targets`` setting has the following format:
125+
126+
.. code-block:: python
127+
128+
smv_build_targets = {
129+
"build_target_name" : {
130+
"builder": `<class sphinx.builders>`,
131+
"downloadable": bool,
132+
"download_format": str
133+
},
134+
}
135+
136+
These fields can be populated as follows:
137+
138+
* ``build_target_name``: This is the name of the build target. It must be unique within the ``smv_build_targets`` dictionary, and is used as the display name of the download artefacts if ``downloadable == True``.
139+
* ``builder``: This is the string identifying any valid `sphinx builder <https://www.sphinx-doc.org/en/master/usage/builders/index.html>`_.
140+
* ``downloadable``: Indicate whether an artefact for this build should be generated. All artefacts are placed within the ``build/version/artefacts`` directory and made available in the html context.
141+
* ``download_format``: A string indicating the format of the final downloadable artefact. Only valid if ``downloadable == True``. Valid values for this include ``tar``, ``zip``, ``pdf``, ``epub``, or any other extension for build artefacts produced by the sphinx builder specified in ``builder``.
142+
143+
.. note::
144+
145+
If ``tar`` or ``zip`` are specified, the entire build directory is archived. An example of this would be the ``html`` directory for a ``html`` sphinx builder, or the ``latex`` directory for a ``latex`` sphinx builder.
146+
147+
.. note::
148+
149+
When the build artefact is an individual file, it is only matched according to the pattern <project>.<download_format> to avoid the ambiguity associated with multiple matches to a file extension. To illustrate this limitation, html files are always indexed with ``index.html``, which would not be identified as an individual build artefact. Thus, in order to make HTML available as a build artefact it must be archived using ``zip``, ``tar``, ``gztar``, ``bztar`` or ``xztar``.
150+
151+
Some common examples may be as follows:
152+
153+
.. code-block:: python
154+
155+
smv_build_targets = {
156+
"HTML" : {
157+
"builder": "html",
158+
"downloadable": True,
159+
"download_format": "zip",
160+
},
161+
"SingleHTML" : {
162+
"builder": "singlehtml",
163+
"downloadable": True,
164+
"download_format": "tar",
165+
},
166+
"PDF" : {
167+
"builder": "latexpdf", # This will build a .pdf file after generating latex documents
168+
"downloadable": True,
169+
"download_format": "pdf",
170+
},
171+
"LaTeX" : {
172+
"builder": "latex", # This will only generate latex documents.
173+
"downloadable": True,
174+
"download_format": "gztar",
175+
},
176+
"ePub" : {
177+
"builder": "epub",
178+
"downloadable": True,
179+
"download_format": "epub",
180+
},
181+
}
182+
183+
Additionally, the user is able to configure whether intermediate build files are cleaned from the output directory using the ``smv_clean_intermediate_files`` setting:
184+
185+
.. code-block:: python
186+
187+
smv_clean_intermediate_files = True
188+
189+
If this flag is ``True``, the resulting directory structure will resemble the following:
190+
191+
.. code-block:: bash
192+
193+
build
194+
├── develop
195+
│   ├── artefacts
196+
│   │   ├── example_docs-develop.epub
197+
│   │   ├── example_docs-develop-HTML.zip
198+
│   │   └── example_docs-develop.pdf
199+
│   ├── index.html
200+
│   └── ...
201+
├── master
202+
│   ├── artefacts
203+
│   │   ├── example_docs-master.epub
204+
│   │   ├── example_docs-master-HTML.zip
205+
│   │   └── example_docs-master.pdf
206+
│   ├── index.html
207+
│   └── ...
208+
└── v0.1.0
209+
├── artefacts
210+
│   ├── example_docs-v0.1.0.epub
211+
│   ├── example_docs-v0.1.0-HTML.zip
212+
│   └── example_docs-v0.1.0.pdf
213+
├── index.html
214+
└── ...
215+
216+
However, if this flag is set to ``False``, the resulting directory will also include intermediate build directories:
217+
218+
.. code-block:: bash
219+
220+
build
221+
├── develop
222+
│   ├── artefacts
223+
│   │   ├── example_docs-develop.epub
224+
│   │   ├── example_docs-develop-HTML.zip
225+
│   │   └── example_docs-develop.pdf
226+
│   ├── epub
227+
│   │   ├── example.epub
228+
│   │   ├── index.xhtml
229+
│   │   └── ...
230+
│   ├── html
231+
│   │   ├── index.html
232+
│   │   └── ...
233+
│   ├── index.html
234+
│   ├── latexpdf
235+
│   │   └── latex
236+
│   └── ...
237+
├── master
238+
│   ├── artefacts
239+
│   │   ├── example_docs-master.epub
240+
│   │   ├── example_docs-master-HTML.zip
241+
│   │   └── example_docs-master.pdf
242+
│   ├── epub
243+
│   │   ├── example.epub
244+
│   │   ├── index.xhtml
245+
│   │   └── ...
246+
│   ├── html
247+
│   │   ├── index.html
248+
│   │   └── ...
249+
│   ├── index.html
250+
│   ├── latexpdf
251+
│   │   └── latex
252+
│   └── ...
253+
└── v0.1.0
254+
├── artefacts
255+
│   ├── example_docs-v0.1.0.epub
256+
│   ├── example_docs-v0.1.0-HTML.zip
257+
│   └── example_docs-v0.1.0.pdf
258+
├── epub
259+
│   ├── example.epub
260+
│   ├── index.xhtml
261+
│   └── ...
262+
├── html
263+
│   ├── index.html
264+
│   └── ...
265+
├── index.html
266+
├── latexpdf
267+
│   └── latex
268+
└── ...
269+
270+
This will be useful if you want to use an external program to interact with the build output.
271+
108272

109273
Overriding Configuration Variables
110274
==================================

docs/templates.rst

+21
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ List releases and development versions separately
8080
</ul>
8181
{% endif %}
8282

83+
List available downloads
84+
------------------------
85+
86+
.. code-block:: html
87+
88+
{% if current_version.artefacts %}
89+
<h3>{{ _('Downloads') }}</h3>
90+
<ul>
91+
{%- for artefact in current_version.artefacts %}
92+
<li><a href="{{ artefact.url }}">{{ artefact.name }}</a></li>
93+
{%- endfor %}
94+
</ul>
95+
{% endif %}
8396

8497
Version Banners
8598
===============
@@ -139,6 +152,14 @@ So instead of adding a custom template to ``html_sidebars``, you need to create
139152
{%- endfor %}
140153
</dl>
141154
{%- endif %}
155+
{%- if current_version.artefacts %}
156+
<dl>
157+
<dt>Downloads</dt>
158+
{%- for artefact in current_version.artefacts %}
159+
<dd><a href="{{ artefact.url }}">{{ artefact.name }}</a></dd>
160+
{%- endfor %}
161+
</dl>
162+
{%- endif %}
142163
</div>
143164
</div>
144165
{%- endif %}

0 commit comments

Comments
 (0)