Skip to content

Commit

Permalink
Fixing Table of Content per EPUB
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-butti committed Dec 30, 2023
1 parent 03d9c84 commit 35295e8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 18 additions & 16 deletions src/Commands/BuildEpubCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use PHPePub\Core\EPub;
use PHPePub\Core\Structure\OPF\MetaValue;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;

Expand Down Expand Up @@ -116,7 +115,9 @@ protected function buildEpub(Collection $chapters, array $config, string $curren
//$book->setLanguage("en");

$book->addCSSFile("style.css", "css1", $this->getStyle($this->config->workingPath, "style"));
$cssData = file_get_contents("https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.css");
//$cssData = file_get_contents("https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.css");
$cssData = file_get_contents("https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/github-gist.min.css");

$book->addCSSFile("github.css", "css2", $cssData);
//
$cover = $content_start . "<h1>" . $this->config->title() . "</h1>\n";
Expand All @@ -137,32 +138,33 @@ protected function buildEpub(Collection $chapters, array $config, string $curren
$coverDimensions = $config['cover']['dimensions'] ?? 'width: 210mm; height: 297mm; margin: 0;';
$book->setCoverImage($coverImage, file_get_contents($pathCoverImage), mime_content_type($pathCoverImage));
}
$book->buildTOC(null, "toc", "Table of Contents", true, true);
$book->addChapter("Notices", "Cover.html", $cover);
//$book->addChapter("Table of Contents", "TOC.html", null, false, EPub::EXTERNAL_REF_IGNORE);
//$book->buildTOC();

$book->addChapter("Cover", "Cover.html", $cover);
$book->addChapter("Table of Contents", "TOC.xhtml", null, false, EPub::EXTERNAL_REF_IGNORE);

/*
$book->addFileToMETAINF("com.apple.ibooks.display-options.xml", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<display_options>\n <platform name=\"*\">\n <option name=\"fixed-layout\">true</option>\n <option name=\"interactive\">true</option>\n <option name=\"specified-fonts\">true</option>\n </platform>\n</display_options>");
*/
//$book->addCustomNamespace("dc", "http://purl.org/dc/elements/1.1/"); // StaticData::$namespaces["dc"]);
// This is to show how to use meta data, normally you'd use the $book->setAuthor
$metaValue = new MetaValue("dc:creator", $this->config->author());
$metaValue->addOpfAttr("file-as", $this->config->author());
$metaValue->addOpfAttr("role", "aut");
$book->addCustomMetaValue($metaValue);
$book->addCustomNamespace("dc", "http://purl.org/dc/elements/1.1/"); // StaticData::$namespaces["dc"]);


foreach ($chapters as $key => $chapter) {
$this->output->writeln('<fg=yellow>==></> ❇️ ' . $chapter["mdfile"] . ' ...');

$book->addChapter(
Arr::get($chapter, "frontmatter.title", "Chapter " . $key + 1),
"Chapter" . $key . ".html",
$content_start . $chapter["html"] . $content_end
chapterName: Arr::get($chapter, "frontmatter.title", "Chapter " . $key + 1),
fileName: "Chapter" . $key . ".html",
chapterData: $content_start . $chapter["html"] . $content_end,
externalReferences: EPub::EXTERNAL_REF_ADD
);
//file_put_contents('export/' . "Chapter" . $key . " .html", $content_start . $chapter["html"] . $content_end);
}
//$book->buildTOC();

$book->buildTOC(
title: "Index",
addReferences: false,
addToIndex: false
);

$book->finalize();

Expand Down
1 change: 1 addition & 0 deletions stubs/content/004-writing-content.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This sample content is taken from [Ibis Next: create your eBooks with Markdown](
Inside the `content` directory, you can write multiple `.md` files. Ibis uses the headings to divide the book into parts and chapters:

~~~markdown

# Part 1

`<h1>` tags define the start of a part. A separate PDF page will be generated to print the part title and any content below.
Expand Down
4 changes: 4 additions & 0 deletions stubs/content/006-conclusion.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
title: Conclusion and Your Feedback
---

## Conclusion and Your Feedback

Congratulations on exploring the powerful capabilities of Ibis Next for seamless eBook creation!
Expand Down

0 comments on commit 35295e8

Please sign in to comment.