Skip to content

Commit 231d6c6

Browse files
authored
Merge pull request #63 from ErikThorsell/feat/exclude_recursively
Exclude pages recursively
2 parents 6226a76 + 11f8aa6 commit 231d6c6

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

mkdocs_with_pdf/generator.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import re
44
from importlib import import_module
55
from importlib.util import module_from_spec, spec_from_file_location
6+
from typing import List
67

78
from bs4 import BeautifulSoup, PageElement
89
from weasyprint import HTML, urls
@@ -43,8 +44,31 @@ def on_nav(self, nav):
4344
def on_post_page(self, output_content: str, page, pdf_path: str) -> str:
4445
""" on_post_page """
4546

47+
def get_excluded_pages(e_paths: List[str]) -> List[str]:
48+
49+
def get_files_in_dir(path: str) -> List[str]:
50+
files = list()
51+
for f in os.listdir(path):
52+
sub_path = os.path.join(path, f)
53+
if os.path.isdir(sub_path):
54+
files += get_files_in_dir(sub_path)
55+
else:
56+
files.append(os.path.splitext(sub_path)[0] + '/')
57+
return files
58+
59+
excluded_pages = list()
60+
cwd = os.getcwd()
61+
os.chdir("docs")
62+
for path in e_paths:
63+
if os.path.isdir(path):
64+
excluded_pages += get_files_in_dir(path)
65+
else:
66+
excluded_pages.append(path)
67+
os.chdir(cwd)
68+
return excluded_pages
69+
4670
def is_excluded(url: str) -> bool:
47-
return url in self._options.exclude_pages
71+
return url in get_excluded_pages(self._options.exclude_pages)
4872

4973
if is_excluded(page.url):
5074
self.logger.info(f'Page skipped: [{page.title}]({page.url})')

0 commit comments

Comments
 (0)