Skip to content

Commit

Permalink
Added htmlmin library to minify the web-pages as per minimization#23
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamSaleh committed Jan 24, 2023
1 parent 14880d3 commit 8ee3c53
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from registry.fedoraproject.org/fedora:37

run dnf -y update fedora-gpg-keys && \
dnf -y install git python3-pytest python3-pytest-cov python3-jinja2 python3-koji python3-yaml && \
dnf -y install git python3-pytest python3-htmlmin python3-pytest-cov python3-jinja2 python3-koji python3-yaml && \
dnf clean all

workdir /workspace
Expand Down
11 changes: 10 additions & 1 deletion feedback_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python3

import argparse, yaml, tempfile, os, subprocess, json, jinja2, datetime, copy, re, dnf, pprint, urllib.request, sys, koji
import argparse, yaml, tempfile, os, subprocess, json, jinja2, datetime, copy, re, dnf, pprint, urllib.request, sys, koji, htmlmin
import concurrent.futures
import rpm_showme as showme
from functools import lru_cache
Expand Down Expand Up @@ -159,11 +159,13 @@ def load_settings(argv=None):
parser.add_argument("--use-cache", dest="use_cache", action='store_true', help="Use local data instead of pulling Content Resolver. Saves a lot of time! Needs a 'cache_data.json' file at the same location as the script is at.")
parser.add_argument("--dev-buildroot", dest="dev_buildroot", action='store_true', help="Buildroot grows pretty quickly. Use a fake one for development.")
parser.add_argument("--dnf-cache-dir", dest="dnf_cache_dir_override", help="Override the dnf cache_dir.")
parser.add_argument("--htmlmin", dest="htmlmin", action='store_true', help="Run html minimiser while producing the pages.")
args = parser.parse_args(argv)

settings["configs"] = args.configs
settings["output"] = args.output
settings["use_cache"] = args.use_cache
settings["htmlmin"] = args.htmlmin
settings["dev_buildroot"] = args.dev_buildroot
settings["dnf_cache_dir_override"] = args.dnf_cache_dir_override

Expand Down Expand Up @@ -5721,6 +5723,13 @@ def _generate_html_page(template_name, template_data, page_name, settings):

page = template.render(**template_data)

if settings["htmlmin"]:
try:
page = htmlmin.minify(page, remove_empty_space=True)
except Exception as e:
log(" Minification failed for... ({})".format(filename))


filename = ("{page_name}.html".format(
page_name=page_name.replace(":", "--")
))
Expand Down
5 changes: 3 additions & 2 deletions test_feedback_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ def feedback_pipeline_output():
with tempfile.TemporaryDirectory() as tmp:
os.mkdir(f"{tmp}/history")
feedback_pipeline.main([
"--dev-buildroot", "--dnf-cache-dir",
"/tmp/test_cr", "test_configs", tmp])
"--dev-buildroot", "--htmlmin",
"--dnf-cache-dir", "/tmp/test_cr",
"test_configs", tmp])
yield tmp


Expand Down

0 comments on commit 8ee3c53

Please sign in to comment.