Attemopting to minify deploy files.
This commit is contained in:
parent
80cbf81a81
commit
21f024a6c0
3 changed files with 58 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ COPY . .
|
|||
RUN pip install --no-cache-dir -r ./requirements.txt
|
||||
RUN zensical build
|
||||
RUN rm ./deploy/sitemap.xml
|
||||
RUN python minify.py
|
||||
|
||||
FROM caddy:alpine
|
||||
COPY --from=builder /app/deploy /usr/share/caddy
|
||||
|
|
|
|||
54
minify.py
Executable file
54
minify.py
Executable file
|
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Minify CSS, JS, and HTML files in the deploy directory in-place."""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import htmlmin
|
||||
import rcssmin
|
||||
import rjsmin
|
||||
|
||||
DEPLOY_DIR = Path("./deploy")
|
||||
|
||||
|
||||
def minify_css():
|
||||
for css_file in DEPLOY_DIR.rglob("*.css"):
|
||||
content = css_file.read_text(encoding="utf-8")
|
||||
minified = rcssmin.cssmin(content)
|
||||
css_file.write_text(minified, encoding="utf-8")
|
||||
print(f" CSS: {css_file}")
|
||||
|
||||
|
||||
def minify_js():
|
||||
for js_file in DEPLOY_DIR.rglob("*.js"):
|
||||
if js_file.name.endswith(".min.js"):
|
||||
continue
|
||||
content = js_file.read_text(encoding="utf-8")
|
||||
minified = rjsmin.jsmin(content)
|
||||
js_file.write_text(minified, encoding="utf-8")
|
||||
print(f" JS: {js_file}")
|
||||
|
||||
|
||||
def minify_html():
|
||||
for html_file in DEPLOY_DIR.rglob("*.html"):
|
||||
content = html_file.read_text(encoding="utf-8")
|
||||
minified = htmlmin.minify(
|
||||
content,
|
||||
remove_comments=True,
|
||||
remove_empty_space=True,
|
||||
reduce_boolean_attributes=True,
|
||||
)
|
||||
html_file.write_text(minified, encoding="utf-8")
|
||||
print(f" HTML: {html_file}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if not DEPLOY_DIR.exists():
|
||||
print(f"Error: deploy directory not found at {DEPLOY_DIR}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
print("Minifying assets...")
|
||||
minify_css()
|
||||
minify_js()
|
||||
minify_html()
|
||||
print("Done.")
|
||||
|
|
@ -5,6 +5,7 @@ ghp-import==2.1.0
|
|||
griffe==1.15.0
|
||||
griffecli==2.0.0
|
||||
griffelib==2.0.0
|
||||
htmlmin==0.1.12
|
||||
Jinja2==3.1.6
|
||||
Markdown==3.10.2
|
||||
MarkupSafe==3.0.3
|
||||
|
|
@ -22,6 +23,8 @@ pymdown-extensions==10.21
|
|||
python-dateutil==2.9.0.post0
|
||||
PyYAML==6.0.3
|
||||
pyyaml_env_tag==1.1
|
||||
rcssmin==1.2.2
|
||||
rjsmin==1.2.4
|
||||
six==1.17.0
|
||||
watchdog==6.0.0
|
||||
zensical==0.0.27
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue