From 1a7e7dfc82d02108af4c26fd6cc7fad39b470273 Mon Sep 17 00:00:00 2001 From: Chris Warrick Date: Sun, 9 Jul 2023 14:35:36 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20#3698=20=E2=80=94=20ignore=20.DS=5FStore?= =?UTF-8?q?=20files=20in=20listing=20indexes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES.txt | 1 + nikola/plugins/task/listings.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 75dd4ec6f1..f7c4b91c58 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -9,6 +9,7 @@ Features Bugfixes -------- +* Ignore ``.DS_Store`` files in listing indexes (Issue #3698) * Fix baguetteBox.js invoking in the base theme (Issue #3687) New in v8.2.4 diff --git a/nikola/plugins/task/listings.py b/nikola/plugins/task/listings.py index 5a1b140135..4c1636e558 100644 --- a/nikola/plugins/task/listings.py +++ b/nikola/plugins/task/listings.py @@ -107,6 +107,7 @@ def gen_tasks(self): """Render pretty code listings.""" # Things to ignore in listings ignored_extensions = (".pyc", ".pyo") + ignored_files = (".DS_Store",) def render_listing(in_name, out_name, input_folder, output_folder, folders=[], files=[]): needs_ipython_css = False @@ -183,7 +184,9 @@ def render_listing(in_name, out_name, input_folder, output_folder, folders=[], f for input_folder, output_folder in self.kw['listings_folders'].items(): for root, dirs, files in os.walk(input_folder, followlinks=True): - files = [f for f in files if os.path.splitext(f)[-1] not in ignored_extensions] + files = [f for f in files + if os.path.splitext(f)[-1] not in ignored_extensions and + f not in ignored_files] uptodate = {'c': self.site.GLOBAL_CONTEXT} @@ -224,7 +227,7 @@ def render_listing(in_name, out_name, input_folder, output_folder, folders=[], f 'clean': True, }, self.kw["filters"]) for f in files: - if f == '.DS_Store': + if f in ignored_files: continue ext = os.path.splitext(f)[-1] if ext in ignored_extensions: