hackish incomplete cached feed reader

This commit is contained in:
Alexis Marie Wright 2022-03-17 21:25:15 -04:00
parent 4629a55b90
commit f63a675358
4 changed files with 57 additions and 13 deletions

15
lib/ComicPage.php Normal file
View File

@ -0,0 +1,15 @@
<?php
declare(strict_types = 1);
class ComicPage {
public string $href = '';
public string $pageNo = '';
public string $title = '';
public string $imageUrl = '';
function __construct() {}
function __toString() {
return "[{$this->href}] [{$this->imageUrl}] {$this->pageNo} // {$this->title}";
}
};

View File

@ -3,22 +3,13 @@ declare(strict_types = 1);
include_once('config/default.php');
include_once('lib/ComicPage.php');
include_once('lib/log.php');
include_once('lib/fetch-url.php');
class ComicPage {
public string $href = '';
public string $pageNo = '';
public string $title = '';
public string $imageUrl = '';
function __construct() {}
function __toString() {
return "[{$this->href}] [{$this->imageUrl}] {$this->pageNo} // {$this->title}";
}
};
function fetchSiteContent() {
// i don't know why i'm trying to use php's pathetic excuse for a type
// system lol
function fetchSiteContent(array $knownLinks) {
$comicPages = array();
$archivePage = fetchUrl(Config::archiveUrl);
@ -33,6 +24,11 @@ function fetchSiteContent() {
$link->href = Config::baseUrl . "/" . $el->href;
$link->pageNo = $el->innerText;
if (in_array($link->href, $knownLinks)) {
Log::info("Skipping known link {$link->href}");
continue;
};
// we'll get the image URL from this later, but fetch it early
// in order to check that the page exists; if not, we'll
// exclude it from the feed

31
lib/read-feed.php Normal file
View File

@ -0,0 +1,31 @@
<?php
declare(strict_types = 1);
include_once('lib/log.php');
include_once('lib/ComicPage.php');
function getKnownItemsFromFeed($feedPath) {
$feed = simplexml_load_file($feedPath);
$knownItems = array();
if (!$feed) {
Log::warn("Failed to load existing feed from {$feedPath} - rebuilding");
return array();
};
$items = $feed->xpath('//item/link');
foreach ($items as $item) {
$known = new ComicPage;
$known->href = $item->link;
$known->pageNo =
};
// $links = $feed->xpath('//item/link');
// return array_unique(
// array_map(function ($el) {
// return strip_tags($el->asXML());
// }, $links)
// );
return $knownItems;
};

View File

@ -11,8 +11,10 @@ include_once('config/default.php');
include_once('lib/log.php');
include_once('lib/fetch-site-content.php');
include_once('lib/read-feed.php');
include_once('lib/generate-feed.php');
$knownPages = readFeed(Config::feedPath);
$content = fetchSiteContent();
$feedXml = generateFeed(array_reverse($content));