mirror of
https://github.com/standardebooks/web.git
synced 2025-07-10 00:30:28 -04:00
Formatting tweaks
This commit is contained in:
parent
0138b19000
commit
60f0ea16cb
1 changed files with 65 additions and 50 deletions
|
@ -1,5 +1,5 @@
|
||||||
<?
|
<?
|
||||||
// See https://developers.google.com/search/docs/data-types/book for RDFa metadata details
|
// See <https://developers.google.com/search/docs/data-types/book> for RDFa metadata details.
|
||||||
|
|
||||||
use Safe\DateTimeImmutable;
|
use Safe\DateTimeImmutable;
|
||||||
use function Safe\preg_match;
|
use function Safe\preg_match;
|
||||||
|
@ -15,24 +15,23 @@ $carouselTag = null;
|
||||||
$targetCarouselSize = 5;
|
$targetCarouselSize = 5;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$urlPath = trim(str_replace('.', '', HttpInput::Str(GET, 'url-path') ?? ''), '/'); // Contains the portion of the URL (without query string) that comes after https://standardebooks.org/ebooks/
|
$urlPath = trim(str_replace('.', '', HttpInput::Str(GET, 'url-path') ?? ''), '/'); // Contains the portion of the URL (without query string) that comes after `https://standardebooks.org/ebooks/`.
|
||||||
$wwwFilesystemPath = EBOOKS_DIST_PATH . $urlPath; // Path to the deployed WWW files for this ebook
|
$wwwFilesystemPath = EBOOKS_DIST_PATH . $urlPath; // Path to the deployed WWW files for this ebook.
|
||||||
|
|
||||||
if($urlPath == '' || mb_stripos($wwwFilesystemPath, EBOOKS_DIST_PATH) !== 0){
|
if($urlPath == '' || mb_stripos($wwwFilesystemPath, EBOOKS_DIST_PATH) !== 0){
|
||||||
// Ensure the path exists and that the root is in our www directory
|
// Ensure the path exists and that the root is in our www directory.
|
||||||
throw new Exceptions\EbookNotFoundException();
|
throw new Exceptions\EbookNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Were we passed the author and a work but not the translator?
|
// Were we passed the author and a work but not the translator?
|
||||||
// For example:
|
// For example: <https://standardebooks.org/ebooks/omar-khayyam/the-rubaiyat-of-omar-khayyam>
|
||||||
// https://standardebooks.org/ebooks/omar-khayyam/the-rubaiyat-of-omar-khayyam
|
// Instead of: <https://standardebooks.org/ebooks/omar-khayyam/the-rubaiyat-of-omar-khayyam/edward-fitzgerald/edmund-dulac>.
|
||||||
// Instead of:
|
// We can tell because if so, the dir we are passed will exist, but there will be no `src` folder.
|
||||||
// https://standardebooks.org/ebooks/omar-khayyam/the-rubaiyat-of-omar-khayyam/edward-fitzgerald/edmund-dulac
|
|
||||||
// We can tell because if so, the dir we are passed will exist, but there will be no 'src' folder.
|
|
||||||
if(is_dir($wwwFilesystemPath) && !is_dir($wwwFilesystemPath . '/src')){
|
if(is_dir($wwwFilesystemPath) && !is_dir($wwwFilesystemPath . '/src')){
|
||||||
/** @var DirectoryIterator $file */
|
/** @var DirectoryIterator $file */
|
||||||
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($wwwFilesystemPath)) as $file){
|
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($wwwFilesystemPath)) as $file){
|
||||||
// This iterator will do a deep scan on the directory. When we hit another directory, the filename will be "." and the path will contain the directory path.
|
// This iterator will do a deep scan on the directory. When we hit another directory, the filename will be `.` and the path will contain the directory path.
|
||||||
// We want to find where the "src" directory is, and the directory directly below that will be the final web URL we're looking for.
|
// We want to find where the `src` directory is, and the directory directly below that will be the final web URL we're looking for.
|
||||||
if($file->getFilename() == '.' && preg_match('|/src$|ius', $file->getPath())){
|
if($file->getFilename() == '.' && preg_match('|/src$|ius', $file->getPath())){
|
||||||
throw new Exceptions\SeeOtherEbookException(preg_replace(['|' . WEB_ROOT . '|ius', '|/src$|ius'], '', $file->getPath()));
|
throw new Exceptions\SeeOtherEbookException(preg_replace(['|' . WEB_ROOT . '|ius', '|/src$|ius'], '', $file->getPath()));
|
||||||
}
|
}
|
||||||
|
@ -42,7 +41,7 @@ try{
|
||||||
$identifier = EBOOKS_IDENTIFIER_PREFIX . $urlPath;
|
$identifier = EBOOKS_IDENTIFIER_PREFIX . $urlPath;
|
||||||
$ebook = Ebook::GetByIdentifier($identifier);
|
$ebook = Ebook::GetByIdentifier($identifier);
|
||||||
|
|
||||||
// Divide our sources into transcriptions and scans
|
// Divide our sources into transcriptions and scans.
|
||||||
foreach($ebook->Sources as $source){
|
foreach($ebook->Sources as $source){
|
||||||
switch($source->Type){
|
switch($source->Type){
|
||||||
case EbookSourceType::ProjectGutenberg:
|
case EbookSourceType::ProjectGutenberg:
|
||||||
|
@ -94,15 +93,16 @@ catch(Exceptions\EbookNotFoundException){
|
||||||
For example, William Wordsworth & Samuel Coleridge will both link to /ebooks/william-wordsworth_samuel-taylor-coleridge
|
For example, William Wordsworth & Samuel Coleridge will both link to /ebooks/william-wordsworth_samuel-taylor-coleridge
|
||||||
But, each author is an individual, so we have to differentiate them in RDFa with `resource` */ ?>
|
But, each author is an individual, so we have to differentiate them in RDFa with `resource` */ ?>
|
||||||
<? if($author->Name != 'Anonymous'){ ?>
|
<? if($author->Name != 'Anonymous'){ ?>
|
||||||
<h2><a property="schema:author" typeof="schema:Person" href="<?= Formatter::EscapeHtml($ebook->AuthorsUrl) ?>" resource="<?= '/ebooks/' . $author->UrlName ?>">
|
<h2>
|
||||||
<span property="schema:name"><?= Formatter::EscapeHtml($author->Name) ?></span>
|
<a property="schema:author" typeof="schema:Person" href="<?= Formatter::EscapeHtml($ebook->AuthorsUrl) ?>" resource="<?= '/ebooks/' . $author->UrlName ?>">
|
||||||
<meta property="schema:url" content="<?= SITE_URL . Formatter::EscapeHtml($ebook->AuthorsUrl) ?>"/>
|
<span property="schema:name"><?= Formatter::EscapeHtml($author->Name) ?></span>
|
||||||
<? if($author->NacoafUrl){ ?>
|
<meta property="schema:url" content="<?= SITE_URL . Formatter::EscapeHtml($ebook->AuthorsUrl) ?>"/>
|
||||||
<meta property="schema:sameAs" content="<?= Formatter::EscapeHtml($author->NacoafUrl) ?>"/>
|
<? if($author->NacoafUrl){ ?>
|
||||||
<? } ?>
|
<meta property="schema:sameAs" content="<?= Formatter::EscapeHtml($author->NacoafUrl) ?>"/>
|
||||||
<? if($author->WikipediaUrl){ ?>
|
<? } ?>
|
||||||
<meta property="schema:sameAs" content="<?= Formatter::EscapeHtml($author->WikipediaUrl) ?>"/>
|
<? if($author->WikipediaUrl){ ?>
|
||||||
<? } ?>
|
<meta property="schema:sameAs" content="<?= Formatter::EscapeHtml($author->WikipediaUrl) ?>"/>
|
||||||
|
<? } ?>
|
||||||
</a>
|
</a>
|
||||||
</h2>
|
</h2>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
|
@ -127,18 +127,25 @@ catch(Exceptions\EbookNotFoundException){
|
||||||
<? foreach($ebook->CollectionMemberships as $collectionMembership){ ?>
|
<? foreach($ebook->CollectionMemberships as $collectionMembership){ ?>
|
||||||
<? $collection = $collectionMembership->Collection; ?>
|
<? $collection = $collectionMembership->Collection; ?>
|
||||||
<? $sequenceNumber = $collectionMembership->SequenceNumber; ?>
|
<? $sequenceNumber = $collectionMembership->SequenceNumber; ?>
|
||||||
<p><? if($sequenceNumber !== null){ ?>№ <?= number_format($sequenceNumber) ?> in the<? }else{ ?>Part of the<? } ?> <a href="<?= $collection->Url ?>" property="schema:isPartOf"><?= Formatter::EscapeHtml(preg_replace('/^The /ius', '', (string)$collection->Name)) ?></a>
|
<p>
|
||||||
<? if($collection->Type !== null){ ?>
|
<? if($sequenceNumber !== null){ ?>№ <?= number_format($sequenceNumber) ?> in the<? }else{ ?>Part of the<? } ?> <a href="<?= $collection->Url ?>" property="schema:isPartOf"><?= Formatter::EscapeHtml(preg_replace('/^The /ius', '', (string)$collection->Name)) ?></a>
|
||||||
<? if(substr_compare(mb_strtolower($collection->Name), mb_strtolower($collection->Type->value), -strlen(mb_strtolower($collection->Type->value))) !== 0){ ?>
|
<? if($collection->Type !== null){ ?>
|
||||||
<?= $collection->Type->value ?>.
|
<? if(substr_compare(mb_strtolower($collection->Name), mb_strtolower($collection->Type->value), -strlen(mb_strtolower($collection->Type->value))) !== 0){ ?>
|
||||||
|
<?= $collection->Type->value ?>.
|
||||||
|
<? } ?>
|
||||||
|
<? }else{ ?>
|
||||||
|
collection.
|
||||||
<? } ?>
|
<? } ?>
|
||||||
<? }else{ ?>
|
|
||||||
collection.
|
|
||||||
<? } ?>
|
|
||||||
</p>
|
</p>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
<ul class="tags"><? foreach($ebook->Tags as $tag){ ?><li><a href="<?= $tag->Url ?>"><?= Formatter::EscapeHtml($tag->Name) ?></a></li><? } ?></ul>
|
<ul class="tags">
|
||||||
|
<? foreach($ebook->Tags as $tag){ ?>
|
||||||
|
<li>
|
||||||
|
<a href="<?= $tag->Url ?>"><?= Formatter::EscapeHtml($tag->Name) ?></a>
|
||||||
|
</li>
|
||||||
|
<? } ?>
|
||||||
|
</ul>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<section id="description">
|
<section id="description">
|
||||||
|
@ -149,7 +156,9 @@ catch(Exceptions\EbookNotFoundException){
|
||||||
<?= Template::DonationAlert() ?>
|
<?= Template::DonationAlert() ?>
|
||||||
|
|
||||||
<? if($ebook->LongDescription === null){ ?>
|
<? if($ebook->LongDescription === null){ ?>
|
||||||
<p><i>There’s no description for this ebook yet.</i></p>
|
<p>
|
||||||
|
<i>There’s no description for this ebook yet.</i>
|
||||||
|
</p>
|
||||||
<? }else{ ?>
|
<? }else{ ?>
|
||||||
<?= $ebook->LongDescription ?>
|
<?= $ebook->LongDescription ?>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
|
@ -277,7 +286,9 @@ catch(Exceptions\EbookNotFoundException){
|
||||||
<? foreach($ebook->GitCommits as $commit){ ?>
|
<? foreach($ebook->GitCommits as $commit){ ?>
|
||||||
<li>
|
<li>
|
||||||
<time datetime="<?= $commit->Created->format(DateTimeImmutable::RFC3339) ?>"><?= $commit->Created->format('M j, Y') ?></time>
|
<time datetime="<?= $commit->Created->format(DateTimeImmutable::RFC3339) ?>"><?= $commit->Created->format('M j, Y') ?></time>
|
||||||
<p><a href="<?= Formatter::EscapeHtml($ebook->GitHubUrl) ?>/commit/<?= Formatter::EscapeHtml($commit->Hash) ?>"><?= Formatter::EscapeHtml($commit->Message) ?></a></p>
|
<p>
|
||||||
|
<a href="<?= Formatter::EscapeHtml($ebook->GitHubUrl) ?>/commit/<?= Formatter::EscapeHtml($commit->Hash) ?>"><?= Formatter::EscapeHtml($commit->Message) ?></a>
|
||||||
|
</p>
|
||||||
</li>
|
</li>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
</ol>
|
</ol>
|
||||||
|
@ -294,12 +305,16 @@ catch(Exceptions\EbookNotFoundException){
|
||||||
<ul>
|
<ul>
|
||||||
<? if($ebook->GitHubUrl !== null){ ?>
|
<? if($ebook->GitHubUrl !== null){ ?>
|
||||||
<li>
|
<li>
|
||||||
<p><a href="<?= Formatter::EscapeHtml($ebook->GitHubUrl) ?>" class="github">This ebook’s source code at GitHub</a></p>
|
<p>
|
||||||
|
<a href="<?= Formatter::EscapeHtml($ebook->GitHubUrl) ?>" class="github">This ebook’s source code at GitHub</a>
|
||||||
|
</p>
|
||||||
</li>
|
</li>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
<? if($ebook->WikipediaUrl !== null){ ?>
|
<? if($ebook->WikipediaUrl !== null){ ?>
|
||||||
<li>
|
<li>
|
||||||
<p><a href="<?= Formatter::EscapeHtml($ebook->WikipediaUrl) ?>" class="wikipedia">This book at Wikipedia</a></p>
|
<p>
|
||||||
|
<a href="<?= Formatter::EscapeHtml($ebook->WikipediaUrl) ?>" class="wikipedia">This book at Wikipedia</a>
|
||||||
|
</p>
|
||||||
</li>
|
</li>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -314,23 +329,23 @@ catch(Exceptions\EbookNotFoundException){
|
||||||
<h3>Transcriptions</h3>
|
<h3>Transcriptions</h3>
|
||||||
<ul>
|
<ul>
|
||||||
<? foreach($transcriptionSources as $source){ ?>
|
<? foreach($transcriptionSources as $source){ ?>
|
||||||
<li>
|
<li>
|
||||||
<p>
|
<p>
|
||||||
<? if($source->Type == EbookSourceType::ProjectGutenberg){ ?>
|
<? if($source->Type == EbookSourceType::ProjectGutenberg){ ?>
|
||||||
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="project-gutenberg">Transcription at Project Gutenberg</a>
|
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="project-gutenberg">Transcription at Project Gutenberg</a>
|
||||||
<? }elseif($source->Type == EbookSourceType::ProjectGutenbergAustralia){ ?>
|
<? }elseif($source->Type == EbookSourceType::ProjectGutenbergAustralia){ ?>
|
||||||
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="project-gutenberg">Transcription at Project Gutenberg Australia</a>
|
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="project-gutenberg">Transcription at Project Gutenberg Australia</a>
|
||||||
<? }elseif($source->Type == EbookSourceType::ProjectGutenbergCanada){ ?>
|
<? }elseif($source->Type == EbookSourceType::ProjectGutenbergCanada){ ?>
|
||||||
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="project-gutenberg">Transcription at Project Gutenberg Canada</a>
|
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="project-gutenberg">Transcription at Project Gutenberg Canada</a>
|
||||||
<? }elseif($source->Type == EbookSourceType::Wikisource){ ?>
|
<? }elseif($source->Type == EbookSourceType::Wikisource){ ?>
|
||||||
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="wikisource">Transcription at Wikisource</a>
|
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="wikisource">Transcription at Wikisource</a>
|
||||||
<? }elseif($source->Type == EbookSourceType::FadedPage){ ?>
|
<? }elseif($source->Type == EbookSourceType::FadedPage){ ?>
|
||||||
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="globe">Transcription at Faded Page</a>
|
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="globe">Transcription at Faded Page</a>
|
||||||
<? }else{?>
|
<? }else{?>
|
||||||
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="globe">Transcription</a>
|
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="globe">Transcription</a>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</li>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue