|
3 | 3 | import re
|
4 | 4 | from importlib import import_module
|
5 | 5 | from importlib.util import module_from_spec, spec_from_file_location
|
| 6 | +from typing import List |
6 | 7 |
|
7 | 8 | from bs4 import BeautifulSoup, PageElement
|
8 | 9 | from weasyprint import HTML, urls
|
@@ -43,8 +44,31 @@ def on_nav(self, nav):
|
43 | 44 | def on_post_page(self, output_content: str, page, pdf_path: str) -> str:
|
44 | 45 | """ on_post_page """
|
45 | 46 |
|
| 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 | + |
46 | 70 | 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) |
48 | 72 |
|
49 | 73 | if is_excluded(page.url):
|
50 | 74 | self.logger.info(f'Page skipped: [{page.title}]({page.url})')
|
|
0 commit comments