Include lead image in feed item descriptions

The API already returns image_affiche_scale/image_full_scale for every
item (news and events alike), no extra request needed — just wasn't
being used. Embedded as an <img> at the top of the HTML description so
feed readers display it inline with the article.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
para
2026-09-25 23:53:19 +02:00
co-authored by Claude Sonnet 5
parent 13e5c94ee7
commit d917e76819
4 changed files with 36 additions and 11 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ function build_news_feed(): string
'link' => SITE . '/actualites/' . slugify($title) . '?u=' . rawurlencode($uid),
'guid' => $uid,
'pubDate' => $item['effective'] ?? $item['created'] ?? null,
'description' => full_body_html($item),
'description' => full_body_html($item, $title),
];
}
return build_rss(
+1 -1
View File
@@ -55,7 +55,7 @@ function build_events_feed(): string
$uid = $item['UID'] ?? $id;
$meta = format_event_meta($item);
$description = ($meta !== '' ? '<p>' . htmlspecialchars($meta, ENT_QUOTES, 'UTF-8') . '</p>' : '')
. full_body_html($item);
. full_body_html($item, $title);
// Un evenement recurrent partage le meme UID sur toutes ses
// occurrences (memes UID, dates differentes) : on suffixe le guid
// avec la date de debut pour rester unique par occurrence, comme
+19 -4
View File
@@ -135,17 +135,32 @@ function attachments_html(array $item): string
}
/**
* Corps HTML complet d'un item (texte riche + pieces jointes), avec
* repli sur le resume court si le texte complet est vide.
* Image principale de l'item (deja fournie par l'API, aucune requete
* supplementaire necessaire). "paysage_affiche" est une taille
* intermediaire raisonnable pour une image de flux RSS.
*/
function full_body_html(array $item): string
function lead_image_html(array $item, string $title): string
{
$url = $item['image_affiche_scale'] ?? $item['image_full_scale'] ?? null;
if (!$url) {
return '';
}
return '<p><img src="' . htmlspecialchars($url, ENT_QUOTES, 'UTF-8') . '" alt="'
. htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '" /></p>';
}
/**
* Corps HTML complet d'un item (image + texte riche + pieces jointes),
* avec repli sur le resume court si le texte complet est vide.
*/
function full_body_html(array $item, string $title): string
{
$body = trim($item['text_fr']['data'] ?? '');
if ($body === '') {
$summary = strip_html($item['description_fr'] ?? $item['description'] ?? null);
$body = $summary !== '' ? '<p>' . htmlspecialchars($summary, ENT_QUOTES, 'UTF-8') . '</p>' : '';
}
return $body . attachments_html($item);
return lead_image_html($item, $title) . $body . attachments_html($item);
}
function rfc822(?string $isoDate): string