Allow customizing HTML and hero titles
This commit is contained in:
parent
3d155bb46f
commit
2df1e82f31
3 changed files with 16 additions and 4 deletions
|
@ -82,6 +82,10 @@ class BlogPostTagPage(BaseListingPage):
|
||||||
subpage_types: list[Any] = []
|
subpage_types: list[Any] = []
|
||||||
parent_page_types = [BlogPostTagListPage]
|
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:
|
def get_listing_pages(self) -> models.QuerySet:
|
||||||
blog_list_page = BlogPostListPage.objects.all().live().get()
|
blog_list_page = BlogPostListPage.objects.all().live().get()
|
||||||
return blog_list_page.get_listing_pages().filter(tags=self)
|
return blog_list_page.get_listing_pages().filter(tags=self)
|
||||||
|
|
|
@ -46,6 +46,14 @@ class BasePage(Page):
|
||||||
"""
|
"""
|
||||||
return self.get_ancestors().exclude(depth__lte=2)
|
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):
|
class BaseContentPage(BasePage, MetadataMixin):
|
||||||
subtitle = models.CharField(max_length=255, blank=True)
|
subtitle = models.CharField(max_length=255, blank=True)
|
||||||
|
@ -149,7 +157,7 @@ class BaseContentPage(BasePage, MetadataMixin):
|
||||||
return self.hero_image_url
|
return self.hero_image_url
|
||||||
|
|
||||||
def get_meta_title(self) -> str:
|
def get_meta_title(self) -> str:
|
||||||
return self.seo_title or self.title
|
return self.html_title
|
||||||
|
|
||||||
def get_meta_description(self) -> str:
|
def get_meta_description(self) -> str:
|
||||||
return self.summary
|
return self.summary
|
||||||
|
@ -222,7 +230,7 @@ class BaseListingPage(RoutablePageMixin, BaseContentPage):
|
||||||
return self.feed_class(
|
return self.feed_class(
|
||||||
self.get_listing_pages(),
|
self.get_listing_pages(),
|
||||||
self.get_full_url(request),
|
self.get_full_url(request),
|
||||||
self.title,
|
self.html_title,
|
||||||
)(request)
|
)(request)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
{% block body_class %}{{ page.body_class }}{% endblock %}
|
{% 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 %}
|
{% block extra_head %}
|
||||||
{% meta_tags %}
|
{% meta_tags %}
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
{% include "common/breadcrumbs.html" with parents=page.get_parent_pages %}
|
{% 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 %}
|
{% if page.subtitle %}
|
||||||
<h2 class="subtitle">{{ page.subtitle }}</h2>
|
<h2 class="subtitle">{{ page.subtitle }}</h2>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in a new issue