Add title to diagram filename
This commit is contained in:
parent
2f94dc4231
commit
5f5a057c34
2 changed files with 8 additions and 3 deletions
|
@ -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("/")))
|
||||
|
||||
|
|
|
@ -6,3 +6,4 @@ minify-html
|
|||
beautifulsoup4
|
||||
py-svg-hush
|
||||
scour
|
||||
python-slugify
|
||||
|
|
Loading…
Reference in a new issue