Skip to content

Commit

Permalink
Warn when a plugin later in the list replaces the nav
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed Feb 2, 2021
1 parent 31985fa commit 145ce69
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mkdocs_section_index/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ def __init__(self, title: str, file: File, config: Config, children: Sequence):

def __repr__(self):
return "Section" + Page.__repr__(self)

def __eq__(self, other):
return object.__eq__(self, other)

def __hash__(self):
return object.__hash__(self)
9 changes: 9 additions & 0 deletions mkdocs_section_index/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,21 @@ def on_nav(self, nav: Navigation, config, files) -> Navigation:
child.parent = page
# The page replaces the section; the section will be garbage-collected.
items[i] = page
self._nav = nav
return nav

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

def on_page_context(self, context, page, config, nav):
if nav != self._nav:
self._nav = nav
log.warning(
"It seems that the effects of section-index plugin have been lost, because another MkDocs plugin re-wrote the nav! "
"Re-order `plugins` in mkdocs.yml so that 'section-index' appears closer to the end."
)

def on_post_build(self, config):
if not self._loader.found_supported_theme:
log.warning(
Expand Down

0 comments on commit 145ce69

Please sign in to comment.