From 4306a7d246639506aab10323c86319abdd0a55f6 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 3 Jul 2024 20:00:37 +0200 Subject: [PATCH] Fix plot links for astro static files --- _quarto-blog.yml | 2 ++ tools/fix-astro-img.py | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tools/fix-astro-img.py diff --git a/_quarto-blog.yml b/_quarto-blog.yml index cadadf5..a3f0b72 100644 --- a/_quarto-blog.yml +++ b/_quarto-blog.yml @@ -3,6 +3,8 @@ project: output-dir: /home/marty/projects/hosting/webpage/src/content/blog/2024-07-02-nuclear-explosions-analysis render: - index.qmd + post-render: + - tools/fix-astro-img.py format: hugo-md: diff --git a/tools/fix-astro-img.py b/tools/fix-astro-img.py new file mode 100644 index 0000000..c4badde --- /dev/null +++ b/tools/fix-astro-img.py @@ -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'', r"![fig](./\1)", content) + + with open(fname, "w") as f: + f.write(modified)