fix: make build-slides.sh work with Docker marp by using temp directory with proper permissions

- Process each slide individually to avoid Docker --output flag issues
- Use a temp directory with 777 permissions for Docker to write to
- Copy generated files to final output directory after build
- Both marp-cli and mermaid injection now work properly with Docker

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sjat 2026-05-10 17:49:02 +02:00
parent c6052a8a66
commit 9e5a315c54

View file

@ -3,7 +3,6 @@ set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OUTPUT_DIR="$REPO_ROOT/slides" OUTPUT_DIR="$REPO_ROOT/slides"
mkdir -p "$OUTPUT_DIR"
# Find all markdown files with marp: true frontmatter # Find all markdown files with marp: true frontmatter
SLIDES=() SLIDES=()
@ -19,20 +18,32 @@ fi
echo "Found ${#SLIDES[@]} presentation(s):" echo "Found ${#SLIDES[@]} presentation(s):"
printf ' %s\n' "${SLIDES[@]}" printf ' %s\n' "${SLIDES[@]}"
# Create temp output directory for Docker
TEMP_OUTPUT=$(mktemp -d)
chmod 777 "$TEMP_OUTPUT"
trap "rm -rf '$TEMP_OUTPUT'" EXIT
if command -v marp &>/dev/null; then if command -v marp &>/dev/null; then
marp --html --output "$OUTPUT_DIR/" "${SLIDES[@]}" marp --html --output "$OUTPUT_DIR/" "${SLIDES[@]}"
else else
echo "marp not found locally — using Docker (marpteam/marp-cli)..." echo "marp not found locally — using Docker (marpteam/marp-cli)..."
REL_SLIDES=() # Process each slide individually in Docker
for f in "${SLIDES[@]}"; do for slide in "${SLIDES[@]}"; do
REL_SLIDES+=("${f#"$REPO_ROOT"/}") REL_SLIDE="${slide#${REPO_ROOT}/}"
BASENAME=$(basename "${slide%.*}")
docker run --rm \
-v "$REPO_ROOT":/home/marp/app:ro \
-v "$TEMP_OUTPUT":/home/marp/output \
marpteam/marp-cli --html --output "/home/marp/output/${BASENAME}.html" "$REL_SLIDE"
done done
docker run --rm \
-v "$REPO_ROOT":/home/marp/app:ro \
-v "$OUTPUT_DIR":/home/marp/output \
marpteam/marp-cli --html --output /home/marp/output "${REL_SLIDES[@]}"
fi fi
# Ensure output directory exists
mkdir -p "$OUTPUT_DIR"
# Copy generated HTML files to final output directory
cp "$TEMP_OUTPUT"/*.html "$OUTPUT_DIR/" 2>/dev/null || true
# Inject mermaid.js into any HTML that contains mermaid code blocks. # Inject mermaid.js into any HTML that contains mermaid code blocks.
# Marp emits fenced mermaid blocks as <pre><code class="language-mermaid">. # Marp emits fenced mermaid blocks as <pre><code class="language-mermaid">.
# The script finds those elements, replaces them with <div class="mermaid">, # The script finds those elements, replaces them with <div class="mermaid">,