You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+91-29
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,10 @@ In normal Sphinx documentation, the documentation site-map is defined *via* a bo
11
11
12
12
This extension facilitates a **top-down** approach to defining the site-map structure, within a single YAML file.
13
13
14
+

15
+
16
+
It also allows for documents not specified in the ToC to be auto-excluded.
17
+
14
18
## User Guide
15
19
16
20
### Sphinx Configuration
@@ -39,7 +43,7 @@ The value of the `root` key will be a path to a file, in Unix format (folders sp
39
43
This root file will be set as the [`master_doc`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-master_doc).
40
44
:::
41
45
42
-
Document files can then have a `subtrees` key - denoting a list of individual toctrees for that document - and in-turn each subtree should have a `sections` key - denoting a list of children links, that are one of: `file`, `url` or `glob`:
46
+
Document files can then have a `subtrees` key - denoting a list of individual toctrees for that document - and in-turn each subtree should have a `items` key - denoting a list of children links, that are one of:
43
47
44
48
- `file`: path to a single document file in Unix format, with or without the file extension (as for `root`)
45
49
- `glob`: path to one or more document files *via* Unix shell-style wildcards (similar to [`fnmatch`](https://docs.python.org/3/library/fnmatch.html), but single stars don't match slashes.)
@@ -54,13 +58,13 @@ This can proceed recursively to any depth.
54
58
```yaml
55
59
root: intro
56
60
subtrees:
57
-
- sections:
61
+
- items:
58
62
- file: doc1
59
63
subtrees:
60
-
- sections:
64
+
- items:
61
65
- file: doc2
62
66
subtrees:
63
-
- sections:
67
+
- items:
64
68
- file: doc3
65
69
- url: https://example.com
66
70
- glob: subfolder/other*
@@ -69,16 +73,16 @@ subtrees:
69
73
This is equivalent to having a single `toctree` directive in `intro`, containing `doc1`,
70
74
and a single `toctree` directive in `doc1`, with the `:glob:` flag and containing `doc2`, `https://example.com` and `subfolder/other*`.
71
75
72
-
As a shorthand, the `sections` key can be at the same level as the `file`, which denotes a document with a single subtree.
76
+
As a shorthand, the `items` key can be at the same level as the `file`, which denotes a document with a single subtree.
73
77
For example, this file is exactly equivalent to the one above:
74
78
75
79
```yaml
76
80
root: intro
77
-
sections:
81
+
items:
78
82
- file: doc1
79
-
sections:
83
+
items:
80
84
- file: doc2
81
-
sections:
85
+
items:
82
86
- file: doc3
83
87
- url: https://example.com
84
88
- glob: subfolder/other*
@@ -92,7 +96,7 @@ With the `title` key you can set an alternative title for a document. and also f
92
96
```yaml
93
97
root: intro
94
98
subtrees:
95
-
- sections:
99
+
- items:
96
100
- file: doc1
97
101
title: Document 1 Title
98
102
- url: https://example.com
@@ -106,13 +110,13 @@ Each subtree can be configured with a number of options (see also [sphinx `toctr
106
110
- `caption` (string): A title for the whole the subtree, e.g. shown above the subtree in ToCs
107
111
- `hidden` (boolean): Whether to show the ToC within (inline of) the document (default `False`).
108
112
By default it is appended to the end of the document, but see also the `tableofcontents` directive for positioning of the ToC.
109
-
- `maxdepth` (integer): A maximum nesting depth to use when showing the ToC within the document.
113
+
- `maxdepth` (integer): A maximum nesting depth to use when showing the ToC within the document (default -1, meaning infinite).
110
114
- `numbered` (boolean or integer): Automatically add numbers to all documents within a subtree (default `False`).
111
115
If set to `True`, all sub-trees will also be numbered based on nesting (e.g. with `1.1` or `1.1.1`),
112
116
or if set to an integer then the numbering will only be applied to that depth.
113
-
- `reversed` (boolean): If `True` then the entries in the subtree will be listed in reverse order.
114
-
This can be useful when using `glob` sections.
115
-
- `titlesonly` (boolean): If `True` then only the first heading in the document will be shown in the ToC, not other headings of the same level.
117
+
- `reversed` (boolean): If `True` then the entries in the subtree will be listed in reverse order (default `False`).
118
+
This can be useful when using `glob` items.
119
+
- `titlesonly` (boolean): If `True` then only the first heading in the document will be shown in the ToC, not other headings of the same level (default `False`).
116
120
117
121
These options can be set at the level of the subtree:
118
122
@@ -125,11 +129,11 @@ subtrees:
125
129
numbered: True
126
130
reversed: False
127
131
titlesonly: True
128
-
sections:
132
+
items:
129
133
- file: doc1
130
134
subtrees:
131
135
- titlesonly: True
132
-
sections:
136
+
items:
133
137
- file: doc2
134
138
```
135
139
@@ -144,11 +148,11 @@ options:
144
148
numbered: True
145
149
reversed: False
146
150
titlesonly: True
147
-
sections:
151
+
items:
148
152
- file: doc1
149
153
options:
150
154
titlesonly: True
151
-
sections:
155
+
items:
152
156
- file: doc2
153
157
```
154
158
@@ -164,9 +168,9 @@ options:
164
168
maxdepth: 1
165
169
numbered: True
166
170
reversed: False
167
-
sections:
171
+
items:
168
172
- file: doc1
169
-
sections:
173
+
items:
170
174
- file: doc2
171
175
```
172
176
@@ -175,10 +179,55 @@ sections:
175
179
:::
176
180
177
181
:::{note}
178
-
By default, section numbering restarts for each subtree.
182
+
By default, title numbering restarts for each subtree.
179
183
If you want want this numbering to be continuous, check-out the [sphinx-multitoc-numbering extension](https://github.com/executablebooks/sphinx-multitoc-numbering).
180
184
:::
181
185
186
+
### Using different key-mappings
187
+
188
+
For certain use-cases, it is helpful to map the `subtrees`/`items` keys to mirror e.g. an output [LaTeX structure](https://www.overleaf.com/learn/latex/sections_and_chapters).
189
+
190
+
The `format` key can be used to provide such mappings (and also initial defaults).
191
+
Currently available:
192
+
193
+
- `jb-article`:
194
+
- Maps `items` -> `sections`
195
+
- Sets the default of `titlesonly` to `true`
196
+
- `jb-book`:
197
+
- Maps the top-level `subtrees` to `parts`
198
+
- Maps the top-level `items` to `chapters`
199
+
- Maps other levels of `items` to `sections`
200
+
- Sets the default of `titlesonly` to `true`
201
+
202
+
For example:
203
+
204
+
```yaml
205
+
defaults:
206
+
titlesonly: true
207
+
root: index
208
+
subtrees:
209
+
- items:
210
+
- file: doc1
211
+
items:
212
+
- file: doc2
213
+
```
214
+
215
+
is equivalent to:
216
+
217
+
```yaml
218
+
format: jb-book
219
+
root: index
220
+
parts:
221
+
- chapters:
222
+
- file: doc1
223
+
sections:
224
+
- file: doc2
225
+
```
226
+
227
+
:::{important}
228
+
These change in key names do not change the output site-map structure.
229
+
:::
230
+
182
231
## Add a ToC to a page's content
183
232
184
233
By default, the `toctree` generated per document (one per subtree) are appended to the end of the document and hidden (then, for example, most HTML themes show them in a side-bar).
@@ -225,19 +274,32 @@ To see all options:
225
274
226
275
```console
227
276
$ sphinx-etoc --help
277
+
Usage: sphinx-etoc [OPTIONS] COMMAND [ARGS]...
278
+
279
+
Command-line for ``sphinx-external-toc``.
280
+
281
+
Options:
282
+
--version Show the version and exit.
283
+
-h, --help Show this message and exit.
284
+
285
+
Commands:
286
+
from-site Create a ToC file from a site directory.
0 commit comments