Use smaller, PNG image for meta image
This ensures it's not too large, but also crawlers are more likely to support PNG than webp
This commit is contained in:
parent
be009dcb37
commit
eaa5b063f4
2 changed files with 17 additions and 15 deletions
|
@ -26,10 +26,13 @@ class LMOTFYSerializer(serializers.ModelSerializer):
|
||||||
def get_full_url(self, page: BlogPostPage) -> str:
|
def get_full_url(self, page: BlogPostPage) -> str:
|
||||||
return page.get_full_url(request=self.context["request"])
|
return page.get_full_url(request=self.context["request"])
|
||||||
|
|
||||||
def get_image(self, page: BlogPostPage) -> str:
|
def get_image(self, page: BlogPostPage) -> str | None:
|
||||||
hero_image_url = page.hero_image_url
|
image_url = page.get_meta_image_url(request=self.context["request"])
|
||||||
|
|
||||||
if isinstance(hero_image_url, str) and hero_image_url[0] == "/":
|
if not image_url:
|
||||||
return self.context["request"].build_absolute_uri(hero_image_url)
|
return None
|
||||||
|
|
||||||
return hero_image_url
|
if image_url[0] == "/":
|
||||||
|
return self.context["request"].build_absolute_uri(image_url)
|
||||||
|
|
||||||
|
return image_url
|
||||||
|
|
|
@ -128,27 +128,26 @@ class BaseContentPage(BasePage, MetadataMixin):
|
||||||
def plain_text(self) -> str:
|
def plain_text(self) -> str:
|
||||||
return extract_text(self.content_html)
|
return extract_text(self.content_html)
|
||||||
|
|
||||||
@cached_property
|
def hero_url(self, unsplash_size: str, wagtail_image_spec: str) -> Optional[str]:
|
||||||
def hero_image_url(self) -> Optional[str]:
|
|
||||||
if self.hero_unsplash_photo_id is not None:
|
if self.hero_unsplash_photo_id is not None:
|
||||||
return self.hero_unsplash_photo.get_image_urls()["regular"]
|
return self.hero_unsplash_photo.get_image_urls()[unsplash_size]
|
||||||
elif self.hero_image_id is not None:
|
elif self.hero_image_id is not None:
|
||||||
return generate_image_url(self.hero_image, "width-1200")
|
return generate_image_url(self.hero_image, wagtail_image_spec)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def hero_image_url(self) -> Optional[str]:
|
||||||
|
return self.hero_url("full", "width-2000")
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def list_image_url(self) -> Optional[str]:
|
def list_image_url(self) -> Optional[str]:
|
||||||
if self.hero_unsplash_photo_id is not None:
|
return self.hero_url("small", "width-400")
|
||||||
return self.hero_unsplash_photo.get_image_urls()["small"]
|
|
||||||
elif self.hero_image_id is not None:
|
|
||||||
return generate_image_url(self.hero_image, "width-400")
|
|
||||||
return None
|
|
||||||
|
|
||||||
def get_meta_url(self) -> str:
|
def get_meta_url(self) -> str:
|
||||||
return self.full_url
|
return self.full_url
|
||||||
|
|
||||||
def get_meta_image_url(self, request: HttpRequest) -> Optional[str]:
|
def get_meta_image_url(self, request: HttpRequest) -> Optional[str]:
|
||||||
return self.hero_image_url
|
return self.hero_url("regular", "width-1000|format-png")
|
||||||
|
|
||||||
def get_meta_title(self) -> str:
|
def get_meta_title(self) -> str:
|
||||||
return self.html_title
|
return self.html_title
|
||||||
|
|
Loading…
Reference in a new issue