1
Fork 0

Add title to diagram filename

This commit is contained in:
Jake Howard 2023-09-15 21:41:46 +01:00
parent 2f94dc4231
commit 5f5a057c34
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 8 additions and 3 deletions

View file

@ -10,6 +10,7 @@ from mkdocs.utils import write_file
import os
from py_svg_hush import filter_svg
from scour.scour import scourString
from slugify import slugify
logger = get_plugin_logger("kroki")
@ -30,13 +31,16 @@ def get_kroki_diagram(source, language):
def fence_div_format(site_dir, source, language, *args, attrs, **kwargs):
try:
title = attrs.get("title")
title = attrs.get("title", "")
diagram = get_kroki_diagram(source, language)
filename = hashlib.md5(source.encode()).hexdigest() + ".svg"
filename = hashlib.md5(source.encode()).hexdigest()[:12] + ".svg"
image_url = f"/_gen/kroki/{language}/{filename}"
if title:
filename = "-".join([slugify(title)[:32].rstrip("-"), filename])
image_url = f"/_gen/kroki/{filename}"
write_file(diagram, os.path.join(site_dir, image_url.removeprefix("/")))

View file

@ -6,3 +6,4 @@ minify-html
beautifulsoup4
py-svg-hush
scour
python-slugify