Skip to content

Commit 145ce69

Browse files
committed
Warn when a plugin later in the list replaces the nav
1 parent 31985fa commit 145ce69

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

mkdocs_section_index/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ def __init__(self, title: str, file: File, config: Config, children: Sequence):
1616

1717
def __repr__(self):
1818
return "Section" + Page.__repr__(self)
19+
20+
def __eq__(self, other):
21+
return object.__eq__(self, other)
22+
23+
def __hash__(self):
24+
return object.__hash__(self)

mkdocs_section_index/plugin.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,21 @@ def on_nav(self, nav: Navigation, config, files) -> Navigation:
4040
child.parent = page
4141
# The page replaces the section; the section will be garbage-collected.
4242
items[i] = page
43+
self._nav = nav
4344
return nav
4445

4546
def on_env(self, env: Environment, config, files) -> Environment:
4647
env.loader = self._loader = rewrites.TemplateRewritingLoader(env.loader)
4748
return env
4849

50+
def on_page_context(self, context, page, config, nav):
51+
if nav != self._nav:
52+
self._nav = nav
53+
log.warning(
54+
"It seems that the effects of section-index plugin have been lost, because another MkDocs plugin re-wrote the nav! "
55+
"Re-order `plugins` in mkdocs.yml so that 'section-index' appears closer to the end."
56+
)
57+
4958
def on_post_build(self, config):
5059
if not self._loader.found_supported_theme:
5160
log.warning(

0 commit comments

Comments
 (0)