Skip to content

Commit

Permalink
Add get_meta_title function to get SEO title before saving
Browse files Browse the repository at this point in the history
  • Loading branch information
erick-otenyo committed Apr 23, 2024
1 parent 5a52058 commit 827c857
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pages/home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class HomePage(MetadataPageMixin, Page):
'cap.CapAlertListPage',
'glossary.GlossaryIndexPage',
'webstories.WebStoryListPage',

]
parent_page_type = [
'wagtailcore.Page'
Expand Down Expand Up @@ -135,18 +135,16 @@ def get_meta_image(self):
if self.search_image:
return self.search_image
return self.hero_banner

def save(self, *args, **kwargs):
if not self.search_image and self.hero_banner:
self.search_image = self.hero_banner
if not self.seo_title and self.hero_title:

if not self.seo_title and self.hero_title:
self.seo_title = self.hero_title
print("SEO_TITLE", self.seo_title)

if not self.search_description and self.hero_subtitle:
self.search_description = truncatechars(self.hero_subtitle, 160)
print("SEO_subtitle", self.search_description)

return super().save(*args, **kwargs)

Expand All @@ -155,6 +153,11 @@ def get_meta_description(self):
return self.search_description
return self.hero_subtitle

def get_meta_title(self):
if self.seo_title:
return self.seo_title
return self.hero_title

def get_context(self, request, *args, **kwargs):
context = super(HomePage, self).get_context(request, *args, **kwargs)

Expand Down

0 comments on commit 827c857

Please sign in to comment.