Skip to content

Commit

Permalink
More options
Browse files Browse the repository at this point in the history
- Adding the option for customizing the working path (the directory with the assets folder)
- Adding the option for customizing the content path (the directory where you have your Markdown files)
- Now you can organize your markdown files in subfolders
- Eliminating most of the warnings during the EPUB generation process (thanks to the `epubcheck` tool)
- Refactoring the configuration class
  • Loading branch information
roberto-butti committed Dec 28, 2023
1 parent 01d9dcd commit a091fa7
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 170 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 1.0.4 - WIP

- Adding the option for customizing the working path (the directory with the assets folder)
- Adding the option for customizing the content path (the directory where you have your Markdown files)
- Now you can organize your markdown files in subfolders
- Eliminating most of the warnings during the EPUB generation process (thanks to the `epubcheck` tool)
- Refactoring the configuration class


## 1.0.3 - 21th December 2023
- Creating the export directory if not exist for EPUB creation
- Improving metadata for EPUB
Expand Down
19 changes: 17 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,21 @@ Before proposing or submitting new features, consider whether they are genuinely
- Examine the codebase to prevent duplication of your proposed feature.
- Check the pull requests to verify that another contributor hasn't already submitted the same feature or fix.

## Opening a Pull Request
### Follow the PER code style guide

This project uses Laravel Pint to fix the code style according to `per` preset.
The `pint.json` file defines the Laravel Pint configuration.
Laravel Pint is built on top of the great tool PHP-CS-Fixer.

To review code out of style, you can run the fix command as a dry run. Run the composer script like this:

`composer run csfix-review`

To fix the source code, run the following composer script:

`composer run csfix`

### Opening a Pull Request

To maintain coding consistency, we adhere to the PER coding standard and use PHPStan for static code analysis (WIP). You can utilize the following command:

Expand All @@ -40,7 +54,8 @@ composer all-check
This command encompasses:

- PER Coding Standard checks employing Laravel Pint.
- (WIP) PHPStan analysis at level 8.
- Executing some RectoryPHP checks, like the usage of PHP updated syntax (at least 8.1), the type declaration, early return, and dead code. For more info check the `rector.php` file in the root of the project.
- (WIP) PHPStan analysis.
- (WIP) Execution of all tests from the `./tests/*` directory using PestPHP.

We recommend running `composer all-check` before committing and creating a pull request.
Expand Down
11 changes: 10 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,23 @@
"csfix-review": [
"pint --test"
],
"refactor": [
"rector process src"
],
"refactor-review": [
"rector process src --dry-run"
],
"all-check": [
"@refactor-review",
"@csfix"
]
},
"scripts-descriptions": {
"csfix": "Runs Pint to fix code style.",
"csfix-review": "Runs Pint to show the code style review.",
"all-check": "Runs all checks needed."
"all-check": "Runs all checks needed.",
"refactor-review": "Runs Rector to show the code refactor review.",
"refactor": "Runs Rector and applies the refactor."
},
"minimum-stability": "stable",
"prefer-stable": true
Expand Down
87 changes: 44 additions & 43 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
<p align="center">
<img src="https://raw.githubusercontent.com/hi-folks/ibis-next/main/art/ibis-next-cover.png" alt="Ibis Next cover" width="480">

Artwork generated with Cover Wizard.
</p>

---

This PHP tool helps you write eBooks in markdown. Run `ibis-next build` and an eBook will be generated with:
This PHP tool helps you write eBooks in markdown. You can automatically generate a PDF or an EPUB file.
Run `ibis-next build` or `ibis-next epub` and an eBook will be generated with:

1. A cover photo.
2. Clickable auto-generated table of contents.
3. Code syntax highlighting.
4. Available in 2 themes. Light and dark.
4. Available in 2 themes. Light and dark (the theme features is supported only for PDF).

The Ibis project was created by Mohamed Said. The sources of the Ibis project are https://github.com/themsaid/ibis.
We want to say thank you to Mohamed for creating this tool.
Ibis was used to create [Laravel Queues in Action](https://learn-laravel-queues.com), an eBook Mohamed published in August 2020. [Click here](https://learn-laravel-queues.com/laravel-queues-in-action.zip) for the sample.

Why we forked the repository: to speed up the process of supporting PHP 8.2, PHP 8.3, Laravel 10, Symfony 7, Commonmark 2, and other dependencies upgrades.
Then we want to try to support also EPUB format, not only PDF.
Why we forked the repository: to speed up the process of supporting PHP 8.2, **PHP 8.3**, **Laravel 10**, **Symfony 7**, **Commonmark 2**, and other dependencies upgrades.
With *Ibis Next* we added also the **support for generating the EPUB format**. So with *Ibis Next* you can create your markdown files and then export them into PDF and EPUB for better compatibility with your devices and software.

## Installation

Expand All @@ -30,39 +29,41 @@ You can decide if you want to install it locally for a specific project (eBook i

If you want to start quickly to build your eBook you can:
- create a new empty directory via the `mkdir` command, and then jump into the new directory via the `cd` command:
```

~~~shell
mkdir my-first-ebook
cd my-first-ebook
```
~~~

Now you are in the new empty directory, you can install Ibis Next:

```
~~~shell
composer require hi-folks/ibis-next
```
~~~

Once the tool is installed, you will find the `vendor/` directory where you can find your new tool (`vendor/bin/ibis-next`).

Now you can initialize properly the directory via the `init` command for automatically creating the configuration file, the assets folder, and the content folder (for creating your Markdown files).
To launch the `init`` command:

```
~~~shell
./vendor/bin/ibis-next init
```
~~~

### Installing ibis-next globally


Instead, if you prefer to install the composer package globally you can add the `global` option while you are running the `composer require` command:

```
~~~shell
composer global require hi-folks/ibis-next
```
~~~

Then, run this command inside an **empty directory**:

```
~~~shell
ibis-next init
```
~~~

This will create the following files and directories:

Expand All @@ -84,7 +85,7 @@ This sample content is taken from [Laravel Queues in Action](https://learn-larav

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 All @@ -96,65 +97,65 @@ Inside the `content` directory, you can write multiple `.md` files. Ibis uses th
### Starting with Ibis

<h3> tags define different titles inside a chapter.
```
~~~

### Adding different quotes

Three different types of quotes can be added: `quote`, `warning`, and `notice`.

```md
~~~markdown
>{quote} This is a quote.

>{warning} This is a warning.

>{notice} This is a notice.
```
~~~

### Using images

Images can be stored in the content folder and then brought in like this:

```
~~~markdown
![Screenshot 1](content/screenshot-1.png)
```
~~~

### Adding a cover image
To use a cover image, add a `cover.jpg` in the `assets/` directory (or a `cover.html` file if you'd prefer a HTML-based cover page). If you don't want a cover image, delete these files.
If your cover is in a PNG format you can store the file in the `assets/` directory and then in the `ibis.php` file you can adjust the `cover` configuration where you can set the cover file name, for example:

```
~~~php
'cover' => [
'position' => 'position: absolute; left:0; right: 0; top: -.2; bottom: 0;',
'dimensions' => 'width: 210mm; height: 297mm; margin: 0;',
'image' => 'cover.png',
],
```
~~~

### Setting the page headers

You can set a page header for the pages.
To add the header you need to set the `header` parameter in the `ibis.php` configuration file.
For example, in the `ibis.php` file, you can set:

```php
~~~php
/**
* CSS inline style for the page header.
* If you want to skip header, comment the line
*/
'header' => 'font-style: italic; text-align: right; border-bottom: solid 1px #808080;',
```
~~~

If you want to customize the page header for each section, in the markdown file, you can add in the frontmatter section the `title` parameter:

```markdown
~~~markdown
---
title: My Title
---

## My Section Title
This is an example.

```
~~~

<p align="center">
<img src="https://raw.githubusercontent.com/hi-folks/ibis-next/main/art/ibis-next-setting-page-header.png" alt="Setting the Page Header" width="480">
Expand All @@ -167,17 +168,17 @@ Edit your `/ibis.php` configuration files to define the font files to be loaded

## Generating PDF eBook

```
~~~shell
ibis-next pdf
```
~~~

Ibis will parse the files in alphabetical order and store the PDF file in the `export` directory.

By default, for generating the PDF file, the light theme is used. To generate a PDF using the dark theme:

```
~~~shell
ibis-next pdf dark
```
~~~

### Using content from a different directory

Expand Down Expand Up @@ -208,6 +209,16 @@ Ibis will parse the files in alphabetical order and store the EPUB file in the `

By default, for generating the EPUB file, the `assets/style.css` file is used.

If you are managing more than one book, you can use define the working directory. The working directory is the directory where your `assets` folder and `ibis.php` configuration file are located. You can define the path of the working directory via the `-w` option:

```
ibis-next epub -c ../your-dir-with-markdown-files -w ../myibisbook
```

You can combine the usage of the `-c` option for defining the content directory and the `-w` option for defining the working directory.

> You can organize your Markdown files in your content directory in subfolders.
## Generating A Sample

```
Expand All @@ -220,17 +231,7 @@ This command will use the generated files from the `ibis-next build` command to

## Development

This project uses Laravel Pint to fix the code style according to `per` preset.
The `pint.json` file defines the Laravel Pint configuration.
Laravel Pint is built on top of the great tool PHP-CS-Fixer.

To review code out of style, you can run the fix command as a dry run. Run the composer script like this:

`composer run csfix-review`

To fix the source code, run the following composer script:

`composer run csfix`
If you want to contribute to the development of this open-source project you can read the CONTRIBUTING.md file, at the root of the project.

## Credits

Expand Down
39 changes: 16 additions & 23 deletions src/Commands/BaseBuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Ibis\Commands;

use Ibis\Config;
use SplFileInfo;

use Illuminate\Filesystem\Filesystem;
Expand Down Expand Up @@ -33,34 +34,28 @@ class BaseBuildCommand extends Command

protected string $currentPath;

protected array $config;
protected Config $config;


protected function preExecute(InputInterface $input, OutputInterface $output)
protected function preExecute(InputInterface $input, OutputInterface $output): bool
{
$this->disk = new Filesystem();
$this->output = $output;

$this->currentPath = getcwd();

$this->contentDirectory = $input->getOption('content');
if ($this->contentDirectory === "") {
$this->contentDirectory = getcwd() . DIRECTORY_SEPARATOR . "content";
}
if (!$this->disk->isDirectory($this->contentDirectory)) {
$this->output->writeln('<error>Error, check if ' . $this->contentDirectory . ' exists.</error>');
exit;
$this->config = Config::load($input->getOption('workingdir'));
$this->output->writeln('<info>Loading config/assets from: ' . $this->config->workingPath . '</info>');
$this->output->writeln('<info>Loading config file from: ' . $this->config->ibisConfigPath . '</info>');
if ($this->config->setContentPath($input->getOption('content')) === false) {
$this->output->writeln('<error>Error, check if ' . $this->config->contentPath . ' exists.</error>');
return false;
}
$this->output->writeln('<info>Loading content from: ' . $this->contentDirectory . '</info>');
$this->output->writeln('<info>Loading content from: ' . $this->config->contentPath . '</info>');

$configIbisFile = $this->currentPath . '/ibis.php';
if (!$this->disk->isFile($configIbisFile)) {
$this->output->writeln('<error>Error, check if ' . $configIbisFile . ' exists.</error>');
exit;
if (!$this->disk->isFile($this->config->ibisConfigPath)) {
$this->output->writeln('<error>Error, check if ' . $this->config->ibisConfigPath . ' exists.</error>');
return false;
}

$this->config = require $configIbisFile;

return true;
}


Expand Down Expand Up @@ -134,10 +129,8 @@ protected function prepareHtmlForEbook(string $html, $file, $breakLevel = 2): st
'[break]' => '<div style="page-break-after: always;"></div>'
];

if ($file > 1) {
if ($breakLevel >= 1) {
$html = str_replace('<h1>', '[break]<h1>', $html);
}
if ($file > 1 && $breakLevel >= 1) {
$html = str_replace('<h1>', '[break]<h1>', $html);
}
if ($breakLevel >= 2) {
$html = str_replace('<h2>', '[break]<h2>', $html);
Expand Down
Loading

0 comments on commit a091fa7

Please sign in to comment.