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">
|
||||
{% 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>
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue