From 73ba658a052ed3dd3f99d9a02cb96410cdcfd2db Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Tue, 13 Oct 2020 14:28:32 -0500 Subject: [PATCH] Update ebooks to explode the ./src/epub folder into ebook endpoints, instead of just exploding the whole epub --- config/apache/standardebooks.org.conf | 8 ++------ config/apache/standardebooks.test.conf | 8 ++------ lib/Ebook.php | 8 ++++---- lib/Library.php | 2 +- scripts/deploy-ebook-to-www | 7 ++++++- scripts/generate-opds.php | 2 +- www/ebooks/ebook.php | 4 ++++ 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/config/apache/standardebooks.org.conf b/config/apache/standardebooks.org.conf index d384779b..f9885203 100644 --- a/config/apache/standardebooks.org.conf +++ b/config/apache/standardebooks.org.conf @@ -165,11 +165,7 @@ Define domain standardebooks.org RewriteRule ^/(.+?)/$ /$1 [R=301,L] # Redirect ToC of XHTML representation of books - RewriteRule ^/ebooks/(.+?)/text$ /ebooks/$1/src/epub/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 + RewriteRule ^/ebooks/(.+?)/text$ /ebooks/$1/toc.xhtml [L] # Received: /filename and /filename.xhtml exists in filesystem; Result: rewrite to /filename.xhtml 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 RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/downloads/.+$ - RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/src/.+$ + RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/text.*$ RewriteRule ^/ebooks/([^\.]+?)$ /ebooks/ebook.php?url-path=$1 # If we ask for /opds/all?query=xyz, rewrite that to the search page. diff --git a/config/apache/standardebooks.test.conf b/config/apache/standardebooks.test.conf index 6dbd2692..ae4daa5d 100644 --- a/config/apache/standardebooks.test.conf +++ b/config/apache/standardebooks.test.conf @@ -164,11 +164,7 @@ Define domain standardebooks.test RewriteRule ^/(.+?)/$ /$1 [R=301,L] # Redirect ToC of XHTML representation of books - RewriteRule ^/ebooks/(.+?)/text$ /ebooks/$1/src/epub/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 + RewriteRule ^/ebooks/(.+?)/text$ /ebooks/$1/toc.xhtml [L] # Received: /filename and /filename.xhtml exists in filesystem; Result: rewrite to /filename.xhtml 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 RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/downloads/.+$ - RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/src/.+$ + RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/text.*$ RewriteRule ^/ebooks/([^\.]+?)$ /ebooks/ebook.php?url-path=$1 # If we ask for /opds/all?query=xyz, rewrite that to the search page. diff --git a/lib/Ebook.php b/lib/Ebook.php index fde517e8..01cc489f 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -75,14 +75,14 @@ class Ebook{ throw new InvalidEbookException('Invalid repo filesystem path: ' . $this->RepoFilesystemPath); } - if(!is_file($wwwFilesystemPath . '/src/epub/content.opf')){ - throw new InvalidEbookException('Invalid content.opf file: ' . $wwwFilesystemPath . '/src/epub/content.opf'); + if(!is_file($wwwFilesystemPath . '/content.opf')){ + throw new InvalidEbookException('Invalid content.opf file: ' . $wwwFilesystemPath . '/content.opf'); } $this->WwwFilesystemPath = $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. preg_match('|]*?>(.+?)|ius', $rawMetadata, $matches); @@ -95,7 +95,7 @@ class Ebook{ $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){ $this->TextSinglePageUrl = $this->Url . '/text/single-page'; } diff --git a/lib/Library.php b/lib/Library.php index a0ecff2f..104410e6 100644 --- a/lib/Library.php +++ b/lib/Library.php @@ -156,7 +156,7 @@ class Library{ foreach(explode("\n", trim(shell_exec('find ' . EBOOKS_DIST_PATH . ' -name "content.opf"') ?? '')) as $filename){ try{ - $ebookWwwFilesystemPath = preg_replace('|/src/.+|ius', '', $filename) ?? ''; + $ebookWwwFilesystemPath = preg_replace('|/content\.opf|ius', '', $filename) ?? ''; $ebook = new Ebook($ebookWwwFilesystemPath); diff --git a/scripts/deploy-ebook-to-www b/scripts/deploy-ebook-to-www index 1f829a9d..5ee122cd 100755 --- a/scripts/deploy-ebook-to-www +++ b/scripts/deploy-ebook-to-www @@ -306,6 +306,9 @@ do mv "${workDir}"/single-page.xhtml "${workDir}"/src/epub/text/single-page.xhtml 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||\n\t\t|" + # Delete the contents of the old webdir rm --preserve-root --recursive --force "${webDir}" @@ -313,7 +316,9 @@ do mkdir -p "${webDir}" # 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 if [ "${images}" = "true" ]; then diff --git a/scripts/generate-opds.php b/scripts/generate-opds.php index 91ecd58d..824bb0e4 100644 --- a/scripts/generate-opds.php +++ b/scripts/generate-opds.php @@ -22,7 +22,7 @@ foreach($contentFiles as $path){ if($path == '') continue; - $ebookWwwFilesystemPath = preg_replace('|/src/.+|ius', '', $path) ?? ''; + $ebookWwwFilesystemPath = preg_replace('|/content\.opf|ius', '', $path) ?? ''; $ebook = new Ebook($ebookWwwFilesystemPath); $allEbooks[$ebook->ModifiedTimestamp->format('Y-m-d\TH:i:s\Z') . ' ' . $ebook->Identifier] = $ebook; diff --git a/www/ebooks/ebook.php b/www/ebooks/ebook.php index 6d736848..d9f172bd 100644 --- a/www/ebooks/ebook.php +++ b/www/ebooks/ebook.php @@ -139,13 +139,17 @@ catch(\Exception $ex){ + TextUrl !== null || $ebook->TextSinglePageUrl !== null){ ?>

Read online

+