diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 05dbe59..989b6d5 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -18,8 +18,8 @@ jobs: run: dnf -y update fedora-gpg-keys - name: Install git and Python libraries - run: dnf -y install git-core python3-yaml python3-jinja2 python3-koji python3-pytest python3-flake8 - + run: dnf -y install git-core python3-yaml python3-htmlmin python3-jinja2 python3-koji python3-pytest python3-flake8 + - name: Clean up run: dnf clean all diff --git a/Dockerfile b/Dockerfile index dc24386..3e6101e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/feedback_pipeline.py b/feedback_pipeline.py index 7becd7b..64d6dee 100755 --- a/feedback_pipeline.py +++ b/feedback_pipeline.py @@ -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 @@ -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 @@ -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(":", "--") )) diff --git a/test_feedback_pipeline.py b/test_feedback_pipeline.py index afd880b..77f9945 100644 --- a/test_feedback_pipeline.py +++ b/test_feedback_pipeline.py @@ -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