diff --git a/generate_indieblog_rss.php b/generate_indieblog_rss.php new file mode 100644 index 0000000..3f7f2aa --- /dev/null +++ b/generate_indieblog_rss.php @@ -0,0 +1,63 @@ += $recentCutoff && + !in_array($item['itemid'], $includedIds); +}); + +// Sort items by publication date (newest first) +usort($recentItems, fn($a, $b) => $b['published'] <=> $a['published']); + +// Generate RSS feed +$rss = new SimpleXMLElement(''); +$channel = $rss->addChild('channel'); +$channel->addChild('title', 'IndieBlog Feed (Recent)'); +$channel->addChild('link', 'https://indieblog.page/'); +$channel->addChild('description', 'RSS feed of articles published in the last 24 hours'); +$channel->addChild('language', 'en'); + +// Add recent items to RSS feed +$newEntries = []; +foreach ($recentItems as $item) { + $rssItem = $channel->addChild('item'); + $rssItem->addChild('title', htmlspecialchars($item['itemtitle'] ?? 'No title')); + $rssItem->addChild('link', htmlspecialchars($item['itemurl'] ?? '')); + $rssItem->addChild('description', htmlspecialchars($item['feedtitle'] ?? '')); + $rssItem->addChild('pubDate', date(DATE_RSS, $item['published'])); + $newEntries[] = $item['itemid']; +} + +// Update cache with newly processed IDs +if (!empty($newEntries)) { + file_put_contents($cacheFile, implode("\n", array_merge($includedIds, $newEntries))); +} + +// Save RSS feed +$rss->asXML($rssFile);