mirror of
https://github.com/standardebooks/web.git
synced 2025-07-06 23:00:28 -04:00
Add subjects OPDS feeds, and switch to a more object-oriented approach to generating the OPDS feeds
This commit is contained in:
parent
a42de8ef4d
commit
133f93cdce
11 changed files with 187 additions and 51 deletions
|
@ -229,8 +229,8 @@ fi
|
|||
|
||||
php "${scriptsDir}/generate-opds.php" --webroot "${webRoot}" --weburl "${webUrl}"
|
||||
|
||||
sudo chown se:committers /standardebooks.org/web/www/opds/*.xml
|
||||
sudo chmod 664 /standardebooks.org/web/www/opds/*.xml
|
||||
sudo chown --recursive se:committers /standardebooks.org/web/www/opds/*
|
||||
sudo chmod --recursive 664 /standardebooks.org/web/www/opds/*
|
||||
|
||||
if [ "${verbose}" = "true" ]; then
|
||||
printf "Done.\n"
|
||||
|
|
|
@ -13,7 +13,10 @@ $webUrl = $options["weburl"] ?? "https://standardebooks.org";
|
|||
$contentFiles = explode("\n", trim(shell_exec('find ' . escapeshellarg($webRoot . '/www/ebooks/') . ' -name "content.opf" | sort') ?? ''));
|
||||
$allEbooks = [];
|
||||
$newestEbooks = [];
|
||||
$subjects = [];
|
||||
$ebooksBySubject = [];
|
||||
|
||||
// Iterate over all ebooks to build the various feeds
|
||||
foreach($contentFiles as $path){
|
||||
if($path == '')
|
||||
continue;
|
||||
|
@ -23,15 +26,44 @@ foreach($contentFiles as $path){
|
|||
|
||||
$allEbooks[$ebook->ModifiedTimestamp->format('Y-m-d\TH:i:s\Z') . ' ' . $ebook->Identifier] = $ebook;
|
||||
$newestEbooks[$ebook->Timestamp->format('Y-m-d\TH:i:s\Z') . ' ' . $ebook->Identifier] = $ebook;
|
||||
|
||||
foreach($ebook->Tags as $tag){
|
||||
// Add the book's subjects to the main subjects list
|
||||
if(!in_array($tag->Name, $subjects)){
|
||||
$subjects[] = $tag->Name;
|
||||
}
|
||||
|
||||
// Sort this ebook by subject
|
||||
$ebooksBySubject[$tag->Name][$ebook->Timestamp->format('Y-m-d\TH:i:s\Z') . ' ' . $ebook->Identifier] = $ebook;
|
||||
}
|
||||
}
|
||||
|
||||
// Create the subjects navigation document
|
||||
sort($subjects);
|
||||
$subjectNavigationEntries = [];
|
||||
foreach($subjects as $subject){
|
||||
// We leave the updated timestamp blank, as it will be filled in when we generate the individaul feeds
|
||||
$subjectNavigationEntries[] = new OpdsNavigationEntry('/opds/subjects/' . Formatter::MakeUrlSafe($subject), 'subsection', 'navigation', null, $subject, 'Browse Standard Ebooks tagged with “' . strtolower($subject) . ',” most-recently-released first.');
|
||||
}
|
||||
$subjectsFeed = new OpdsNavigationFeed('/opds/subjects', 'Standard Ebooks by Subject', '/opds', $subjectNavigationEntries);
|
||||
$subjectsFeed->Save(WEB_ROOT . '/opds/subjects/index.xml');
|
||||
|
||||
// Now generate each individual subject feed
|
||||
foreach($ebooksBySubject as $subject => $ebooks){
|
||||
krsort($ebooks);
|
||||
$subjectFeed = new OpdsAcquisitionFeed('/opds/subjects/' . Formatter::MakeUrlSafe($subject), $subject, '/opds/subjects', $ebooks);
|
||||
$subjectFeed->Save(WEB_ROOT . '/opds/subjects/' . Formatter::MakeUrlSafe($subject) . '.xml');
|
||||
}
|
||||
|
||||
// Create the 'all' feed
|
||||
krsort($allEbooks);
|
||||
$allFeed = new OpdsFeed(SITE_URL . '/opds/all', 'All Standard Ebooks', $allEbooks, true);
|
||||
$allFeed = new OpdsAcquisitionFeed('/opds/all', 'All Standard Ebooks', '/opds', $allEbooks, true);
|
||||
$allFeed->Save(WEB_ROOT . '/opds/all.xml');
|
||||
|
||||
// Create the 'newest' feed
|
||||
krsort($newestEbooks);
|
||||
$newestEbooks = array_slice($newestEbooks, 0, 30);
|
||||
$newestFeed = new OpdsFeed(SITE_URL . '/opds/newest', 'Newest 30 Standard Ebooks', $newestEbooks);
|
||||
$newestFeed->Save(WEB_ROOT . '/opds/newest.xml');
|
||||
$newestFeed = new OpdsAcquisitionFeed('/opds/new-releases', 'Newest 30 Standard Ebooks', '/opds', $newestEbooks);
|
||||
$newestFeed->Save(WEB_ROOT . '/opds/new-releases.xml');
|
||||
|
||||
?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue