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
+52-54Lines changed: 52 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,11 @@
4
4
[![Coverage Status][codecov-badge]][codecov-link]
5
5
[![Code style: black][black-badge]][black-link]
6
6
7
-
A sphinx extension that allows the documentation toctree to be defined in a single file.
7
+
A sphinx extension that allows the documentation site-map (a.k.a Table of Contents) to be defined external to the documentation files.
8
8
9
-
In normal Sphinx documentation, the documentation structure is defined *via* a bottom-up approach - adding [`toctree` directives](https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#table-of-contents) within pages of the documentation.
9
+
In normal Sphinx documentation, the documentation site-map is defined *via* a bottom-up approach - adding [`toctree` directives](https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#table-of-contents) within pages of the documentation.
10
10
11
-
This extension facilitates a **top-down** approach to defining the Table of Contents (ToC) structure, within a single YAML file that is external to the documentation.
11
+
This extension facilitates a **top-down** approach to defining the site-map structure, within a single YAML file.
A minimal ToC defines the top level `main` key, and a single root document file:
27
+
A minimal ToC defines the top level `root` key, for a single root document file:
28
28
29
29
```yaml
30
-
main:
31
-
file: intro
30
+
root: intro
32
31
```
33
32
34
-
The value of the `file` key will be a path to a file, in Unix format (folders split by `/`), relative to the source directory, and can be with or without the file extension.
33
+
The value of the `root` key will be a path to a file, in Unix format (folders split by `/`), relative to the source directory, and can be with or without the file extension.
35
34
36
35
:::{note}
37
36
This root file will be set as the [`master_doc`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-master_doc).
38
37
:::
39
38
40
39
Document files can then have a `parts` key - denoting a list of individual toctrees for that document - and in-turn each part should have a `sections` key - denoting a list of children links, that are one of: `file`, `url` or `glob`:
41
40
42
-
- `file`: relating to a single document file (see above)
43
-
- `glob`: relating 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.)
44
-
- `url`: relating to an external URL (e.g. `http` or `https`)
41
+
- `file`: path to a single document file in Unix format, with or without the file extension (as for `root`)
42
+
- `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.)
43
+
- `url`: path for an external URL (starting e.g. `http` or `https`)
45
44
46
45
:::{important}
47
46
Each document file can only occur once in the ToC!
@@ -50,16 +49,18 @@ Each document file can only occur once in the ToC!
50
49
This can proceed recursively to any depth.
51
50
52
51
```yaml
53
-
main:
54
-
file: intro
55
-
parts:
56
-
- sections:
57
-
- file: doc1
58
-
parts:
59
-
- sections:
60
-
- file: doc2
61
-
- url: https://example.com
62
-
- glob: subfolder/other*
52
+
root: intro
53
+
parts:
54
+
- sections:
55
+
- file: doc1
56
+
parts:
57
+
- sections:
58
+
- file: doc2
59
+
parts:
60
+
- sections:
61
+
- file: doc3
62
+
- url: https://example.com
63
+
- glob: subfolder/other*
63
64
```
64
65
65
66
This is equivalent to having a single `toctree` directive in `intro`, containing `doc1`,
@@ -69,47 +70,46 @@ As a shorthand, the `sections` key can be at the same level as the `file`, which
69
70
For example, this file is exactly equivalent to the one above:
70
71
71
72
```yaml
72
-
main:
73
-
file: intro
73
+
root: intro
74
+
sections:
75
+
- file: doc1
74
76
sections:
75
-
- file: doc1
77
+
- file: doc2
76
78
sections:
77
-
- file: doc2
78
-
- url: https://example.com
79
-
- glob: subfolder/other*
79
+
- file: doc3
80
+
- url: https://example.com
81
+
- glob: subfolder/other*
80
82
```
81
83
82
84
### Titles and Captions
83
85
84
86
By default, ToCs will use the initial header within a document as its title.
85
87
86
-
With the `title` key you can set an alternative title for a document or URL.
88
+
With the `title` key you can set an alternative title for a document or URL in the ToC.
87
89
Each part can also have a `caption`, e.g. for use in ToC side-bars:
88
90
89
91
```yaml
90
-
main:
91
-
file: intro
92
-
title: Introduction
93
-
parts:
94
-
- caption: Part Caption
95
-
sections:
96
-
- file: doc1
97
-
- url: https://example.com
98
-
title: Example Site
92
+
root: intro
93
+
parts:
94
+
- caption: Part Caption
95
+
sections:
96
+
- file: doc1
97
+
title: Document 1
98
+
- url: https://example.com
99
+
title: Example Site
99
100
```
100
101
101
102
### Numbering
102
103
103
104
You can automatically add numbers to all docs with a part by adding the `numbered: true` flag to it:
104
105
105
106
```yaml
106
-
main:
107
-
file: intro
108
-
parts:
109
-
- numbered: true
110
-
sections:
111
-
- file: doc1
112
-
- file: doc2
107
+
root: intro
108
+
parts:
109
+
- numbered: true
110
+
sections:
111
+
- file: doc1
112
+
- file: doc2
113
113
```
114
114
115
115
You can also **limit the TOC numbering depth** by setting the `numbered` flag to an integer instead of `true`, e.g., `numbered: 3`.
@@ -126,13 +126,12 @@ To have e.g. `numbered` added to all toctrees, set it under a `defaults` top-lev
126
126
```yaml
127
127
defaults:
128
128
numbered: true
129
-
main:
130
-
file: intro
129
+
root: intro
130
+
sections:
131
+
- file: doc1
131
132
sections:
132
-
- file: doc1
133
-
sections:
134
-
- file: doc2
135
-
- url: https://example.com
133
+
- file: doc2
134
+
- url: https://example.com
136
135
```
137
136
138
137
Available keys: `numbered`, `titlesonly`, `reversed`
0 commit comments