Skip to content

Comments

Update minify#9

Merged
eshaben merged 11 commits intomainfrom
0xlukem/minify-update
Feb 19, 2026
Merged

Update minify#9
eshaben merged 11 commits intomainfrom
0xlukem/minify-update

Conversation

@0xlukem
Copy link
Contributor

@0xlukem 0xlukem commented Feb 6, 2026

Minify v2 😄

New changes:

  • Improved the CSS matching regex to correctly handle URLs with or without quotes, ensuring compatibility with non-standard or malformed HTML.
  • Simplified the scoped CSS injection flow by introducing a single primary replacement step with a controlled fallback, replacing the previous multi-stage injection behavior.
    -Added an optional debug mode, disabled by default, aligned with MkDocs plugin conventions and visible only when running with --verbose.
  • Implemented a post-replacement cleanup step for scoped CSS:
    • The original (non-minified) CSS file is kept during build and injection.
    • Once the minified and hashed version is successfully injected into HTML, the original file is removed from the final build output, matching the behavior used for global CSS assets.
    • Updated the HTML minification dependency from htmlmin to htmlmin2, removing reliance on deprecated Python modules (CGI) and ensuring compatibility with current Python versions.

Non-plugging related:

  • Fix missing dependencies in the .toml file. It was working fine because we use those dependencies in the requirements.txt in our repo, but if someone else downloads our plugin pack and doesn't have them installed in advance, it will not work.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 htmlmin with htmlmin2 across requirements/docs and bump package version.
  • Add debug config + 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_replaced is initialized in __init__ and then used to skip the post-build fallback, but it isn’t reset per build. In mkdocs 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 of on_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.

@0xlukem 0xlukem marked this pull request as draft February 6, 2026 20:45
@0xlukem 0xlukem marked this pull request as ready for review February 9, 2026 22:57
@0xlukem 0xlukem requested a review from eshaben February 9, 2026 23:55
Copy link
Collaborator

@eshaben eshaben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@eshaben eshaben merged commit ff2c1f2 into main Feb 19, 2026
@eshaben eshaben deleted the 0xlukem/minify-update branch February 19, 2026 00:13
dawnkelly09 added a commit that referenced this pull request Feb 23, 2026
Brings in merged PRs #9 (minify update) and #11 (toggle docs) so
staging branch is in sync with main. Minify conflicts resolved by
accepting origin/main version.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants