Add and use image alt with Opengraph, if available

v2
Aonrud 2023-02-26 18:13:45 +00:00 zatwierdzone przez Aonrud
rodzic 3c07494809
commit 7b143fb0e1
2 zmienionych plików z 4 dodań i 2 usunięć

Wyświetl plik

@ -413,7 +413,7 @@
<div class="activity-og-meta">
{% if og_meta.image %}
<div>
<img src="{{ og_meta.image | media_proxy_url }}">
<img src="{{ og_meta.image | media_proxy_url }}" {% if og_meta.image__alt %} alt="{{ og_meta.image__alt }}"{% endif %}>
</div>
{% endif %}
<div>

Wyświetl plik

@ -28,6 +28,7 @@ class OpenGraphMeta(BaseModel):
url: str
title: str
image: str | None
image__alt: str | None
description: str | None
site_name: str
@ -47,11 +48,12 @@ def _scrap_og_meta(url: str, html: str) -> OpenGraphMeta | None:
"url": url,
"title": soup.find("title").text.strip(),
"image": None,
"image__alt": None,
"description": None,
"site_name": urlparse(url).hostname,
}
for field in OpenGraphMeta.__fields__.keys():
og_field = f"og:{field}"
og_field = f"og:{field.replace('__',':')}"
if ogs.get(og_field):
raw[field] = ogs.get(og_field, None)