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
1 changed files with 12 additions and 1 deletions

View File

@ -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):