Read existing feed if present
This commit is contained in:
parent
386057dfe5
commit
b4ec4c5f73
|
@ -0,0 +1,14 @@
|
|||
<?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}";
|
||||
}
|
||||
};
|
|
@ -5,18 +5,7 @@ include_once('config/default.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}";
|
||||
}
|
||||
};
|
||||
include_once('lib/comic-page.php');
|
||||
|
||||
function fetchSiteContent() {
|
||||
$comicPages = array();
|
||||
|
|
|
@ -25,11 +25,12 @@ function generateFeed($content) {
|
|||
]);
|
||||
|
||||
$items[] = $twig->render('item.xml', [
|
||||
'title' => $page->title,
|
||||
'title' => htmlspecialchars($page->title),
|
||||
'pageNo' => $page->pageNo,
|
||||
'fullTitle' => htmlspecialchars($page->pageNo . " // " . $page->title),
|
||||
'date' => $now,
|
||||
'url' => $page->href,
|
||||
'imageUrl' => htmlspecialchars($page->imageUrl),
|
||||
'content' => htmlspecialchars($content)
|
||||
]);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
include_once('config/default.php');
|
||||
|
||||
include_once('lib/comic-page.php');
|
||||
include_once('lib/log.php');
|
||||
|
||||
function readFeed($path) {
|
||||
$awfulSinging = file_get_contents($path);
|
||||
|
||||
if ($awfulSinging === false) {
|
||||
Log::warn("Failed to read existing XML feed from " . $path);
|
||||
return null;
|
||||
};
|
||||
|
||||
Log::info("Read " . strlen($awfulSinging) . " bytes from " . $path);
|
||||
|
||||
$xml = simplexml_load_string($awfulSinging);
|
||||
|
||||
$items = array();
|
||||
foreach ($xml->channel->item as $itemXml) {
|
||||
$item = new ComicPage;
|
||||
$item->href = (string) $itemXml->link;
|
||||
$item->pageNo = (string) $itemXml['data-pageno'];
|
||||
$item->title = (string) $itemXml['data-title'];
|
||||
$item->imageUrl = (string) $itemXml['data-imageurl'];
|
||||
|
||||
print $item;
|
||||
exit();
|
||||
|
||||
array_push($item);
|
||||
};
|
||||
};
|
|
@ -10,9 +10,11 @@ require_once('vendor/autoload.php');
|
|||
include_once('config/default.php');
|
||||
|
||||
include_once('lib/log.php');
|
||||
include_once('lib/read-feed.php');
|
||||
include_once('lib/fetch-site-content.php');
|
||||
include_once('lib/generate-feed.php');
|
||||
|
||||
$existingFeed = readFeed(Config::feedPath);
|
||||
$content = fetchSiteContent();
|
||||
$feedXml = generateFeed(array_reverse($content));
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<item data-pageno="{{ pageNo }}" data-title="{{ title }}">
|
||||
<item
|
||||
data-pageno="{{ pageNo }}"
|
||||
data-title="{{ title }}"
|
||||
data-imageurl="{{ imageUrl }}">
|
||||
<title>{{ fullTitle }}</title>
|
||||
<description>{{ content }}</description>
|
||||
<pubDate>{{ date }}</pubDate>
|
||||
|
|
Loading…
Reference in New Issue