diff --git a/ibis-next b/ibis-next index 99f5b5c..4190d65 100755 --- a/ibis-next +++ b/ibis-next @@ -1,8 +1,8 @@ #!/usr/bin/env php setDefaultCommand("build"); +$app = new Application('Ibis Next', '1.0.x'); +//$app->setDefaultCommand("build"); // Authentication... $app->add(new InitCommand()); -$app->add(new BuildCommand); -$app->add(new EpubCommand()); +$app->add(new BuildPdfCommand); +$app->add(new BuildEpubCommand()); $app->add(new SampleCommand); $app->add(new SortContentCommand()); diff --git a/readme.md b/readme.md index 5e9aa79..17254a3 100644 --- a/readme.md +++ b/readme.md @@ -71,6 +71,7 @@ This will create the following files and directories: - /assets/cover.jpg - /assets/theme-light.html - /assets/theme-dark.html +- /assets/style.css - /content - /ibis.php @@ -167,7 +168,7 @@ Edit your `/ibis.php` configuration files to define the font files to be loaded ## Generating PDF eBook ``` -ibis-next build +ibis-next pdf ``` Ibis will parse the files in alphabetical order and store the PDF file in the `export` directory. @@ -175,7 +176,7 @@ Ibis will parse the files in alphabetical order and store the PDF file in the `e By default, for generating the PDF file, the light theme is used. To generate a PDF using the dark theme: ``` -ibis-next build dark +ibis-next pdf dark ``` ## Generating EPUB eBook 🆕 diff --git a/src/Commands/BaseBuildCommand.php b/src/Commands/BaseBuildCommand.php index 4bd8096..945b277 100644 --- a/src/Commands/BaseBuildCommand.php +++ b/src/Commands/BaseBuildCommand.php @@ -5,6 +5,7 @@ use SplFileInfo; use Illuminate\Filesystem\Filesystem; +use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -17,6 +18,7 @@ use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode; use League\CommonMark\Extension\CommonMark\Node\Block\IndentedCode; +use League\CommonMark\Extension\FrontMatter\Output\RenderedContentWithFrontMatter; use League\CommonMark\MarkdownConverter; use Spatie\CommonMarkHighlighter\IndentedCodeRenderer; use Spatie\CommonMarkHighlighter\FencedCodeRenderer; @@ -87,7 +89,7 @@ protected function buildHtml(string $path, array $config): Collection $converter = new MarkdownConverter($environment); return collect($this->disk->allFiles($path)) - ->map(function (SplFileInfo $file, $i) use ($converter) { + ->map(function (SplFileInfo $file, $i) use ($converter, $config) { $chapter = collect([]); if ($file->getExtension() != 'md') { @@ -111,7 +113,8 @@ protected function buildHtml(string $path, array $config): Collection } $chapter["html"] = $this->prepareHtmlForEbook( $convertedMarkdown->getContent(), - $i + 1 + $i + 1, + Arr::get($config, "breakLevel", 2) ); @@ -125,17 +128,20 @@ protected function buildHtml(string $path, array $config): Collection * @param $file * @return string|string[] */ - protected function prepareHtmlForEbook(string $html, $file): string + protected function prepareHtmlForEbook(string $html, $file, $breakLevel = 2): string { $commands = [ '[break]' => '
' ]; if ($file > 1) { - $html = str_replace('

', '[break]

', $html); + if ($breakLevel >= 1) { + $html = str_replace('

', '[break]

', $html); + } + } + if ($breakLevel >= 2) { + $html = str_replace('

', '[break]

', $html); } - - $html = str_replace('

', '[break]

', $html); $html = str_replace("
\n

{notice}", "

Notice:", $html); $html = str_replace("

\n

{warning}", "

Warning:", $html); $html = str_replace("

\n

{quote}", "

", $html); diff --git a/src/Commands/EpubCommand.php b/src/Commands/BuildEpubCommand.php similarity index 97% rename from src/Commands/EpubCommand.php rename to src/Commands/BuildEpubCommand.php index 7defb54..05d27f5 100644 --- a/src/Commands/EpubCommand.php +++ b/src/Commands/BuildEpubCommand.php @@ -6,13 +6,13 @@ use Illuminate\Support\Arr; use Illuminate\Support\Collection; -use Symfony\Component\Console\Command\Command; + use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use PHPePub\Core\EPub; use Symfony\Component\Console\Input\InputOption; -class EpubCommand extends BaseBuildCommand +class BuildEpubCommand extends BaseBuildCommand { /** * Configure the command. @@ -23,6 +23,7 @@ protected function configure() { $this ->setName('epub') + ->addOption( 'content', 'c', @@ -30,7 +31,7 @@ protected function configure() 'The path of the content directory', '' ) - ->setDescription('Generate the book in Epub format.'); + ->setDescription('Generate the book in EPUB format.'); } /** @@ -54,6 +55,7 @@ public function execute(InputInterface $input, OutputInterface $output): int + $this->config["breakLevel"] = 1; $result = $this->buildEpub( $this->buildHtml($this->contentDirectory, $this->config), $this->config, diff --git a/src/Commands/BuildCommand.php b/src/Commands/BuildPdfCommand.php similarity index 97% rename from src/Commands/BuildCommand.php rename to src/Commands/BuildPdfCommand.php index 42cc596..e64e18d 100644 --- a/src/Commands/BuildCommand.php +++ b/src/Commands/BuildPdfCommand.php @@ -11,7 +11,6 @@ use Illuminate\Support\Arr; use Illuminate\Support\Collection; -use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -19,7 +18,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; -class BuildCommand extends BaseBuildCommand +class BuildPdfCommand extends BaseBuildCommand { /** * @var string|string[]|null @@ -39,7 +38,8 @@ class BuildCommand extends BaseBuildCommand protected function configure() { $this - ->setName('build') + ->setName('pdf') + ->setAliases(["build"]) ->addArgument('theme', InputArgument::OPTIONAL, 'The name of the theme', 'light') ->addOption( 'content', @@ -48,7 +48,7 @@ protected function configure() 'The path of the content directory', '' ) - ->setDescription('Generate the book.'); + ->setDescription('Generate the book in PDF format.'); } /**