Only show ToC if there are enough items
This commit is contained in:
parent
2fbc96946d
commit
b6fa67163f
5 changed files with 14 additions and 13 deletions
|
@ -23,11 +23,8 @@ class BlogPostListPage(BaseListingPage):
|
||||||
]
|
]
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def table_of_contents(self) -> list[TocEntry]:
|
def show_table_of_contents(self) -> bool:
|
||||||
"""
|
return False
|
||||||
Showing an accurate ToC is complex alongside pagination
|
|
||||||
"""
|
|
||||||
return []
|
|
||||||
|
|
||||||
def get_listing_pages(self) -> models.QuerySet:
|
def get_listing_pages(self) -> models.QuerySet:
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -96,6 +96,10 @@ class BaseContentPage(BasePage, MetadataMixin):
|
||||||
def table_of_contents(self) -> list[TocEntry]:
|
def table_of_contents(self) -> list[TocEntry]:
|
||||||
return get_table_of_contents(self.content_html)
|
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
|
@cached_property
|
||||||
def reading_time(self) -> timedelta:
|
def reading_time(self) -> timedelta:
|
||||||
"""
|
"""
|
||||||
|
@ -204,8 +208,8 @@ class BaseListingPage(RoutablePageMixin, BaseContentPage):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def table_of_contents(self) -> list[TocEntry]:
|
def show_table_of_contents(self) -> bool:
|
||||||
return []
|
return False
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def show_reading_time(self) -> bool:
|
def show_reading_time(self) -> bool:
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="column is-narrow dropdown-wrapper is-hidden-touch is-grouped">
|
<div class="column is-narrow dropdown-wrapper is-hidden-touch is-grouped">
|
||||||
{% block hero_buttons %}
|
{% 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 is-hoverable is-right" id="table-of-contents">
|
||||||
<div class="dropdown-trigger">
|
<div class="dropdown-trigger">
|
||||||
<button class="button is-radiusless" aria-haspopup="true" aria-controls="toc-menu">
|
<button class="button is-radiusless" aria-haspopup="true" aria-controls="toc-menu">
|
||||||
|
|
|
@ -10,7 +10,7 @@ from wagtail.models import Page
|
||||||
from wagtail.search.utils import parse_query_string
|
from wagtail.search.utils import parse_query_string
|
||||||
|
|
||||||
from website.common.models import BaseContentPage
|
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
|
from .serializers import MIN_SEARCH_LENGTH, SearchParamsSerializer
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ class SearchPage(RoutablePageMixin, BaseContentPage):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def table_of_contents(self) -> list[TocEntry]:
|
def show_table_of_contents(self) -> bool:
|
||||||
return []
|
return False
|
||||||
|
|
||||||
def get_context(self, request: HttpRequest) -> dict:
|
def get_context(self, request: HttpRequest) -> dict:
|
||||||
context = super().get_context(request)
|
context = super().get_context(request)
|
||||||
|
|
|
@ -41,8 +41,8 @@ class SpotifyPlaylistPage(BaseContentPage):
|
||||||
]
|
]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def table_of_contents(self) -> list:
|
def show_table_of_contents(self) -> bool:
|
||||||
return []
|
return False
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def reading_time(self) -> timedelta:
|
def reading_time(self) -> timedelta:
|
||||||
|
|
Loading…
Reference in a new issue