Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the MkDocs minify plugin and packaging metadata to a “v2” implementation: switching the HTML minification dependency to htmlmin2, adding an optional debug mode, and reworking scoped CSS link replacement/injection plus post-build cleanup of original scoped CSS files.
Changes:
- Replace
htmlminwithhtmlmin2across requirements/docs and bump package version. - Add
debugconfig + gated debug logging under the MkDocs plugin logger namespace. - Refactor scoped CSS rewriting (regex updates, template fallback gating) and add a post-build cleanup step to remove original scoped CSS when no longer referenced.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
tests/README.md |
Updates listed test dependency from htmlmin to htmlmin2. |
requirements.txt |
Switches HTML minifier dependency to htmlmin2. |
pyproject.toml |
Bumps version and updates runtime dependencies (including htmlmin2 and other missing deps). |
plugins/minify/plugin.py |
Adds debug mode/logging, revises scoped CSS rewrite logic, adds template fallback gating, and introduces scoped CSS cleanup. |
docs/minify.md |
Documents the new debug option and includes tips for filtering debug output. |
Comments suppressed due to low confidence (1)
plugins/minify/plugin.py:485
_tpl_rewrite_replacedis initialized in__init__and then used to skip the post-build fallback, but it isn’t reset per build. Inmkdocs serve(multiple incremental builds), this state can leak across builds and incorrectly skip the fallback scan even when templates/content changed. Reset this tracking (and any other per-build rewrite stats) at the start ofon_pre_build.
def on_pre_build(self, *, config: MkDocsConfig) -> None:
"""Before build: prepare config rewrites and optionally compute hashes."""
self._dbg("[pre_build] start minify_html=%s minify_js=%s minify_css=%s cache_safe=%s", bool(self.config.get("minify_html", False)), bool(self.config.get("minify_js", False)), bool(self.config.get("minify_css", False)), bool(self.config.get("cache_safe", False)))
if self.config.get("minify_js", False) or self.config.get("cache_safe", False):
self._minify_extra_config("js", config)
if self.config.get("minify_css", False) or self.config.get("cache_safe", False):
self._minify_extra_config("css", config)
scoped_files = self._gather_scoped_css_files()
for rel_css in scoped_files:
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
eshaben
left a comment
There was a problem hiding this comment.
This accounts for things that we don't usually do, but I think we almost have to do this because this is based on the original plugin. So, I think what you have is fine, I'm not going to dive into it too much. I tested it out and it still works as expected.
I don't think we should release this until the other plugins are wrapped up. Should be soon though.
Minify v2 😄
New changes:
-Added an optional debug mode, disabled by default, aligned with MkDocs plugin conventions and visible only when running with --verbose.
Non-plugging related: