From 61f0bd2a4347f6ee258ea039ed69ef173a5a4cc7 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Mon, 18 Sep 2023 11:26:42 +0100 Subject: [PATCH] Optimise SVG compression Actually strip out some tags and newlines --- hooks/kroki.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/hooks/kroki.py b/hooks/kroki.py index 39a2629..5cf1b15 100644 --- a/hooks/kroki.py +++ b/hooks/kroki.py @@ -21,12 +21,23 @@ DIAGRAM_TYPES = { DIAGRAM_CACHE_TIME = timedelta(days=7) + +class ScourOptions: + """ + Scour takes its options as a class with attributes, because reasons + """ + remove_descriptions = True + remove_metadata = True + strip_comments = True + newlines = False + + def get_kroki_diagram(source, language): encoded_diagram = base64.urlsafe_b64encode(zlib.compress(source.encode(), 9)).decode() svg = download_and_cache_url(f"https://kroki.io/{language}/svg/{encoded_diagram}", DIAGRAM_CACHE_TIME) - return scourString(filter_svg(svg)).encode() + return scourString(filter_svg(svg), ScourOptions).encode() def fence_div_format(site_dir, source, language, *args, attrs, **kwargs):