Skip to content

Commit

Permalink
feat: resolve globs using pathlib.glob()
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianDsg committed Dec 15, 2023
1 parent 64d7e8c commit 0331da4
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions mkdocs_minify_plugin/plugin.py
Expand Up @@ -2,6 +2,7 @@
An MkDocs plugin to minify HTML, JS or CSS files prior to being written to disk
"""
import hashlib
from pathlib import Path
import os
from typing import Callable, Dict, List, Optional, Tuple, Union

Expand Down Expand Up @@ -82,8 +83,23 @@ def _minify(self, file_type: str, config: MkDocsConfig) -> None:
if not isinstance(file_paths, list):
file_paths = [file_paths]

for file_path in file_paths:
site_file_path: str = f"{config['site_dir']}/{file_path}".replace("\\", "/")
file_paths2 = []
for file_path in file_paths.copy():
if "*" in file_path:
glob_parts = file_path.split("*", maxsplit=1)
glob_dir = Path(config['site_dir']) / Path(glob_parts[0])
file_path = glob_dir.glob(f"*{glob_parts[1]}")

for glob_file in file_path:
file_paths2.append(glob_file)
else:
file_paths2.append(Path(config['site_dir']) / file_path)

# remove duplicates
file_paths2 = list(set(file_paths2))

for file_path in file_paths2:
site_file_path: str = str(file_path.as_posix())

with open(site_file_path, mode="r+", encoding="utf8") as file:
if self.config["cache_safe"]:
Expand Down

0 comments on commit 0331da4

Please sign in to comment.