Only show ToC if there are enough items

This commit is contained in:
Jake Howard 2022-10-29 14:53:34 +01:00
parent 2fbc96946d
commit b6fa67163f
Signed by: jake
GPG Key ID: 57AFB45680EDD477
5 changed files with 14 additions and 13 deletions

View File

@ -23,11 +23,8 @@ class BlogPostListPage(BaseListingPage):
]
@cached_property
def table_of_contents(self) -> list[TocEntry]:
"""
Showing an accurate ToC is complex alongside pagination
"""
return []
def show_table_of_contents(self) -> bool:
return False
def get_listing_pages(self) -> models.QuerySet:
return (

View File

@ -96,6 +96,10 @@ class BaseContentPage(BasePage, MetadataMixin):
def table_of_contents(self) -> list[TocEntry]:
return get_table_of_contents(self.content_html)
@cached_property
def show_table_of_contents(self) -> bool:
return len(self.table_of_contents) >= 3
@cached_property
def reading_time(self) -> timedelta:
"""
@ -204,8 +208,8 @@ class BaseListingPage(RoutablePageMixin, BaseContentPage):
return context
@cached_property
def table_of_contents(self) -> list[TocEntry]:
return []
def show_table_of_contents(self) -> bool:
return False
@cached_property
def show_reading_time(self) -> bool:

View File

@ -32,7 +32,7 @@
</div>
<div class="column is-narrow dropdown-wrapper is-hidden-touch is-grouped">
{% block hero_buttons %}
{% if page.table_of_contents %}
{% if page.show_table_of_contents %}
<div class="dropdown is-hoverable is-right" id="table-of-contents">
<div class="dropdown-trigger">
<button class="button is-radiusless" aria-haspopup="true" aria-controls="toc-menu">

View File

@ -10,7 +10,7 @@ from wagtail.models import Page
from wagtail.search.utils import parse_query_string
from website.common.models import BaseContentPage
from website.common.utils import TocEntry, get_page_models
from website.common.utils import get_page_models
from .serializers import MIN_SEARCH_LENGTH, SearchParamsSerializer
@ -29,8 +29,8 @@ class SearchPage(RoutablePageMixin, BaseContentPage):
return False
@cached_property
def table_of_contents(self) -> list[TocEntry]:
return []
def show_table_of_contents(self) -> bool:
return False
def get_context(self, request: HttpRequest) -> dict:
context = super().get_context(request)

View File

@ -41,8 +41,8 @@ class SpotifyPlaylistPage(BaseContentPage):
]
@property
def table_of_contents(self) -> list:
return []
def show_table_of_contents(self) -> bool:
return False
@cached_property
def reading_time(self) -> timedelta: