Skip to content

Commit 8ee3c53

Browse files
committed
Added htmlmin library to minify the web-pages as per minimization#23
1 parent 14880d3 commit 8ee3c53

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from registry.fedoraproject.org/fedora:37
22

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

77
workdir /workspace

feedback_pipeline.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/python3
22

3-
import argparse, yaml, tempfile, os, subprocess, json, jinja2, datetime, copy, re, dnf, pprint, urllib.request, sys, koji
3+
import argparse, yaml, tempfile, os, subprocess, json, jinja2, datetime, copy, re, dnf, pprint, urllib.request, sys, koji, htmlmin
44
import concurrent.futures
55
import rpm_showme as showme
66
from functools import lru_cache
@@ -159,11 +159,13 @@ def load_settings(argv=None):
159159
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.")
160160
parser.add_argument("--dev-buildroot", dest="dev_buildroot", action='store_true', help="Buildroot grows pretty quickly. Use a fake one for development.")
161161
parser.add_argument("--dnf-cache-dir", dest="dnf_cache_dir_override", help="Override the dnf cache_dir.")
162+
parser.add_argument("--htmlmin", dest="htmlmin", action='store_true', help="Run html minimiser while producing the pages.")
162163
args = parser.parse_args(argv)
163164

164165
settings["configs"] = args.configs
165166
settings["output"] = args.output
166167
settings["use_cache"] = args.use_cache
168+
settings["htmlmin"] = args.htmlmin
167169
settings["dev_buildroot"] = args.dev_buildroot
168170
settings["dnf_cache_dir_override"] = args.dnf_cache_dir_override
169171

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

57225724
page = template.render(**template_data)
57235725

5726+
if settings["htmlmin"]:
5727+
try:
5728+
page = htmlmin.minify(page, remove_empty_space=True)
5729+
except Exception as e:
5730+
log(" Minification failed for... ({})".format(filename))
5731+
5732+
57245733
filename = ("{page_name}.html".format(
57255734
page_name=page_name.replace(":", "--")
57265735
))

test_feedback_pipeline.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ def feedback_pipeline_output():
1414
with tempfile.TemporaryDirectory() as tmp:
1515
os.mkdir(f"{tmp}/history")
1616
feedback_pipeline.main([
17-
"--dev-buildroot", "--dnf-cache-dir",
18-
"/tmp/test_cr", "test_configs", tmp])
17+
"--dev-buildroot", "--htmlmin",
18+
"--dnf-cache-dir", "/tmp/test_cr",
19+
"test_configs", tmp])
1920
yield tmp
2021

2122

0 commit comments

Comments
 (0)