Created
January 25, 2024 20:22
-
-
Save jackbaty/aaba9bbadec4753f927e554cbaa5d381 to your computer and use it in GitHub Desktop.
RSS-Bridge for my combined RSS feed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class JackBatyBridge extends FeedExpander | |
{ | |
const MAINTAINER = 'jackbaty'; | |
const NAME = 'JackBaty'; | |
const URI = 'https://github.com/RSS-Bridge/rss-bridge'; | |
const DESCRIPTION = <<<'TEXT' | |
This bridge merges the feeds from several of my websites.. | |
TEXT; | |
public function collectData() | |
{ | |
$limit = 20; | |
$feeds = [ | |
'https://baty.net/feed', | |
'https://daily.baty.net/allposts.xml', | |
'https://wiki.baty.net/rss.xml', | |
'https://baty.blog/feed.rss', | |
]; | |
// Remove empty values | |
$feeds = array_filter($feeds); | |
foreach ($feeds as $feed) { | |
if (count($feeds) > 1) { | |
// Allow one or more feeds to fail | |
try { | |
$this->collectExpandableDatas($feed); | |
} catch (HttpException $e) { | |
$this->logger->warning(sprintf('Exception in FeedMergeBridge: %s', create_sane_exception_message($e))); | |
$this->items[] = [ | |
'title' => 'RSS-Bridge: ' . $e->getMessage(), | |
// Give current time so it sorts to the top | |
'timestamp' => time(), | |
]; | |
continue; | |
} catch (\Exception $e) { | |
if (str_starts_with($e->getMessage(), 'Unable to parse xml')) { | |
// Allow this particular exception from FeedExpander | |
$this->logger->warning(sprintf('Exception in FeedMergeBridge: %s', create_sane_exception_message($e))); | |
continue; | |
} | |
throw $e; | |
} | |
} else { | |
$this->collectExpandableDatas($feed); | |
} | |
} | |
// Sort by timestamp descending | |
usort($this->items, function ($a, $b) { | |
$t1 = $a['timestamp'] ?? $a['uri'] ?? $a['title']; | |
$t2 = $b['timestamp'] ?? $b['uri'] ?? $b['title']; | |
return $t2 <=> $t1; | |
}); | |
// Remove duplicates by using url as unique key | |
$items = []; | |
foreach ($this->items as $item) { | |
$index = $item['uri'] ?? null; | |
if ($index) { | |
// Overwrite duplicates | |
$items[$index] = $item; | |
} else { | |
$items[] = $item; | |
} | |
} | |
$this->items = array_slice(array_values($items), 0, $limit); | |
} | |
public function getIcon() | |
{ | |
return 'https://cdn.jsdelivr.net/npm/[email protected]/dist/png/folder_feed.png'; | |
} | |
public function getName() | |
{ | |
return $this->getInput('feed_name') ?: 'Everything from Jack Baty'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment