From 98677c730416b5921a50c3e12f9d7201fc9663cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?spart=E2=88=86ck?= <136268910+spart4ck@users.noreply.github.com> Date: Tue, 11 Aug 2026 17:39:28 +0200 Subject: [PATCH 1/2] New feature to be able to skip files already minified with '.min.' in the name, or exclude based in a custom array --- pelican/plugins/minify/minify.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pelican/plugins/minify/minify.py b/pelican/plugins/minify/minify.py index 8b8b25d..fc30f98 100644 --- a/pelican/plugins/minify/minify.py +++ b/pelican/plugins/minify/minify.py @@ -27,16 +27,26 @@ def __init__(self, pelican): minify_js = pelican.settings.get("JS_MIN", True) minify_inline_css = pelican.settings.get("INLINE_CSS_MIN", True) minify_inline_js = pelican.settings.get("INLINE_JS_MIN", True) + minify_skip_files = pelican.settings.get("MINIFY_SKIP_FILES", []) + minify_skip_already_minified = pelican.settings.get( + "MINIFY_SKIP_ALREADY_MINIFIED", True + ) for path, _, files in os.walk(pelican.output_path): for name in files: path_file = os.path.join(path, name) + if self.skip_file( + path, name, minify_skip_files, minify_skip_already_minified + ): + continue + is_html = fnmatch(name, "*.html") is_css = fnmatch(name, "*.css") is_js = fnmatch(name, "*.js") if is_html and minify_html: + LOGGER.debug(f"[MINIFY] File {path_file} minified") self.write_to_file( path_file, lambda content: self.minify( @@ -45,12 +55,14 @@ def __init__(self, pelican): ) if is_css and minify_css: + LOGGER.debug(f"[MINIFY] File {path_file} minified") self.write_to_file( path_file, lambda content: self.minify(content, True, False), ) if is_js and minify_js: + LOGGER.debug(f"[MINIFY] File {path_file} minified") self.write_to_file( path_file, lambda content: self.minify(content, False, True) ) @@ -62,6 +74,16 @@ def minify(self, content, minify_css, minify_js): minify_js=minify_js, ) + # Exclude files which path or name is into the array of skip_files, or is already minified + def skip_file(self, path, name, skip_files, skip_already_minified) -> bool: + if (skip_already_minified and ".min." in name) or any( + path_or_name in skip_files for path_or_name in [path, name] + ): + LOGGER.debug(f"[MINIFY] File {name} skipped") + return True + + return False + @staticmethod def write_to_file(path_file, callback): """Write the file to disk. From 45c4fe1bc11bc1c730ceda407d41ec69fc1ee841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?spart=E2=88=86ck?= <136268910+spart4ck@users.noreply.github.com> Date: Tue, 11 Aug 2026 20:10:49 +0200 Subject: [PATCH 2/2] Correction of logic to detect excluded name into the string, not 100% match of the string --- pelican/plugins/minify/minify.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pelican/plugins/minify/minify.py b/pelican/plugins/minify/minify.py index fc30f98..0774595 100644 --- a/pelican/plugins/minify/minify.py +++ b/pelican/plugins/minify/minify.py @@ -74,10 +74,17 @@ def minify(self, content, minify_css, minify_js): minify_js=minify_js, ) - # Exclude files which path or name is into the array of skip_files, or is already minified + # Exclude files already minified or which name or path is contained into the array of excluded files def skip_file(self, path, name, skip_files, skip_already_minified) -> bool: - if (skip_already_minified and ".min." in name) or any( - path_or_name in skip_files for path_or_name in [path, name] + path_or_name = [path, name] + + if (skip_already_minified and ".min." in name) or ( + skip_files + and any( + exclude_name in real_name + for real_name in path_or_name + for exclude_name in skip_files + ) ): LOGGER.debug(f"[MINIFY] File {name} skipped") return True