kopia lustrzana https://github.com/Aonrud/ila-microblog.pub
Add and use image alt with Opengraph, if available
rodzic
3c07494809
commit
7b143fb0e1
|
@ -413,7 +413,7 @@
|
||||||
<div class="activity-og-meta">
|
<div class="activity-og-meta">
|
||||||
{% if og_meta.image %}
|
{% if og_meta.image %}
|
||||||
<div>
|
<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>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -28,6 +28,7 @@ class OpenGraphMeta(BaseModel):
|
||||||
url: str
|
url: str
|
||||||
title: str
|
title: str
|
||||||
image: str | None
|
image: str | None
|
||||||
|
image__alt: str | None
|
||||||
description: str | None
|
description: str | None
|
||||||
site_name: str
|
site_name: str
|
||||||
|
|
||||||
|
@ -47,11 +48,12 @@ def _scrap_og_meta(url: str, html: str) -> OpenGraphMeta | None:
|
||||||
"url": url,
|
"url": url,
|
||||||
"title": soup.find("title").text.strip(),
|
"title": soup.find("title").text.strip(),
|
||||||
"image": None,
|
"image": None,
|
||||||
|
"image__alt": None,
|
||||||
"description": None,
|
"description": None,
|
||||||
"site_name": urlparse(url).hostname,
|
"site_name": urlparse(url).hostname,
|
||||||
}
|
}
|
||||||
for field in OpenGraphMeta.__fields__.keys():
|
for field in OpenGraphMeta.__fields__.keys():
|
||||||
og_field = f"og:{field}"
|
og_field = f"og:{field.replace('__',':')}"
|
||||||
if ogs.get(og_field):
|
if ogs.get(og_field):
|
||||||
raw[field] = ogs.get(og_field, None)
|
raw[field] = ogs.get(og_field, None)
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue