Tweak OpenGraph

This commit is contained in:
Thomas Sileo 2018-08-05 13:55:48 +02:00
parent 5dce025700
commit 34579bd151
2 changed files with 10 additions and 1 deletions

View file

@ -77,6 +77,7 @@
{% if meta and meta.og_metadata and obj | has_type('Note') %} {% if meta and meta.og_metadata and obj | has_type('Note') %}
{% for og in meta.og_metadata %} {% for og in meta.og_metadata %}
{% if og.url %}
<a href="{{ og.url }}" class="og-link" style="margin:30px 0;clear:both;display: flex;"> <a href="{{ og.url }}" class="og-link" style="margin:30px 0;clear:both;display: flex;">
<div> <div>
<img style="width:100px;border-radius:3px;" src="{{ og.image | get_og_image_url }}"> <img style="width:100px;border-radius:3px;" src="{{ og.image | get_og_image_url }}">
@ -87,6 +88,7 @@
<small>{{ og.site_name }}</small> <small>{{ og.site_name }}</small>
</div> </div>
</a> </a>
{% endif %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}

View file

@ -42,4 +42,11 @@ def fetch_og_metadata(user_agent, links):
r = requests.get(l, headers={"User-Agent": user_agent}, timeout=15) r = requests.get(l, headers={"User-Agent": user_agent}, timeout=15)
r.raise_for_status() r.raise_for_status()
htmls.append(r.text) htmls.append(r.text)
return [dict(opengraph.OpenGraph(html=html)) for html in htmls]
res = []
for html in htmls:
data = dict(opengraph.OpenGraph(html=html))
if data.get("url"):
res.append(data)
return res