1
Fork 0

Optimise SVG compression

Actually strip out some tags and newlines
This commit is contained in:
Jake Howard 2023-09-18 11:26:42 +01:00
parent 4d36f4f1e3
commit 61f0bd2a43
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -21,12 +21,23 @@ DIAGRAM_TYPES = {
DIAGRAM_CACHE_TIME = timedelta(days=7) 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): def get_kroki_diagram(source, language):
encoded_diagram = base64.urlsafe_b64encode(zlib.compress(source.encode(), 9)).decode() 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) 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): def fence_div_format(site_dir, source, language, *args, attrs, **kwargs):