Fix W3C validator errors: duplicate guids and missing atom:link self
- Recurring events share one UID across all occurrences (confirmed via the API: same UID, different start dates), which produced duplicate <guid> values the RSS spec forbids. Suffix the guid with the occurrence's start date to make it unique per occurrence. - Add atom:link rel="self" to the channel, per the validator's recommendation, in both the PHP and Python implementations. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+2
-1
@@ -44,7 +44,8 @@ function build_news_feed(): string
|
||||
'Silly.be - Actualités',
|
||||
SITE . '/actualites',
|
||||
'Actualités de la commune de Silly (Belgique)',
|
||||
$items
|
||||
$items,
|
||||
'https://sillycone-village.be/silly-rss/actualites.php'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+7
-2
@@ -56,10 +56,14 @@ function build_events_feed(): string
|
||||
$meta = format_event_meta($item);
|
||||
$description = ($meta !== '' ? '<p>' . htmlspecialchars($meta, ENT_QUOTES, 'UTF-8') . '</p>' : '')
|
||||
. full_body_html($item);
|
||||
// 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
|
||||
// l'exige la spec RSS.
|
||||
$items[] = [
|
||||
'title' => $title,
|
||||
'link' => SITE . '/agenda/' . slugify($title) . '?u=' . rawurlencode($uid),
|
||||
'guid' => $uid,
|
||||
'guid' => $uid . '-' . ($item['start'] ?? ''),
|
||||
'pubDate' => $item['created'] ?? $item['start'] ?? null,
|
||||
'description' => $description,
|
||||
];
|
||||
@@ -68,7 +72,8 @@ function build_events_feed(): string
|
||||
'Silly.be - Agenda',
|
||||
SITE . '/agenda',
|
||||
"Agenda / événements de la commune de Silly (Belgique)",
|
||||
$items
|
||||
$items,
|
||||
'https://sillycone-village.be/silly-rss/agenda.php'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -166,14 +166,17 @@ function xml_escape(string $text): string
|
||||
/**
|
||||
* Construit un flux RSS 2.0 complet a partir d'une liste d'items deja
|
||||
* formates (chacun un tableau title/link/guid/pubDate/description).
|
||||
* $selfUrl est l'URL du flux lui-meme (atom:link rel="self", recommande
|
||||
* par le validateur W3C).
|
||||
*/
|
||||
function build_rss(string $title, string $link, string $description, array $items): string
|
||||
function build_rss(string $title, string $link, string $description, array $items, string $selfUrl): string
|
||||
{
|
||||
$now = rfc822(null);
|
||||
$xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
||||
$xml .= '<rss version="2.0">' . "\n <channel>\n";
|
||||
$xml .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">' . "\n <channel>\n";
|
||||
$xml .= ' <title>' . xml_escape($title) . "</title>\n";
|
||||
$xml .= ' <link>' . xml_escape($link) . "</link>\n";
|
||||
$xml .= ' <atom:link href="' . xml_escape($selfUrl) . '" rel="self" type="application/rss+xml" />' . "\n";
|
||||
$xml .= ' <description>' . xml_escape($description) . "</description>\n";
|
||||
$xml .= " <language>fr-be</language>\n";
|
||||
$xml .= " <lastBuildDate>$now</lastBuildDate>\n";
|
||||
|
||||
Reference in New Issue
Block a user