mirror of
https://github.com/standardebooks/web.git
synced 2025-07-08 07:40:39 -04:00
Improve how collections are organized and internally and printed to HTML
This commit is contained in:
parent
c8cacc4ace
commit
aed7db7fc1
4 changed files with 23 additions and 15 deletions
|
@ -7,6 +7,6 @@ class Collection{
|
|||
|
||||
public function __construct(string $name){
|
||||
$this->Name = $name;
|
||||
$this->Url = '/collections/' . strtolower(str_replace(' ', '-', Formatter::ToPlainText(Formatter::RemoveDiacritics($this->Name))));
|
||||
$this->Url = '/collections/' . Formatter::MakeUrlSafe($this->Name);
|
||||
}
|
||||
}
|
||||
|
|
3
lib/InvalidCollectionException.php
Normal file
3
lib/InvalidCollectionException.php
Normal file
|
@ -0,0 +1,3 @@
|
|||
<?
|
||||
class InvalidCollectionException extends \Exception{
|
||||
}
|
|
@ -163,16 +163,16 @@ class Library{
|
|||
|
||||
// Create the collections cache
|
||||
foreach($ebook->Collections as $collection){
|
||||
$lcCollection = strtolower(Formatter::RemoveDiacritics($collection->Name));
|
||||
if(!array_key_exists($lcCollection, $collections)){
|
||||
$collections[$lcCollection] = [];
|
||||
$urlSafeCollection = Formatter::MakeUrlSafe($collection->Name);
|
||||
if(!array_key_exists($urlSafeCollection, $collections)){
|
||||
$collections[$urlSafeCollection] = [];
|
||||
}
|
||||
|
||||
if($collection->SequenceNumber !== null){
|
||||
$collections[$lcCollection][$collection->SequenceNumber] = $ebook;
|
||||
$collections[$urlSafeCollection][$collection->SequenceNumber] = $ebook;
|
||||
}
|
||||
else{
|
||||
$collections[$lcCollection][] = $ebook;
|
||||
$collections[$urlSafeCollection][] = $ebook;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,21 +40,26 @@ try{
|
|||
$ebooks = array_slice($ebooks, ($page - 1) * EBOOKS_PER_PAGE, EBOOKS_PER_PAGE);
|
||||
}
|
||||
elseif($collection !== null){
|
||||
$collection = strtolower(str_replace('-', ' ', Formatter::RemoveDiacritics($collection)));
|
||||
$ebooks = Library::GetEbooksByCollection($collection);
|
||||
|
||||
$collectionObject = null;
|
||||
// Get the *actual* name of the collection, in case there are accent marks (like "Arsène Lupin")
|
||||
if(sizeof($ebooks) > 0){
|
||||
// Get the *actual* name of the collection, in case there are accent marks (like "Arsène Lupin")
|
||||
foreach($ebooks[0]->Collections as $c){
|
||||
if($collection == strtolower(str_replace('-', ' ', Formatter::RemoveDiacritics($c->Name)))){
|
||||
$collection = (string)$c->Name; // Explicit typecast to string to satisfy PHPStan
|
||||
if($collection == Formatter::MakeUrlSafe($c->Name)){
|
||||
$collectionObject = $c;
|
||||
}
|
||||
}
|
||||
}
|
||||
$collectionName = ucwords(preg_replace('/^The /ius', '', $collection) ?? '');
|
||||
$pageTitle = 'Browse ebooks in the ' . Formatter::ToPlainText($collectionName) . ' collection';
|
||||
$pageDescription = 'A list of ebooks in the ' . Formatter::ToPlainText($collectionName) . ' collection';
|
||||
$pageHeader = 'Ebooks in the ' . Formatter::ToPlainText($collectionName) . ' collection';
|
||||
if($collectionObject !== null){
|
||||
$collectionName = preg_replace('/^The /ius', '', $collectionObject->Name) ?? '';
|
||||
$collectionType = $collectionObject->Type ?? 'collection';
|
||||
$pageTitle = 'Browse ebooks in the ' . Formatter::ToPlainText($collectionName) . ' ' . $collectionType;
|
||||
$pageDescription = 'A list of ebooks in the ' . Formatter::ToPlainText($collectionName) . ' ' . $collectionType;
|
||||
$pageHeader = 'Ebooks in the ' . Formatter::ToPlainText($collectionName) . ' ' . $collectionType;
|
||||
}
|
||||
else{
|
||||
throw new InvalidCollectionException();
|
||||
}
|
||||
}
|
||||
else{
|
||||
$pageTitle = 'Browse Standard Ebooks';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue