|
| 1 | +#!/bin/bash |
| 2 | +# marpit.sh: Build Marp talks to HTML and generate index |
| 3 | +set -e |
| 4 | +# Change to the directory where this script is located |
| 5 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 6 | +cd "$SCRIPT_DIR/.." |
| 7 | + |
| 8 | +# Create public directory if not present |
| 9 | +mkdir -p public |
| 10 | +grep -v '^#' .marp-talks | while IFS= read -r file; do |
| 11 | + echo "seen $file" |
| 12 | +done |
| 13 | + |
| 14 | + |
| 15 | +# Build Marp talks to HTML |
| 16 | +files=() |
| 17 | +while IFS= read -r line; do |
| 18 | + files+=("$line") |
| 19 | +done < <(grep -v '^#' .marp-talks) # Extract lines to an array |
| 20 | + |
| 21 | +for file in "${files[@]}"; do |
| 22 | + file="$(echo "$file" | xargs)" # Trim whitespace at the beginning and end of the line |
| 23 | + echo "Processing $file" |
| 24 | + [ -z "$file" ] && continue |
| 25 | + # Vérification que le fichier existe |
| 26 | + if [ ! -f "$file" ]; then |
| 27 | + echo "File $file does not exist. Skipping." |
| 28 | + continue |
| 29 | + fi |
| 30 | + # Relative path without extension |
| 31 | + relpath="${file%.md}" |
| 32 | + # Source directory (where the .md is) |
| 33 | + srcdir=$(dirname "$file") |
| 34 | + # Target directory in public/ |
| 35 | + dstdir="public/$srcdir" |
| 36 | + mkdir -p "$dstdir" |
| 37 | + # Copy all contents from the source directory (files and subdirectories) |
| 38 | + if [ -d "$srcdir" ]; then |
| 39 | + cp -r "$srcdir"/* "$dstdir"/ 2>/dev/null || true |
| 40 | + fi |
| 41 | + # Generate the HTML and PDF in the target directory |
| 42 | + out_html="$(basename "$file" .md).html" |
| 43 | + out_pdf="$(basename "$file" .md).pdf" |
| 44 | + marp --html --allow-local-files "$file" -o "$dstdir/$out_html" |
| 45 | + marp --pdf --allow-local-files "$file" -o "$dstdir/$out_pdf" |
| 46 | + |
| 47 | + # Check if HTML file was generated and report its size |
| 48 | + htmlpath="$dstdir/$out_html" |
| 49 | + if [ -f "$htmlpath" ]; then |
| 50 | + size=$(stat -c %s "$htmlpath" 2>/dev/null || stat -f %z "$htmlpath" 2>/dev/null) |
| 51 | + echo "Generated $htmlpath ($size bytes)" |
| 52 | + else |
| 53 | + echo "File $htmlpath was not generated." |
| 54 | + fi |
| 55 | + |
| 56 | + # Check if PDF file was generated and report its size |
| 57 | + pdfpath="$dstdir/$out_pdf" |
| 58 | + if [ -f "$pdfpath" ]; then |
| 59 | + size=$(stat -c %s "$pdfpath" 2>/dev/null || stat -f %z "$pdfpath" 2>/dev/null) |
| 60 | + echo "Generated $pdfpath ($size bytes)" |
| 61 | + else |
| 62 | + echo "File $pdfpath was not generated." |
| 63 | + fi |
| 64 | +done |
| 65 | + |
| 66 | +echo "All talks processed." |
| 67 | +# Add index.html listing all talks |
| 68 | +echo '<!DOCTYPE html><html><head><meta charset="utf-8"><title>simdjson's talks</title><link rel="stylesheet" href="styles.css"></head><body><h1>simdjson's talks</h1>' > public/index.html |
| 69 | +# Collect all talks and years |
| 70 | +awk 'BEGIN{FS="/"} /^[^#]/ && NF>0 { year=$1; talks[year]=talks[year] $0 "\n"; years[year]=1 } END { for (y in years) print y }' .marp-talks | sort -r > years.txt |
| 71 | +while read year; do |
| 72 | + [ -z "$year" ] && continue |
| 73 | + echo "<h2>$year</h2><ul>" >> public/index.html |
| 74 | + grep "^$year/" .marp-talks | while read file; do |
| 75 | + [ -z "$file" ] && continue |
| 76 | + case "$file" in \#*) continue ;; esac |
| 77 | + relpath="${file%.md}" |
| 78 | + htmlpath="$relpath.html" |
| 79 | + pdfpath="$relpath.pdf" |
| 80 | + title=$(grep -m 1 '^title:' "$file" | sed 's/^title: //') |
| 81 | + description=$(grep -m 1 '^description:' "$file" | sed 's/^description: //') |
| 82 | + echo "<li><a href='$htmlpath' title='$description'>$title</a> <a href='$pdfpath' title='$description'>PDF</a></li>" >> public/index.html |
| 83 | + done |
| 84 | + echo "</ul>" >> public/index.html |
| 85 | +done < years.txt |
| 86 | +rm years.txt |
| 87 | +echo '</body></html>' >> public/index.html |
| 88 | +cp css/styles.css public/ || true |
0 commit comments