From 1ce1d3bb06e2b72ab39ae264550f126644279327 Mon Sep 17 00:00:00 2001 From: Adrian DC Date: Mon, 21 Oct 2024 23:48:47 +0200 Subject: [PATCH] feat(pdf/aggregator): implement 'book' covers to have 'limits' + 'fronts' Signed-off-by: Adrian DC --- docs/configuration/generating-pdf-documents.md | 1 + mkdocs_exporter/formats/pdf/aggregator.py | 7 +++++++ mkdocs_exporter/formats/pdf/config.py | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/configuration/generating-pdf-documents.md b/docs/configuration/generating-pdf-documents.md index 4e09c03..932573e 100644 --- a/docs/configuration/generating-pdf-documents.md +++ b/docs/configuration/generating-pdf-documents.md @@ -262,6 +262,7 @@ There are five available options for managing cover pages: - `all` (*default*): retains every cover page from all documents. - `none`: removes every cover page from the aggregated document, resulting in a compilation that includes only the main content of each PDF. - `limits`: retains the front cover of the first document and the back cover of the last document, while removing all other cover pages in between. +- `book`: retains the front cover of the first document and the back cover of the last document, while keeping only the front cover pages in between. - `front`: preserves every front cover page from all documents but removes all back cover pages. - `back`: preserves every back cover page from all documents but removes all front cover pages. diff --git a/mkdocs_exporter/formats/pdf/aggregator.py b/mkdocs_exporter/formats/pdf/aggregator.py index 6f3001d..8fb9d0c 100644 --- a/mkdocs_exporter/formats/pdf/aggregator.py +++ b/mkdocs_exporter/formats/pdf/aggregator.py @@ -52,6 +52,13 @@ def set_pages(self, pages: list[Page]) -> Aggregator: self._skip(page, ['front']) else: self._skip(page, ['front', 'back']) + elif covers == 'book': + if len(self.pages) == 1: + pass + elif index == 0: + self._skip(page, ['back']) + elif index < (len(self.pages) - 1): + self._skip(page, ['back']) return self diff --git a/mkdocs_exporter/formats/pdf/config.py b/mkdocs_exporter/formats/pdf/config.py index 5d9b05d..c2431d0 100644 --- a/mkdocs_exporter/formats/pdf/config.py +++ b/mkdocs_exporter/formats/pdf/config.py @@ -40,7 +40,7 @@ class AggregatorConfig(BaseConfig): metadata = c.Type(dict, default={}) """Some metadata to append to the PDF document.""" - covers = c.Choice(['all', 'none', 'limits', 'front', 'back'], default='all') + covers = c.Choice(['all', 'none', 'limits', 'book', 'front', 'back'], default='all') """The behavior of cover pages."""