mirror of
https://github.com/standardebooks/web.git
synced 2025-07-10 00:30:28 -04:00
Add chapter navigation footer
This commit is contained in:
parent
f87f6290a4
commit
04cf6bce03
3 changed files with 73 additions and 1 deletions
|
@ -339,9 +339,12 @@ do
|
||||||
workTitle=$(grep --only-matching --extended-regexp "<dc:title id=\"title\">(.+?)</dc:title>" "${workDir}"/src/epub/content.opf | sed --regexp-extended "s/<[^>]+?>//g")
|
workTitle=$(grep --only-matching --extended-regexp "<dc:title id=\"title\">(.+?)</dc:title>" "${workDir}"/src/epub/content.opf | sed --regexp-extended "s/<[^>]+?>//g")
|
||||||
find "${workDir}"/src/epub \( -type d -name .git -prune \) -o -type f -name "*.xhtml" -print0 | xargs -0 sed --in-place --regexp-extended "s|<title>|<title>${workTitle} - |g"
|
find "${workDir}"/src/epub \( -type d -name .git -prune \) -o -type f -name "*.xhtml" -print0 | xargs -0 sed --in-place --regexp-extended "s|<title>|<title>${workTitle} - |g"
|
||||||
|
|
||||||
# Add the nav to each page
|
# Add the header nav to each page
|
||||||
find "${workDir}"/src/epub \( -type d -name .git -prune \) -o -type f -name "*.xhtml" -print0 | xargs -0 sed --in-place --regexp-extended "s%<body(.*?)>%<body\1><header><nav><ul><li><a href=\"/\">Standard Ebooks</a></li><li><a href=\"${bookUrl}\">Back to ebook</a></li><li><a href=\"${bookUrl}/text\">Table of contents</a></li></ul></nav></header>%"
|
find "${workDir}"/src/epub \( -type d -name .git -prune \) -o -type f -name "*.xhtml" -print0 | xargs -0 sed --in-place --regexp-extended "s%<body(.*?)>%<body\1><header><nav><ul><li><a href=\"/\">Standard Ebooks</a></li><li><a href=\"${bookUrl}\">Back to ebook</a></li><li><a href=\"${bookUrl}/text\">Table of contents</a></li></ul></nav></header>%"
|
||||||
|
|
||||||
|
# Add a chapter navigation footer to each page
|
||||||
|
"${scriptsDir}"/inject-chapter-navigation-footer "${workDir}"/src/epub "${bookUrl}"
|
||||||
|
|
||||||
# Adjust sponsored links in the colophon
|
# Adjust sponsored links in the colophon
|
||||||
sed --in-place 's|<p><a href="http|<p><a rel="nofollow" href="http|g' "${workDir}"/src/epub/text/colophon.xhtml
|
sed --in-place 's|<p><a href="http|<p><a rel="nofollow" href="http|g' "${workDir}"/src/epub/text/colophon.xhtml
|
||||||
|
|
||||||
|
|
43
scripts/inject-chapter-navigation-footer
Executable file
43
scripts/inject-chapter-navigation-footer
Executable file
|
@ -0,0 +1,43 @@
|
||||||
|
#!/usr/bin/php
|
||||||
|
<?
|
||||||
|
if(count($argv) < 3){
|
||||||
|
print 'Expected usage: inject-chapter-navigation-footer <epubDirectory> <bookUrl>';
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
$epubDirectory = $argv[1];
|
||||||
|
$bookUrl = $argv[2];
|
||||||
|
|
||||||
|
// Parse the order of chapters from the table of contents.
|
||||||
|
$doc = new DOMDocument();
|
||||||
|
libxml_use_internal_errors(true); // Suppress warnings from output.
|
||||||
|
$doc->loadHTMLFile($epubDirectory . '/toc.xhtml');
|
||||||
|
libxml_clear_errors();
|
||||||
|
$toc = $doc->getElementById('toc');
|
||||||
|
if($toc){
|
||||||
|
$chapterLinks = array();
|
||||||
|
foreach($toc->getElementsByTagName('a') as $link){
|
||||||
|
$obj = new stdClass();
|
||||||
|
$obj->Path = $link->getAttribute('href');
|
||||||
|
$obj->Name = $link->textContent;
|
||||||
|
|
||||||
|
// Only include links pointing to actual files (e.g. skip href="text/chapter-7#panawes-story").
|
||||||
|
if(file_exists($epubDirectory . '/' . $obj->Path . '.xhtml')){
|
||||||
|
$chapterLinks[] = $obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for($i = 0; $i < count($chapterLinks); $i++){
|
||||||
|
$previousObj = $i > 0 ? $chapterLinks[$i - 1] : null;
|
||||||
|
$nextObj = $i < count($chapterLinks) - 1 ? $chapterLinks[$i + 1] : null;
|
||||||
|
|
||||||
|
$fileName = $epubDirectory . '/' . $chapterLinks[$i]->Path . '.xhtml';
|
||||||
|
$chapter = file_get_contents($fileName);
|
||||||
|
// Inject the navigation footer.
|
||||||
|
$previousLink = $previousObj ? sprintf('<a href="%s"><em>Previous:</em> %s</a>', $bookUrl . '/' . $previousObj->Path, htmlspecialchars($previousObj->Name)) : '';
|
||||||
|
$nextLink = $nextObj ? sprintf('<a href="%s"><em>Next:</em> %s</a>', $bookUrl . '/' . $nextObj->Path, htmlspecialchars($nextObj->Name)) : '';
|
||||||
|
$footer = sprintf('<footer><ul><li>%s</li><li>%s</li></ul></footer>', $previousLink, $nextLink);
|
||||||
|
$chapter = str_replace('</body>', $footer . '</body>', $chapter);
|
||||||
|
file_put_contents($fileName, $chapter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -1,5 +1,9 @@
|
||||||
@namespace epub "http://www.idpf.org/2007/ops";
|
@namespace epub "http://www.idpf.org/2007/ops";
|
||||||
|
|
||||||
|
html{
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
body{
|
body{
|
||||||
font-family: "Georgia", serif;
|
font-family: "Georgia", serif;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
|
@ -51,6 +55,28 @@ body > header li:first-child > a:hover{
|
||||||
transform: scale(1.025) rotate(1deg);
|
transform: scale(1.025) rotate(1deg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body > footer{
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
body > footer ul{
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0.5em 1em;
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
body > footer li{
|
||||||
|
max-width: 40%;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
body > section[epub|type~="titlepage"],
|
body > section[epub|type~="titlepage"],
|
||||||
body > section[epub|type~="halftitlepage"]{
|
body > section[epub|type~="halftitlepage"]{
|
||||||
min-height: auto;
|
min-height: auto;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue