From 9ed4c2643813f318d633a1f2596b147b53557e06 Mon Sep 17 00:00:00 2001 From: SansGuidon Date: Thu, 21 Nov 2024 00:32:08 +0000 Subject: [PATCH] add(script) to generate indieblog rss feed I'm hosting this on apache on cloudron and running it hourly --- generate_indieblog_rss.php | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 generate_indieblog_rss.php 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);