Skip to content

Commit 4d4bc4c

Browse files
committed
Add an option for page exclusion, issue #4.
1 parent a230aa2 commit 4d4bc4c

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ plugins:
7373
#excludes_children:
7474
# - 'release-notes/:upgrading'
7575
# - 'release-notes/:changelog'
76-
#
76+
#exclude_pages:
77+
# - 'bugs/'
78+
# - 'appendix/contribute/'
7779
#output_path: any-place/document.pdf
7880
#enabled_if_env: ENABLE_PDF_EXPORT
7981
#
@@ -149,6 +151,14 @@ plugins:
149151
Set the page `id` of `nav` url. If the `id` matches in this list, it will be excluded from the heading number addition and table of contents.
150152
**default**: `[]`
151153
154+
##### for Page
155+
156+
* `exclude_pages`
157+
158+
Set the page `id` of `nav` url. If the `id` matches in this list, it will be excluded page contents.
159+
**default**: `[]`
160+
_**since**: `v0.3.0`_
161+
152162
##### ... and more
153163
154164
* `output_path`

mkdocs_with_pdf/generator.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ def on_nav(self, nav):
3333

3434
def on_post_page(self, output_content: str, page, pdf_path: str) -> str:
3535
""" on_post_page """
36+
37+
def is_excluded(url: str) -> bool:
38+
return url in self._options.exclude_pages
39+
40+
if is_excluded(page.url):
41+
self.logger.info(f'Page skipped: [{page.title}]({page.url})')
42+
return f"<!-- skipped '{page}' -->"
43+
else:
44+
self.logger.debug(f' (post: [{page.title}]({page.url})')
45+
3646
soup = self._soup_from_content(output_content, page)
3747

3848
self._remove_empty_tags(soup)

mkdocs_with_pdf/options.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class Options(object):
3131
('heading_shift', config_options.Type(bool, default=True)),
3232
('toc_level', config_options.Type(int, default=2)),
3333
('ordered_chapter_level', config_options.Type(int, default=3)),
34-
('excludes_children', config_options.Type(list, default=[]))
34+
('excludes_children', config_options.Type(list, default=[])),
35+
36+
('exclude_pages', config_options.Type(list, default=[]))
3537
)
3638

3739
def __init__(self, local_config, config, logger: logging):
@@ -63,6 +65,9 @@ def __init__(self, local_config, config, logger: logging):
6365
self.ordered_chapter_level = local_config['ordered_chapter_level']
6466
self.excludes_children = local_config['excludes_children']
6567

68+
# Page
69+
self.exclude_pages = local_config['exclude_pages']
70+
6671
# Theming
6772
self.theme_name = config['theme'].name
6873
self.theme_handler_path = config.get('theme_handler_path', None)

0 commit comments

Comments
 (0)