Fix plot links for astro static files

This commit is contained in:
Marty Oehme 2024-07-03 20:00:37 +02:00
parent e90b423ebc
commit 4306a7d246
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
2 changed files with 28 additions and 0 deletions

26
tools/fix-astro-img.py Normal file
View file

@ -0,0 +1,26 @@
#!/usr/bin/env python3
# Replaces all img tags with markdown ![image-tags](./aiming/at/output/dir)
import re
import os
import sys
if not os.getenv("QUARTO_PROJECT_RENDER_ALL"):
sys.exit(0)
q_output_dir = os.getenv("QUARTO_PROJECT_OUTPUT_DIR")
q_output_files = os.getenv("QUARTO_PROJECT_OUTPUT_FILES")
if not q_output_files:
sys.exit(1)
for fname in q_output_files.splitlines():
if not fname.endswith(".md"):
continue
with open(fname, "r") as f:
content = f.read()
modified = re.sub(r'<img src="(.+?)".*/>', r"![fig](./\1)", content)
with open(fname, "w") as f:
f.write(modified)