Update ebooks to explode the ./src/epub folder into ebook endpoints, instead of just exploding the whole epub

This commit is contained in:
Alex Cabal 2020-10-13 14:28:32 -05:00
parent d9ac7312c2
commit 73ba658a05
7 changed files with 20 additions and 19 deletions

View file

@ -165,11 +165,7 @@ Define domain standardebooks.org
RewriteRule ^/(.+?)/$ /$1 [R=301,L] RewriteRule ^/(.+?)/$ /$1 [R=301,L]
# Redirect ToC of XHTML representation of books # Redirect ToC of XHTML representation of books
RewriteRule ^/ebooks/(.+?)/text$ /ebooks/$1/src/epub/toc.xhtml [L] RewriteRule ^/ebooks/(.+?)/text$ /ebooks/$1/toc.xhtml [L]
# Redirect XHTML representation of books
# This has to appear before the next check, so that we can exclude .xhtml endings
RewriteRule ^/ebooks/(.+?)/(text|css|images|fonts)(.*) /ebooks/$1/src/epub/$2$3
# Received: /filename and /filename.xhtml exists in filesystem; Result: rewrite to /filename.xhtml # Received: /filename and /filename.xhtml exists in filesystem; Result: rewrite to /filename.xhtml
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.xhtml -f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.xhtml -f
@ -228,7 +224,7 @@ Define domain standardebooks.org
# Prevent this rule from firing if we're getting a distribution file # Prevent this rule from firing if we're getting a distribution file
RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/downloads/.+$ RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/downloads/.+$
RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/src/.+$ RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/text.*$
RewriteRule ^/ebooks/([^\.]+?)$ /ebooks/ebook.php?url-path=$1 RewriteRule ^/ebooks/([^\.]+?)$ /ebooks/ebook.php?url-path=$1
# If we ask for /opds/all?query=xyz, rewrite that to the search page. # If we ask for /opds/all?query=xyz, rewrite that to the search page.

View file

@ -164,11 +164,7 @@ Define domain standardebooks.test
RewriteRule ^/(.+?)/$ /$1 [R=301,L] RewriteRule ^/(.+?)/$ /$1 [R=301,L]
# Redirect ToC of XHTML representation of books # Redirect ToC of XHTML representation of books
RewriteRule ^/ebooks/(.+?)/text$ /ebooks/$1/src/epub/toc.xhtml [L] RewriteRule ^/ebooks/(.+?)/text$ /ebooks/$1/toc.xhtml [L]
# Redirect XHTML representation of books
# This has to appear before the next check, so that we can exclude .xhtml endings
RewriteRule ^/ebooks/(.+?)/(text|css|images|fonts)(.*) /ebooks/$1/src/epub/$2$3
# Received: /filename and /filename.xhtml exists in filesystem; Result: rewrite to /filename.xhtml # Received: /filename and /filename.xhtml exists in filesystem; Result: rewrite to /filename.xhtml
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.xhtml -f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.xhtml -f
@ -227,7 +223,7 @@ Define domain standardebooks.test
# Prevent this rule from firing if we're getting a distribution file # Prevent this rule from firing if we're getting a distribution file
RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/downloads/.+$ RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/downloads/.+$
RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/src/.+$ RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/text.*$
RewriteRule ^/ebooks/([^\.]+?)$ /ebooks/ebook.php?url-path=$1 RewriteRule ^/ebooks/([^\.]+?)$ /ebooks/ebook.php?url-path=$1
# If we ask for /opds/all?query=xyz, rewrite that to the search page. # If we ask for /opds/all?query=xyz, rewrite that to the search page.

View file

@ -75,14 +75,14 @@ class Ebook{
throw new InvalidEbookException('Invalid repo filesystem path: ' . $this->RepoFilesystemPath); throw new InvalidEbookException('Invalid repo filesystem path: ' . $this->RepoFilesystemPath);
} }
if(!is_file($wwwFilesystemPath . '/src/epub/content.opf')){ if(!is_file($wwwFilesystemPath . '/content.opf')){
throw new InvalidEbookException('Invalid content.opf file: ' . $wwwFilesystemPath . '/src/epub/content.opf'); throw new InvalidEbookException('Invalid content.opf file: ' . $wwwFilesystemPath . '/content.opf');
} }
$this->WwwFilesystemPath = $wwwFilesystemPath; $this->WwwFilesystemPath = $wwwFilesystemPath;
$this->Url = str_replace(WEB_ROOT, '', $this->WwwFilesystemPath); $this->Url = str_replace(WEB_ROOT, '', $this->WwwFilesystemPath);
$rawMetadata = file_get_contents($wwwFilesystemPath . '/src/epub/content.opf') ?: ''; $rawMetadata = file_get_contents($wwwFilesystemPath . '/content.opf') ?: '';
// Get the SE identifier. // Get the SE identifier.
preg_match('|<dc:identifier[^>]*?>(.+?)</dc:identifier>|ius', $rawMetadata, $matches); preg_match('|<dc:identifier[^>]*?>(.+?)</dc:identifier>|ius', $rawMetadata, $matches);
@ -95,7 +95,7 @@ class Ebook{
$this->TextUrl = $this->Url . '/text'; $this->TextUrl = $this->Url . '/text';
$tempPath = glob($this->WwwFilesystemPath . '/src/epub/text/single-page.xhtml'); $tempPath = glob($this->WwwFilesystemPath . '/text/single-page.xhtml');
if(sizeof($tempPath) > 0){ if(sizeof($tempPath) > 0){
$this->TextSinglePageUrl = $this->Url . '/text/single-page'; $this->TextSinglePageUrl = $this->Url . '/text/single-page';
} }

View file

@ -156,7 +156,7 @@ class Library{
foreach(explode("\n", trim(shell_exec('find ' . EBOOKS_DIST_PATH . ' -name "content.opf"') ?? '')) as $filename){ foreach(explode("\n", trim(shell_exec('find ' . EBOOKS_DIST_PATH . ' -name "content.opf"') ?? '')) as $filename){
try{ try{
$ebookWwwFilesystemPath = preg_replace('|/src/.+|ius', '', $filename) ?? ''; $ebookWwwFilesystemPath = preg_replace('|/content\.opf|ius', '', $filename) ?? '';
$ebook = new Ebook($ebookWwwFilesystemPath); $ebook = new Ebook($ebookWwwFilesystemPath);

View file

@ -306,6 +306,9 @@ do
mv "${workDir}"/single-page.xhtml "${workDir}"/src/epub/text/single-page.xhtml mv "${workDir}"/single-page.xhtml "${workDir}"/src/epub/text/single-page.xhtml
fi fi
# Add viewport meta elements to all output
find "${workDir}" \( -type d -name .git -prune \) -o -type f -name "*.xhtml" -print0 | xargs -0 sed --in-place "s|</title>|</title>\n\t\t<meta content=\"width=device-width, initial-scale=1\" name=\"viewport\"/>|"
# Delete the contents of the old webdir # Delete the contents of the old webdir
rm --preserve-root --recursive --force "${webDir}" rm --preserve-root --recursive --force "${webDir}"
@ -313,7 +316,9 @@ do
mkdir -p "${webDir}" mkdir -p "${webDir}"
# Move contents of the work dir over # Move contents of the work dir over
mv "${workDir}"/* "${webDir}/" mv "${workDir}"/downloads "${webDir}/"
rm "${workDir}/src/epub/onix.xml"
mv "${workDir}"/src/epub/* "${webDir}/"
fi fi
if [ "${images}" = "true" ]; then if [ "${images}" = "true" ]; then

View file

@ -22,7 +22,7 @@ foreach($contentFiles as $path){
if($path == '') if($path == '')
continue; continue;
$ebookWwwFilesystemPath = preg_replace('|/src/.+|ius', '', $path) ?? ''; $ebookWwwFilesystemPath = preg_replace('|/content\.opf|ius', '', $path) ?? '';
$ebook = new Ebook($ebookWwwFilesystemPath); $ebook = new Ebook($ebookWwwFilesystemPath);
$allEbooks[$ebook->ModifiedTimestamp->format('Y-m-d\TH:i:s\Z') . ' ' . $ebook->Identifier] = $ebook; $allEbooks[$ebook->ModifiedTimestamp->format('Y-m-d\TH:i:s\Z') . ' ' . $ebook->Identifier] = $ebook;

View file

@ -139,13 +139,17 @@ catch(\Exception $ex){
<aside> <aside>
<p>Read about <a href="/help/how-to-use-our-ebooks#which-file-to-download">which file to download</a> and <a href="/help/how-to-use-our-ebooks#transferring-to-your-ereader">how to transfer them to your ereader</a>.</p> <p>Read about <a href="/help/how-to-use-our-ebooks#which-file-to-download">which file to download</a> and <a href="/help/how-to-use-our-ebooks#transferring-to-your-ereader">how to transfer them to your ereader</a>.</p>
</aside> </aside>
<? if($ebook->TextUrl !== null || $ebook->TextSinglePageUrl !== null){ ?>
<h3>Read online</h3> <h3>Read online</h3>
<ul> <ul>
<? if($ebook->TextUrl !== null){ ?>
<li><p><span><a href="<?= $ebook->TextUrl ?>" class="list">Start from the table of contents</a></span></p></li> <li><p><span><a href="<?= $ebook->TextUrl ?>" class="list">Start from the table of contents</a></span></p></li>
<? } ?>
<? if($ebook->TextSinglePageUrl !== null){ ?> <? if($ebook->TextSinglePageUrl !== null){ ?>
<li><p><span><a href="<?= $ebook->TextSinglePageUrl ?>" class="page">Read on one page</a></span></p></li> <li><p><span><a href="<?= $ebook->TextSinglePageUrl ?>" class="page">Read on one page</a></span></p></li>
<? } ?> <? } ?>
</ul> </ul>
<? } ?>
</section> </section>
<? } ?> <? } ?>