From 5dbe3d42051005c88a9c7bf15542aa87b8dcf0bf Mon Sep 17 00:00:00 2001 From: Rayan Date: Wed, 7 Apr 2021 00:24:43 -0400 Subject: [PATCH] ignoring specific subdirectories by setting 'IGNORE_SUBDIRS' --- pelican/generators.py | 9 +++++++++ pelican/settings.py | 1 + 2 files changed, 10 insertions(+) diff --git a/pelican/generators.py b/pelican/generators.py index 63e20a0a..f8031a62 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -149,6 +149,7 @@ class Generator: files = set() ignores = self.settings['IGNORE_FILES'] + for path in paths: # careful: os.path.join() will add a slash when path == ''. root = os.path.join(self.path, path) if path else self.path @@ -158,6 +159,14 @@ class Generator: root, topdown=True, followlinks=True): excl = exclusions_by_dirpath.get(dirpath, ()) # We copy the `dirs` list as we will modify it in the loop: + # ---- + for dir in dirs: + # check the IGNORE_SUBDIRS + subdirignores = self.settings['IGNORE_SUBDIRS'] + + if any(fnmatch.fnmatch(dir, willignore) for willignore in subdirignores): + dirs.remove(dir) + # ---- for d in list(dirs): if (d in excl or any(fnmatch.fnmatch(d, ignore) diff --git a/pelican/settings.py b/pelican/settings.py index ea3ee8eb..08dde9ef 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -144,6 +144,7 @@ DEFAULT_CONFIG = { 'TEMPLATE_PAGES': {}, 'TEMPLATE_EXTENSIONS': ['.html'], 'IGNORE_FILES': ['.#*'], + 'IGNORE_SUBDIRS': [], 'SLUG_REGEX_SUBSTITUTIONS': [ (r'[^\w\s-]', ''), # remove non-alphabetical/whitespace/'-' chars (r'(?u)\A\s*', ''), # strip leading whitespace