Allow customizing HTML and hero titles

This commit is contained in:
Jake Howard 2022-08-27 13:12:45 +01:00
parent 3d155bb46f
commit 2df1e82f31
Signed by: jake
GPG key ID: 57AFB45680EDD477
3 changed files with 16 additions and 4 deletions

View file

@ -82,6 +82,10 @@ class BlogPostTagPage(BaseListingPage):
subpage_types: list[Any] = []
parent_page_types = [BlogPostTagListPage]
@cached_property
def html_title(self) -> str:
return f"Pages tagged with '{super().html_title}'"
def get_listing_pages(self) -> models.QuerySet:
blog_list_page = BlogPostListPage.objects.all().live().get()
return blog_list_page.get_listing_pages().filter(tags=self)

View file

@ -46,6 +46,14 @@ class BasePage(Page):
"""
return self.get_ancestors().exclude(depth__lte=2)
@cached_property
def html_title(self) -> str:
return self.seo_title or self.title
@cached_property
def hero_title(self) -> str:
return self.html_title
class BaseContentPage(BasePage, MetadataMixin):
subtitle = models.CharField(max_length=255, blank=True)
@ -149,7 +157,7 @@ class BaseContentPage(BasePage, MetadataMixin):
return self.hero_image_url
def get_meta_title(self) -> str:
return self.seo_title or self.title
return self.html_title
def get_meta_description(self) -> str:
return self.summary
@ -222,7 +230,7 @@ class BaseListingPage(RoutablePageMixin, BaseContentPage):
return self.feed_class(
self.get_listing_pages(),
self.get_full_url(request),
self.title,
self.html_title,
)(request)

View file

@ -4,7 +4,7 @@
{% block body_class %}{{ page.body_class }}{% endblock %}
{% block title %}{% if page.seo_title %}{{ page.seo_title }}{% else %}{{ page.title }}{% endif %}{% endblock %}
{% block title %}{{ page.html_title }}{% endblock %}
{% block extra_head %}
{% meta_tags %}
@ -21,7 +21,7 @@
<div class="columns">
<div class="column">
{% include "common/breadcrumbs.html" with parents=page.get_parent_pages %}
<h1 class="title is-spaced">{{ page.title }}</h1>
<h1 class="title is-spaced">{{ page.hero_title }}</h1>
{% if page.subtitle %}
<h2 class="subtitle">{{ page.subtitle }}</h2>
{% endif %}