Skip to content

Commit

Permalink
Merge pull request #112 from mbasaglia/clean-toc
Browse files Browse the repository at this point in the history
Avoid superfluous entries in the TOC
  • Loading branch information
timvink authored Aug 19, 2024
2 parents aa6b81f + eadc5a1 commit ac37d0f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mkdocs_print_site_plugin/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def get_toc_sidebar(self) -> TableOfContents:
Reference: https://github.com/mkdocs/mkdocs/blob/master/mkdocs/structure/toc.py
"""
toc = []
excluded_pages = self.plugin_config.get("exclude", [])

if self.plugin_config.get("enumerate_headings"):
chapter_number = 0
Expand Down Expand Up @@ -250,7 +251,7 @@ def get_toc_sidebar(self) -> TableOfContents:
title=title, id=f"section-{to_snake_case(item.title)}", level=0
)

subpages = [p for p in item.children if p.is_page]
subpages = [p for p in item.children if p.is_page and not exclude(p.file.src_path, excluded_pages)]
for page in subpages:
if self.plugin_config.get("enumerate_headings"):
chapter_number += 1
Expand All @@ -263,7 +264,8 @@ def get_toc_sidebar(self) -> TableOfContents:
AnchorLink(title=title, id=f"{page_key}", level=1)
)

toc.append(section_link)
if len(subpages) > 0:
toc.append(section_link)

return TableOfContents(toc)

Expand Down

0 comments on commit ac37d0f

Please sign in to comment.