From 4f8518b1a98f28d371eafbd4e24fcb24ff6c093d Mon Sep 17 00:00:00 2001 From: SansGuidon Date: Tue, 3 Dec 2024 00:16:48 +0000 Subject: [PATCH] add(cron) daily indieblog link list --- cron/generate_indieblog_daily_rss.php | 78 +++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 cron/generate_indieblog_daily_rss.php diff --git a/cron/generate_indieblog_daily_rss.php b/cron/generate_indieblog_daily_rss.php new file mode 100644 index 0000000..11edd58 --- /dev/null +++ b/cron/generate_indieblog_daily_rss.php @@ -0,0 +1,78 @@ += $cutoffDate; // Publie dans les 10 derniers jours +}); + +usort($newItems, fn($a, $b) => $b['published'] <=> $a['published']); + +$groupedByDay = []; +foreach ($newItems as $item) { + $day = isset($item['published']) && is_numeric($item['published']) + ? date('Y-m-d', $item['published']) + : date('Y-m-d'); + $groupedByDay[$day][] = $item; +} + +$rss = new SimpleXMLElement(''); +$channel = $rss->addChild('channel'); +$channel->addChild('title', 'IndieBlog Feed (Last 10 Days)'); +$channel->addChild('link', 'https://indieblog.page/'); +$channel->addChild('description', 'RSS feed of articles from the last 10 days'); +$channel->addChild('language', 'en'); + +$newEntries = []; +foreach ($groupedByDay as $day => $items) { + $rssItem = $channel->addChild('item'); + $rssItem->addChild('title', "Links for $day"); + $rssItem->addChild('link', "https://indieblog.page/$day#" . md5(json_encode($items))); + $rssItem->addChild('guid', "https://indieblog.page/$day#" . md5(json_encode($items))); + $rssItem->addChild('pubDate', date(DATE_RSS, strtotime($day))); + + $description = ""; + + addCData($rssItem->addChild('description'), $description); +} + +if (!empty($newEntries)) { + file_put_contents($cacheFile, implode("\n", array_merge($includedIds, $newEntries))); +} + +$rss->asXML($rssFile); + +function addCData(SimpleXMLElement $node, $content) +{ + $domNode = dom_import_simplexml($node); + $domOwner = $domNode->ownerDocument; + $domNode->appendChild($domOwner->createCDATASection($content)); +}