Skip to content

Commit

Permalink
fix: misc. fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienbrignon committed Jun 7, 2024
1 parent 58be8f9 commit d926dc6
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 35 deletions.
25 changes: 3 additions & 22 deletions docs/configuration/generating-pdf-documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ plugins:
attributes: !!python/name:mkdocs_exporter.formats.pdf.buttons.download.attributes
```
<div class="page-break-after"></div>
### Combining pages into a single PDF document
In *MkDocs Exporter*, the aggregator feature allows you to consolidate multiple individual PDF documents into a single cohesive PDF file.
Expand Down Expand Up @@ -248,26 +250,5 @@ plugins:
pdf:
aggregator:
enabled: true
covers: all
output: combined.pdf
```
#### Configuring cover pages
In your `mkdocs.yml` configuration file, you can specify how cover pages are handled during the aggregation process using the `covers` parameter:

```yaml
plugins:
- exporter:
formats:
pdf:
aggregator:
enabled: true
covers: all
output: documentation.pdf
```

You can define how cover pages from individual PDFs should be handled using one of the following modes:

- `none`: Cover pages will be skipped in the final combined document.
- `all` (*default*): Cover pages will be included as-is from each individual PDF.
- `limits`: Only the front cover of the first page and the back cover of the last page will be included in the combined document.
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ hide:

## Examples

- [__Read__ this documentation in the PDF format](./combined.pdf)
- [__Read__ this documentation in the PDF format](../documentation.pdf)
- [__View__ this page in the PDF format](./index.pdf)

## Prerequisites
Expand Down
3 changes: 2 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ extra:
link: https://pypi.org/project/mkdocs-exporter

plugins:
- privacy:
log_level: warn
- mkdocstrings:
handlers:
python:
Expand Down Expand Up @@ -85,7 +87,6 @@ plugins:
- resources/stylesheets/pdf.scss
covers:
front: resources/templates/covers/front.html.j2
back: resources/templates/covers/back.html.j2
browser:
debug: false
headless: true
Expand Down
1 change: 1 addition & 0 deletions mkdocs_exporter/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class LoggingConfig(BaseConfig):
"""The logging configuration."""

level = c.Choice(['debug', 'info', 'warning', 'error', 'critical'], default='info')
"""The log level."""


class Config(BaseConfig):
Expand Down
3 changes: 0 additions & 3 deletions mkdocs_exporter/formats/pdf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ class AggregatorConfig(BaseConfig):
output = c.Type(str, default='combined.pdf')
"""The aggregated PDF document output file path."""

covers = c.Choice(['none', 'all', 'limits'], default='all')
"""The behaviour of cover pages."""

metadata = c.Type(dict, default={})
"""Some metadata to append to the PDF document."""

Expand Down
8 changes: 0 additions & 8 deletions mkdocs_exporter/formats/pdf/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,11 @@ def on_page_markdown(self, markdown: str, page: Page, config: Config, **kwargs)

content = markdown
covers = {**self.config.covers, **{k: os.path.join(os.path.dirname(config['config_file_path']), v) for k, v in page.meta.get('covers', {}).items()}}
page.formats['pdf']['covers'] = {
'front': False,
'back': False
}

if covers.get('front'):
page.formats['pdf']['covers']['front'] = True

with open(covers['front'], 'r', encoding='utf-8') as file:
content = self.renderer.cover(file.read()) + content
if covers.get('back'):
page.formats['pdf']['covers']['back'] = True

with open(covers['back'], 'r', encoding='utf-8') as file:
content = content + self.renderer.cover(file.read())

Expand Down

0 comments on commit d926dc6

Please sign in to comment.