Skip to content

Commit

Permalink
Fine tuning EPUB generation
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-butti committed Dec 21, 2023
1 parent 331df0f commit 01d9dcd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
# Changelog

## 1.0.3 - 21th December 2023
- Creating the export directory if not exist for EPUB creation
- Improving metadata for EPUB
- Table of Contents or EPUB

## 1.0.2 - 21th December 2023
- Setting the content directory
- Refactoring common code EPUB and PDF build
- Introducing RectorPHP


## 1.0.1 - 21th December 2023
- Welcome to EPUB generation
- Welcome to the EPUB generation

## 1.0.0 - 17th December 2023

- upgrade and check with PHP 8.2 and PHP 8.3
- update support for Symfony 7 components
- upgrade code using new renderer of CommonMark
- upgrade code using the new renderer of CommonMark
- upgrade GitHub Actions workflow
- using Pint with PSR12
- added configuration for cover image (instead of using hard-coded cover.jpg, you can specify a new file name and format, for example, my-cover.png)
Expand Down
25 changes: 20 additions & 5 deletions src/Commands/BuildEpubCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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\Input\InputOption;

class BuildEpubCommand extends BaseBuildCommand
Expand Down Expand Up @@ -52,7 +53,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
$this->preExecute($input, $output);



$this->ensureExportDirectoryExists($this->currentPath);


$this->config["breakLevel"] = 1;
Expand Down Expand Up @@ -99,13 +100,14 @@ protected function buildEpub(Collection $chapters, array $config, string $curren
$book->setAuthor(Ibis::author(), Ibis::author());
$book->setIdentifier(Ibis::title() . "&stamp=" . time(), EPub::IDENTIFIER_URI);
$book->setLanguage("en");

$book->addCSSFile("style.css", "css1", $this->getStyle($this->currentPath, "style"));
$cssData = file_get_contents("https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.css");
$book->addCSSFile("github.css", "css2", $cssData);
//$book->addChapter("Table of Contents", "TOC.xhtml", null, false, EPub::EXTERNAL_REF_IGNORE);
$book->addChapter("Table of Contents", "TOC.xhtml", null, false, EPub::EXTERNAL_REF_IGNORE);
$cover = $content_start . "<h1>" . Ibis::title() . "</h1>\n";
if (Ibis::author()) {
$cover .= "<h2>By: " . Ibis::author() . "e</h2>\n";
$cover .= "<h2>By: " . Ibis::author() . "</h2>\n";
}
$content_end = "</body></html>";
$cover .= $content_end;
Expand All @@ -122,11 +124,24 @@ protected function buildEpub(Collection $chapters, array $config, string $curren
}

$book->addChapter("Notices", "Cover.html", $cover);
$book->buildTOC();
$book->buildTOC(null, "toc", "Table of Contents", true, true);
//$book->buildTOC();
/*
$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", Ibis::author());
$metaValue->addOpfAttr("file-as", Ibis::author());
$metaValue->addOpfAttr("role", "aut");
$book->addCustomMetaValue($metaValue);


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

$book->addChapter(
Arr::get($chapter, "frontmatter.title", "Chapter " . $key),
Arr::get($chapter, "frontmatter.title", "Chapter " . $key + 1),
"Chapter" . $key . " .html",
$content_start . $chapter["html"] . $content_end
);
Expand Down

0 comments on commit 01d9dcd

Please sign in to comment.