Skip to content

Commit 2746ba9

Browse files
fix: copy zh figure files after babelquarto render to restore broken images on zh pages (#299)
Agent-Logs-Url: https://github.com/openbiox/Bizard/sessions/55282061-380e-4d5d-bfbf-b4a691672a72 Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
1 parent 844ee69 commit 2746ba9

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

.github/workflows/quarto-publish-update-cache.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,38 @@ jobs:
324324
QUARTO_JULIA_PROJECT: ${{ env.QUARTO_JULIA_PROJECT }}
325325
run: Rscript -e 'babelquarto::render_website()'
326326

327+
# ── Fix zh page figure files ──────────────────────────────
328+
# See quarto-publish.yml for full explanation. Short version: the
329+
# frozen chunk HTML in *.zh.qmd freeze entries references
330+
# <name>.zh_files/figure-html/ but babelquarto never places the actual
331+
# PNG files there. Copy the identical English figures over.
332+
- name: Fix zh page figure files
333+
run: |
334+
echo "Copying figure files into zh output directories..."
335+
COPIED=0
336+
while IFS= read -r -d '' zh_html; do
337+
zh_dir=$(dirname "$zh_html")
338+
name=$(basename "$zh_html" .html)
339+
340+
rel="${zh_dir#_site/zh}"
341+
rel="${rel#/}"
342+
343+
if [ -z "$rel" ]; then
344+
eng_files="_site/${name}_files"
345+
else
346+
eng_files="_site/${rel}/${name}_files"
347+
fi
348+
349+
zh_files="${zh_dir}/${name}.zh_files"
350+
351+
if [ -d "$eng_files" ] && [ ! -d "$zh_files" ]; then
352+
cp -r "$eng_files" "$zh_files"
353+
echo " ✓ Copied: $eng_files → $zh_files"
354+
COPIED=$((COPIED+1))
355+
fi
356+
done < <(find _site/zh -name "*.html" -print0)
357+
echo "✅ Done: copied figure files for ${COPIED} zh pages"
358+
327359
- name: Check disk usage after rendering
328360
run: |
329361
echo "=== Final Disk Usage ==="

.github/workflows/quarto-publish.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,46 @@ jobs:
467467
QUARTO_JULIA_PROJECT: ${{ env.QUARTO_JULIA_PROJECT }}
468468
run: Rscript -e 'babelquarto::render_website()'
469469

470+
# ── Fix zh page figure files ──────────────────────────────
471+
# ROOT CAUSE: babelquarto renames <name>.zh.qmd → <name>.qmd before
472+
# rendering the zh pass, but the frozen chunk HTML still references
473+
# <name>.zh_files/figure-html/ (the path from when the file was named
474+
# <name>.zh.qmd). The actual figure PNGs are never placed at that path
475+
# because code is not re-executed (freeze is used). The English figures
476+
# live at _site/<category>/<name>_files/ and are identical (zh .qmd
477+
# files share the same code blocks as their English counterparts).
478+
# FIX: after babelquarto finishes, copy the English <name>_files/ tree
479+
# into _site/zh/<category>/<name>.zh_files/ for every zh HTML page
480+
# that references a missing *.zh_files/ directory.
481+
- name: Fix zh page figure files
482+
run: |
483+
echo "Copying figure files into zh output directories..."
484+
COPIED=0
485+
while IFS= read -r -d '' zh_html; do
486+
zh_dir=$(dirname "$zh_html")
487+
name=$(basename "$zh_html" .html)
488+
489+
# Relative path from _site/zh (may be empty for root-level pages)
490+
rel="${zh_dir#_site/zh}"
491+
rel="${rel#/}"
492+
493+
# Corresponding English _files directory
494+
if [ -z "$rel" ]; then
495+
eng_files="_site/${name}_files"
496+
else
497+
eng_files="_site/${rel}/${name}_files"
498+
fi
499+
500+
zh_files="${zh_dir}/${name}.zh_files"
501+
502+
if [ -d "$eng_files" ] && [ ! -d "$zh_files" ]; then
503+
cp -r "$eng_files" "$zh_files"
504+
echo " ✓ Copied: $eng_files → $zh_files"
505+
COPIED=$((COPIED+1))
506+
fi
507+
done < <(find _site/zh -name "*.html" -print0)
508+
echo "✅ Done: copied figure files for ${COPIED} zh pages"
509+
470510
# ── Save freeze cache (ALWAYS – even on failure) ─────────
471511
# This is the key to reducing wasted work across consecutive
472512
# failed builds. Even if the render fails on file #400,

0 commit comments

Comments
 (0)