mirror of
https://github.com/standardebooks/web.git
synced 2025-07-14 18:42:00 -04:00
Update ebooks to explode the ./src/epub folder into ebook endpoints, instead of just exploding the whole epub
This commit is contained in:
parent
d9ac7312c2
commit
73ba658a05
7 changed files with 20 additions and 19 deletions
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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('|<dc:identifier[^>]*?>(.+?)</dc:identifier>|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';
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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|</title>|</title>\n\t\t<meta content=\"width=device-width, initial-scale=1\" name=\"viewport\"/>|"
|
||||
|
||||
# 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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -139,13 +139,17 @@ catch(\Exception $ex){
|
|||
<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>
|
||||
</aside>
|
||||
<? if($ebook->TextUrl !== null || $ebook->TextSinglePageUrl !== null){ ?>
|
||||
<h3>Read online</h3>
|
||||
<ul>
|
||||
<? if($ebook->TextUrl !== null){ ?>
|
||||
<li><p><span><a href="<?= $ebook->TextUrl ?>" class="list">Start from the table of contents</a></span></p></li>
|
||||
<? } ?>
|
||||
<? if($ebook->TextSinglePageUrl !== null){ ?>
|
||||
<li><p><span><a href="<?= $ebook->TextSinglePageUrl ?>" class="page">Read on one page</a></span></p></li>
|
||||
<? } ?>
|
||||
</ul>
|
||||
<? } ?>
|
||||
</section>
|
||||
<? } ?>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue