Add placeholders for public domain day ebooks

This commit is contained in:
Alex Cabal 2024-11-04 14:42:47 -06:00
parent 60f0ea16cb
commit 163ada3b09
7 changed files with 163 additions and 9 deletions

View file

@ -102,3 +102,22 @@ const DONATION_DRIVE_DATES = [
const DONATION_DRIVE_COUNTER_ENABLED = false; const DONATION_DRIVE_COUNTER_ENABLED = false;
const DONATION_DRIVE_COUNTER_START = new DateTimeImmutable('May 2, 2022 00:00:00 America/New_York'); const DONATION_DRIVE_COUNTER_START = new DateTimeImmutable('May 2, 2022 00:00:00 America/New_York');
const DONATION_DRIVE_COUNTER_END = new DateTimeImmutable('May 8, 2022 23:59:00 America/New_York'); const DONATION_DRIVE_COUNTER_END = new DateTimeImmutable('May 8, 2022 23:59:00 America/New_York');
const PD_DAY_YEAR = 2025;
const PD_DAY_DRAFT_PATH = '/standardebooks.org/drafts/' . PD_DAY_YEAR;
const PD_DAY_EBOOKS = [
'graham-greene/the-man-within' => ['author' => 'Graham Greene', 'title' => 'The Man Within'],
'c-s-forester/brown-on-resolution' => ['author' => 'C. S. Forester', 'title' => 'Brown on Resolution'],
'dashiell-hammett/red-harvest' => ['author' => 'Dashiell Hammett', 'title' => 'Red Harvest'],
'dashiell-hammett/the-dain-curse' => ['author' => 'Dashiell Hammett', 'title' => 'The Dain Curse'],
'erich-maria-remarque/all-quiet-on-the-western-front/a-w-wheen' => ['author' => 'Erich Maria Remarque', 'title' => 'All Quiet on the Western Front', 'translator' => 'A. W. Wheen'],
'ernest-hemingway/a-farewell-to-arms' => ['author' => 'Ernest Heminway', 'title' => 'A Farewell to Arms'],
'j-b-priestley/the-good-companions' => ['author' => 'J. B. Priestley', 'title' => 'The Good Companions'],
'john-steinbeck/cup-of-gold' => ['author' => 'John Steinbeck', 'title' => 'Cup of Gold'],
'oliver-la-farge/laughing-boy' => ['author' => 'Oliver La Farge', 'title' => 'Laughing Boy'],
'william-faulkner/the-sound-and-the-fury' => ['author' => 'William Faulkner', 'title' => 'The Sound and the Fury'],
'mahatma-gandhi/the-story-of-my-experiments-with-truth/mahadev-desai' => ['author' => 'Mahatma Gandhi', 'title' => 'The Story of My Experiments with Truth'],
'arthur-conan-doyle/the-maracot-deep' => ['author' => 'Arthur Conan Doyle', 'title' => 'The Maracot Deep'],
'sinclair-lewis/dodsworth' => ['author' => 'Sinclair Lewis', 'title' => 'Dodsworth'],
'thomas-wolfe/look-homeard-angel' => ['author' => 'Thomas Wolfe', 'title' => 'Look Homeward, Angel']
];

View file

@ -606,8 +606,13 @@ class Ebook{
$ebookFromFilesystem = new Ebook(); $ebookFromFilesystem = new Ebook();
// First, construct a source repo path from our WWW filesystem path. // First, construct a source repo path from our WWW filesystem path.
$ebookFromFilesystem->RepoFilesystemPath = str_replace(EBOOKS_DIST_PATH, '', $wwwFilesystemPath); if(str_starts_with($wwwFilesystemPath, '/')){
$ebookFromFilesystem->RepoFilesystemPath = SITE_ROOT . '/ebooks/' . str_replace('/', '_', $ebookFromFilesystem->RepoFilesystemPath) . '.git'; $ebookFromFilesystem->RepoFilesystemPath = $wwwFilesystemPath;
}
else{
$ebookFromFilesystem->RepoFilesystemPath = str_replace(EBOOKS_DIST_PATH, '', $wwwFilesystemPath);
$ebookFromFilesystem->RepoFilesystemPath = SITE_ROOT . '/ebooks/' . str_replace('/', '_', $ebookFromFilesystem->RepoFilesystemPath) . '.git';
}
if(!is_dir($ebookFromFilesystem->RepoFilesystemPath)){ // On dev systems we might not have the bare repos, so make an adjustment. if(!is_dir($ebookFromFilesystem->RepoFilesystemPath)){ // On dev systems we might not have the bare repos, so make an adjustment.
try{ try{
@ -643,8 +648,7 @@ class Ebook{
$ebookFromFilesystem->Identifier = (string)$matches[1]; $ebookFromFilesystem->Identifier = (string)$matches[1];
try{ try{
// PHP Safe throws an exception from filesize() if the file doesn't exist, but PHP still // PHP Safe throws an exception from filesize() if the file doesn't exist, but PHP still emits a warning. So, just silence the warning.
// emits a warning. So, just silence the warning.
$ebookFromFilesystem->TextSinglePageByteCount = @filesize($ebookFromFilesystem->WwwFilesystemPath . '/text/single-page.xhtml'); $ebookFromFilesystem->TextSinglePageByteCount = @filesize($ebookFromFilesystem->WwwFilesystemPath . '/text/single-page.xhtml');
} }
catch(\Exception){ catch(\Exception){
@ -687,13 +691,18 @@ class Ebook{
} }
// Fill in the short history of this repo. // Fill in the short history of this repo.
$historyEntries = explode("\n", shell_exec('cd ' . escapeshellarg($ebookFromFilesystem->RepoFilesystemPath) . ' && git log -n5 --pretty=format:"%ct %H %s"')); try{
$historyEntries = explode("\n", shell_exec('cd ' . escapeshellarg($ebookFromFilesystem->RepoFilesystemPath) . ' && git log -n5 --pretty=format:"%ct %H %s"'));
$gitCommits = []; $gitCommits = [];
foreach($historyEntries as $logLine){ foreach($historyEntries as $logLine){
$gitCommits[] = GitCommit::FromLogLine($logLine); $gitCommits[] = GitCommit::FromLogLine($logLine);
}
$ebookFromFilesystem->GitCommits = $gitCommits;
}
catch(\Safe\Exceptions\ExecException){
// Pass.
} }
$ebookFromFilesystem->GitCommits = $gitCommits;
// Now do some heavy XML lifting! // Now do some heavy XML lifting!
try{ try{

View file

@ -2936,6 +2936,11 @@ aside button.close:active{
transition: transform .5s; transition: transform .5s;
} }
article.ebook.public-domain-day-placeholder #read-free p{
text-align: center;
font-style: italic;
}
article.ebook section#read-online ul li p.has-size{ article.ebook section#read-online ul li p.has-size{
display: flex; display: flex;
} }

View file

@ -39,6 +39,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.
@ -75,6 +76,12 @@ catch(Exceptions\SeeOtherEbookException $ex){
exit(); exit();
} }
catch(Exceptions\EbookNotFoundException){ catch(Exceptions\EbookNotFoundException){
// Are we accessing a placeholder for a Public Domain Day book that is not yet released?
if(array_key_exists($urlPath, PD_DAY_EBOOKS)){
require('/standardebooks.org/web/www/ebooks/public-domain-day-placeholder.php');
exit();
}
Template::Emit404(); Template::Emit404();
} }
?><?= Template::Header(['title' => strip_tags($ebook->TitleWithCreditsHtml) . ' - Free ebook download', 'ogType' => 'book', 'coverUrl' => $ebook->DistCoverUrl, 'highlight' => 'ebooks', 'description' => 'Free epub ebook download of the Standard Ebooks edition of ' . $ebook->Title . ': ' . $ebook->Description, 'canonicalUrl' => SITE_URL . $ebook->Url]) ?> ?><?= Template::Header(['title' => strip_tags($ebook->TitleWithCreditsHtml) . ' - Free ebook download', 'ogType' => 'book', 'coverUrl' => $ebook->DistCoverUrl, 'highlight' => 'ebooks', 'description' => 'Free epub ebook download of the Standard Ebooks edition of ' . $ebook->Title . ': ' . $ebook->Description, 'canonicalUrl' => SITE_URL . $ebook->Url]) ?>

View file

@ -0,0 +1,114 @@
<?
use function Safe\preg_replace;
/** @var string $urlPath Passed from script this is included from. */
$ebook = null;
try{
try{
// Attempt to read a draft ebook repo from the filesystem.
$ebook = Ebook::FromFilesystem(PD_DAY_DRAFT_PATH . '/' . str_replace('/', '_', $urlPath) . '/src/epub');
}
catch(Exceptions\EbookNotFoundException $ex){
// We may have ebooks listed as in progress, but no actual draft repos yet.
// In that case, fill in the details from PD_DAY_EBOOKS.
if(array_key_exists($urlPath, PD_DAY_EBOOKS)){
$ebook = new Ebook();
$c = new Contributor();
$c->Name = PD_DAY_EBOOKS[$urlPath]['author'];
$ebook->Authors = [$c];
if(isset(PD_DAY_EBOOKS[$urlPath]['translator'])){
$c = new Contributor();
$c->Name = PD_DAY_EBOOKS[$urlPath]['translator'];
$ebook->Translators = [$c];
}
$ebook->Title = PD_DAY_EBOOKS[$urlPath]['title'];
$ebook->WwwFilesystemPath = '';
$ebook->Identifier = '';
}
else{
throw $ex;
}
}
}
catch(Exceptions\EbookNotFoundException){
Template::Emit404();
}
?><?= Template::Header(['title' => strip_tags($ebook->TitleWithCreditsHtml) . ' - Free ebook download', 'highlight' => 'ebooks', 'description' => 'Free epub ebook download of the Standard Ebooks edition of ' . $ebook->Title . ': ' . $ebook->Description, 'canonicalUrl' => SITE_URL . $ebook->Url]) ?>
<main>
<article class="ebook public-domain-day-placeholder">
<header>
<hgroup>
<h1><?= Formatter::EscapeHtml($ebook->Title) ?></h1>
<? foreach($ebook->Authors as $author){ ?>
<? /* We include the `resource` attr here because we can have multiple authors, and in that case their href URLs will link to their combined corpus.
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` */ ?>
<? if($author->Name != 'Anonymous'){ ?>
<h2>
<a href="<?= Formatter::EscapeHtml($ebook->AuthorsUrl) ?>"><?= Formatter::EscapeHtml($author->Name) ?></a>
</h2>
<? } ?>
<? } ?>
</hgroup>
<picture>
<source srcset="/images/public-domain-day-placeholder-cover-hero@2x.jpg 2x, /images/public-domain-day-placeholder-cover-hero.jpg 1x" type="image/jpg"/>
<img src="/images/public-domain-day-placeholder-cover-hero@2x.jpg" alt="" height="439" width="1318" />
</picture>
</header>
<? if(sizeof($ebook->Tags) > 0){ ?>
<aside id="reading-ease">
<? if($ebook->ContributorsHtml !== null){ ?>
<p><?= $ebook->ContributorsHtml ?></p>
<? } ?>
<? if(sizeof($ebook->CollectionMemberships) > 0){ ?>
<? foreach($ebook->CollectionMemberships as $collectionMembership){ ?>
<? $collection = $collectionMembership->Collection; ?>
<? $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>
<? if($collection->Type !== null){ ?>
<? if(substr_compare(mb_strtolower($collection->Name), mb_strtolower($collection->Type->value), -strlen(mb_strtolower($collection->Type->value))) !== 0){ ?>
<?= $collection->Type->value ?>.
<? } ?>
<? }else{ ?>
collection.
<? } ?>
</p>
<? } ?>
<? } ?>
<ul class="tags">
<? foreach($ebook->Tags as $tag){ ?>
<li>
<a href="<?= $tag->Url ?>"><?= Formatter::EscapeHtml($tag->Name) ?></a>
</li>
<? } ?>
</ul>
</aside>
<? } ?>
<section id="description">
<h2>Description</h2>
<?= Template::DonationCounter() ?>
<?= Template::DonationProgress() ?>
<?= Template::DonationAlert() ?>
<? if($ebook->LongDescription !== null){ ?>
<?= $ebook->LongDescription ?>
<? } ?>
</section>
<section id="read-free">
<?= $ebook->GenerateContributorsRdfa() ?>
<h2>Read free</h2>
<p>This book will enter the public domain in the U.S. on <b>January 1, <?= PD_DAY_YEAR ?></b>.</p>
<p>Weve been working hard, and have this ebook prepared and ready for you to download free on January 1. Bookmark this page and come back then to read this ebook for free!</p>
</section>
</article>
</main>
<?= Template::Footer() ?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 KiB