Skip to content

Commit

Permalink
Don't show "Contents" on pages without h1 headings
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg committed Aug 13, 2021
1 parent 3317891 commit a24fb58
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/furo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@


@lru_cache(maxsize=None)
def has_exactly_one_list_item(toc: str) -> bool:
"""Check if the toc has exactly one list item."""
def has_not_enough_items_to_show_toc(toc: str) -> bool:
"""Check if the toc has one or fewer items."""
assert toc

soup = BeautifulSoup(toc, "html.parser")
if len(soup.find_all("li")) == 1:
return True

return False
return len(soup.find_all("li")) <= 1


def wrap_elements_that_can_get_too_wide(content: str) -> str:
Expand Down Expand Up @@ -124,7 +121,7 @@ def _compute_hide_toc(context: Dict[str, Any]) -> bool:
elif not context["toc"]:
return True

return has_exactly_one_list_item(context["toc"])
return has_not_enough_items_to_show_toc(context["toc"])


@lru_cache(maxsize=None)
Expand Down

0 comments on commit a24fb58

Please sign in to comment.