Skip to content

Commit 38672bf

Browse files
authored
🐛 FIX: Inserting toctree into empty document (#77)
1 parent 3d18fee commit 38672bf

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

sphinx_external_toc/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def get_changed(self, previous: "SiteMap") -> Set[str]:
239239
"""
240240
changed_docs = set()
241241
# check if the root document has changed
242-
if self.root.docname != previous.root.docname:
242+
if self.root != previous.root:
243243
changed_docs.add(self.root.docname)
244244
for name, doc in self._docs.items():
245245
if name not in previous:

sphinx_external_toc/events.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def add_changed_toctrees(
131131
"""Add docs with new or changed toctrees to changed list."""
132132
previous_map = getattr(app.env, "external_site_map", None)
133133
# move external_site_map from config to env
134+
site_map: SiteMap
134135
app.env.external_site_map = site_map = app.config.external_site_map
135136
# Compare to previous map, to record docnames with new or changed toctrees
136137
if not previous_map:
@@ -287,11 +288,14 @@ def insert_toctrees(app: Sphinx, doctree: nodes.document) -> None:
287288

288289
if toc_placeholders:
289290
toc_placeholders[0].replace_self(node_list)
290-
else:
291+
elif doctree.children and isinstance(doctree.children[-1], nodes.section):
291292
# note here the toctree cannot not just be appended to the end of the doc,
292293
# since `TocTreeCollector.process_doc` expects it in a section
294+
# otherwise it will result in the child documents being on the same level as this document
293295
# TODO check if there is this is always ok
294296
doctree.children[-1].extend(node_list)
297+
else:
298+
doctree.children.extend(node_list)
295299

296300

297301
class InsertToctrees(SphinxTransform):

0 commit comments

Comments
 (0)