@@ -8,6 +8,7 @@ from dataclasses import dataclass | |||
from datetime import date | |||
from pathlib import Path | |||
from time import perf_counter | |||
from urllib.parse import urlparse | |||
import httpx | |||
import lassie | |||
@@ -158,24 +159,36 @@ def generate(): | |||
def fetch_metadata(title, url, description): | |||
"""Fetch additional metadata.""" | |||
parsed_url = urlparse(url) | |||
root_url = f"{parsed_url.scheme}://{parsed_url.netloc}/" | |||
data = lassie.fetch(url) | |||
og_image = "" | |||
favicon = "" | |||
for image in data.get("images"): | |||
image_type = image.get("type") | |||
if image_type == "og:image" and not og_image: | |||
og_image = image["src"] | |||
image_src = image.get("src") | |||
if image_src == root_url: | |||
og_image = "" | |||
continue | |||
elif image_type == "og:image" and not og_image: | |||
og_image = image_src | |||
continue | |||
elif image_type == "twitter:image" and not og_image: | |||
og_image = image["src"] | |||
og_image = image_src | |||
continue | |||
elif image_type == "favicon": | |||
image_src = image["src"] | |||
if not favicon: | |||
favicon = image_src | |||
elif ".ico" in favicon and ".ico" not in image_src: | |||
favicon = image_src | |||
# Fallback on server's default. | |||
if not favicon: | |||
favico_url = f"{root_url}favicon.ico" | |||
response = httpx.get(favico_url) | |||
if response.status_code == 200: | |||
favicon = favico_url | |||
if data.get("title") != title: | |||
print(data.get("title"), "vs.", title, url) | |||
description = description or data.get("description", "") | |||
@@ -190,20 +203,17 @@ def metadata(): | |||
if cache.url.startswith("https://tw5.immateriel.fr"): | |||
print("Skipping", cache.url) | |||
continue | |||
if cache.favicon and ( | |||
cache.description | |||
or cache.url.startswith( | |||
( | |||
"https://www.la-grange.net", | |||
"https://gilest.org", | |||
"https://vasilis.nl", | |||
"https://www.danmcquillan.org", | |||
"https://public-inbox.org", | |||
) | |||
) | |||
): | |||
print("Skipping", cache.url) | |||
continue | |||
# if cache.description or cache.url.startswith( | |||
# ( | |||
# "https://www.la-grange.net", | |||
# "https://gilest.org", | |||
# "https://vasilis.nl", | |||
# "https://www.danmcquillan.org", | |||
# "https://public-inbox.org", | |||
# ) | |||
# ): | |||
# print("Skipping", cache.url) | |||
# continue | |||
print("Fetching metadata for", cache.url, cache.title) | |||
og_image, description, favicon = fetch_metadata( | |||
cache.title, cache.url, cache.description |
@@ -4,7 +4,7 @@ hash_url: 1fe484434058e9c44d21bfebb0ddba31 | |||
archive_date: 2024-01-28 | |||
og_image: | |||
description: | |||
favicon: | |||
favicon: https://www.la-grange.net/favicon.ico | |||
<figure> | |||
<img src="https://www.la-grange.net/2024/01/23/3152-ciel.jpg" alt="Ciel nuageux au dessus de maisons. On ne voit que le premier étage des maisons."> |
@@ -2,7 +2,7 @@ title: Tools shape practices shape tools… | |||
url: https://www.quaternum.net/2024/01/08/tools-shape-practices-shape-tools/ | |||
hash_url: 34fec23081019abd741e0578b050c40e | |||
archive_date: 2024-01-11 | |||
og_image: https://www.quaternum.net/ | |||
og_image: | |||
description: Je découvre (très) tardivement ce _mantra_, ou plutôt ce positionnement récursif et infini : les pratiques modèlent les outils qui modèlent les pratiques etc. | |||
favicon: | |||
@@ -2,7 +2,7 @@ title: Fabrique : concept | |||
url: https://www.quaternum.net/2023/06/02/fabrique-concept/ | |||
hash_url: 55477786fc56b6fc37bb97231b634d90 | |||
archive_date: 2024-01-07 | |||
og_image: https://www.quaternum.net/ | |||
og_image: | |||
description: Le terme fabrique définit une approche spécifique dans la création et dans la production d’artefact, y compris dans le domaine de l’édition. | |||
favicon: | |||
@@ -4,7 +4,7 @@ hash_url: 790f724c45b26de460f9eeac04d48884 | |||
archive_date: 2024-01-28 | |||
og_image: | |||
description: | |||
favicon: | |||
favicon: https://www.la-grange.net/favicon.ico | |||
<figure> | |||
<img src="https://www.la-grange.net/2024/01/20/3134-carnets.jpg" alt="Carnets de notes en archéologie écrit en japonais avec des dessins."> |
@@ -4,7 +4,7 @@ hash_url: 87c468a4eddabe5d2c28e902d7f17504 | |||
archive_date: 2024-01-11 | |||
og_image: | |||
description: | |||
favicon: | |||
favicon: https://www.la-grange.net/favicon.ico | |||
<figure> | |||
<img src="https://www.la-grange.net/2024/01/09/3045-glace.jpg" alt="Cubes de glace étalés sur la chaussée à côté de boîte en plastique et d'un poteau rouge. La glace a un peu fondu."> |
@@ -4,7 +4,7 @@ hash_url: 956819385548bba6e768563b12edc2d6 | |||
archive_date: 2024-01-28 | |||
og_image: | |||
description: | |||
favicon: | |||
favicon: https://www.la-grange.net/favicon.ico | |||
<figure> | |||
<img src="https://www.la-grange.net/2024/01/24/3154-herbe.jpg" alt="Couverte du livre la fraîcheur de l'herbe avec une illustration de graminées."> |
@@ -4,7 +4,7 @@ hash_url: 9bc04d41d25fc73391116d99b7259a3d | |||
archive_date: 2024-01-07 | |||
og_image: | |||
description: | |||
favicon: | |||
favicon: https://www.la-grange.net/favicon.ico | |||
<figure> | |||
<img src="https://www.la-grange.net/2023/07/10/0797-batiment-visage.jpg" alt="bâtiments avec deux signes blancs. L'ensemble donne un peu l'impression d'un visage."> |
@@ -4,7 +4,7 @@ hash_url: b692faaa55fd2775e957b20e833e9e5e | |||
archive_date: 2024-01-28 | |||
og_image: | |||
description: | |||
favicon: | |||
favicon: https://www.la-grange.net/favicon.ico | |||
<figure> | |||
<img src="https://www.la-grange.net/2024/01/26/3159-chauffage.jpg" alt="Détail de la lampe à chauffer."> |
@@ -4,7 +4,7 @@ hash_url: d75afc90a9d3c3b5a56b69446795fbb5 | |||
archive_date: 2024-01-07 | |||
og_image: | |||
description: | |||
favicon: | |||
favicon: https://www.la-grange.net/favicon.ico | |||
<figure> | |||
<img src="https://www.la-grange.net/2024/01/06/3008-furikake.jpg" alt="Feuilles de céleri et de persil, finement hâchées avec du zeste de citron."> |