Skip to content

Commit

Permalink
Add 'published' date to Atom feed entries
Browse files Browse the repository at this point in the history
This change includes the 'published' date for each feed entry, using the post's creation timestamp. It enhances compliance with the Atom specification and provides more accurate metadata for feed consumers. Indentation inconsistencies in the file were also corrected for better readability.
  • Loading branch information
svandragt committed Jan 11, 2025
1 parent 2345300 commit 4b8251c
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/themes/default/feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

function escape(string $html): string
{
return htmlspecialchars($html, ENT_XML1 | ENT_QUOTES | ENT_SUBSTITUTE);
return htmlspecialchars($html, ENT_XML1 | ENT_QUOTES | ENT_SUBSTITUTE);
}

header('Content-type: application/atom+xml');
Expand All @@ -26,13 +26,14 @@ function escape(string $html): string
$Author->addChild('email', escape($config['author_email']));

foreach ($data['posts'] as $bean) {
$Entry = $Xml->addChild('entry');
$Entry->addChild('id', Lamb\permalink($bean));
$Entry->addChild('title', escape($bean->title ?? ''));
$Entry->addChild('updated', date(DATE_ATOM, strtotime($bean->updated)));
$Content = $Entry->addChild('content', $bean->transformed);
$Content->addAttribute('type', 'html');
$Link = $Entry->addChild('link');
$Link->addAttribute('href', Lamb\permalink($bean));
$Entry = $Xml->addChild('entry');
$Entry->addChild('id', Lamb\permalink($bean));
$Entry->addChild('title', escape($bean->title ?? ''));
$Entry->addChild('published', date(DATE_ATOM, strtotime($bean->created)));
$Entry->addChild('updated', date(DATE_ATOM, strtotime($bean->updated)));
$Content = $Entry->addChild('content', $bean->transformed);
$Content->addAttribute('type', 'html');
$Link = $Entry->addChild('link');
$Link->addAttribute('href', Lamb\permalink($bean));
}
echo $Xml->asXML();

0 comments on commit 4b8251c

Please sign in to comment.