#!/usr/bin/env bash # Extract klausur-relevant slides from all kapitel # Usage: ./extract-klausur.sh # Output: slides//klausur.md set -e COURSE="${1:-223015b}" SLIDES_DIR="slides/$COURSE" OUTPUT_FILE="$SLIDES_DIR/klausur.md" # Find the first kapitel file (01-*.md) to copy styles from FIRST_KAPITEL=$(ls "$SLIDES_DIR"/01-*.md 2>/dev/null | head -1) if [[ -z "$FIRST_KAPITEL" ]]; then echo "Error: No 01-*.md file found in $SLIDES_DIR" exit 1 fi echo "Extracting klausur slides for $COURSE..." # Extract frontmatter and styles (everything up to first EOF # Extract and copy the cover slide (first slide after frontmatter/styles, up to first ---) awk ' BEGIN { past_style = 0; in_cover = 0; printed = 0 } /<\/style>/ { past_style = 1; next } past_style && !in_cover && /^[^[:space:]]/ { in_cover = 1 } in_cover && /^---$/ { print "---\n"; exit } in_cover { print } ' "$FIRST_KAPITEL" >> "$OUTPUT_FILE" # Process each kapitel file in order - extract klausur slides only for md_file in $(ls "$SLIDES_DIR"/[0-9][0-9]-*.md 2>/dev/null | grep -v klausur | sort); do filename=$(basename "$md_file") kapitel_num=$(echo "$filename" | grep -oE '^[0-9]+' | sed 's/^0*//') # Skip intro (kapitel 0) if [[ "$kapitel_num" == "0" ]] || [[ -z "$kapitel_num" ]]; then continue fi # Check if file has any klausur slides if ! grep -q '' "$md_file"; then continue fi echo " Processing Kapitel $kapitel_num..." # Extract klausur slides, hide header/footer, convert * to - bullets awk ' // { in_klausur = 1 # Add header/footer hiding print "" print "" print "" next } in_klausur && /^---$/ { print "\n---\n" in_klausur = 0 next } in_klausur { # Skip marp directives (we add our own) if (/