Files
uni/scripts/extract-klausur.sh
Michael Czechowski 9e12447528 rebuild dev and build system with single marp server
- simplify development: single marp server on port 3000 instead of 3 processes
- rename klausur to klausurfolien for better naming
- update extract script to use 00-intro.md as template when no 01-*.md exists
- update makefile and package.json for new workflow
- add comprehensive AGENTS.md guidelines
2026-02-01 18:17:51 +01:00

113 lines
3.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Extract klausur-relevant slides from all kapitel
# Usage: ./extract-klausur.sh <course_id>
# Output: slides/<course>/klausurfolien.md
set -e
COURSE="${1:-223015b}"
SLIDES_DIR="slides/$COURSE"
OUTPUT_FILE="$SLIDES_DIR/klausurfolien.md"
# Find the first kapitel file (00-intro.md or 01-*.md) to copy styles from
FIRST_KAPITEL=$(ls "$SLIDES_DIR"/00-intro.md "$SLIDES_DIR"/01-*.md 2>/dev/null | head -1)
if [[ -z "$FIRST_KAPITEL" ]]; then
echo "Error: No 00-intro.md or 01-*.md file found in $SLIDES_DIR"
exit 1
fi
echo "Extracting klausur slides for $COURSE..."
# Extract frontmatter and styles (everything up to first <!-- _class: line after style block)
# This gets the YAML frontmatter + <style> block
awk '
BEGIN { in_frontmatter = 0; in_style = 0; done = 0 }
/^---$/ && !in_frontmatter { in_frontmatter = 1; print; next }
/^---$/ && in_frontmatter && !in_style { in_frontmatter = 0; print; next }
in_frontmatter { print; next }
/<style>/ { in_style = 1; print; next }
/<\/style>/ { in_style = 0; print; print ""; done = 1; next }
in_style { print; next }
done { exit }
' "$FIRST_KAPITEL" > "$OUTPUT_FILE"
# Add warning comment
cat >> "$OUTPUT_FILE" << 'EOF'
<!--
╔═══════════════════════════════════════════════════════════════════╗
║ AUTO-GENERATED FILE - DO NOT EDIT MANUALLY ║
║ ║
║ This file is generated by: make klausur ║
║ Source: scripts/extract-klausur.sh ║
║ ║
║ To update, edit the source slides and re-run make klausur ║
╚═══════════════════════════════════════════════════════════════════╝
-->
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 klausurfolien | 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 '<!-- _class: klausur -->' "$md_file"; then
continue
fi
echo " Processing Kapitel $kapitel_num..."
# Extract klausur slides, hide header/footer, convert * to - bullets
awk '
/<!-- _class: klausur -->/ {
in_klausur = 1
# Add header/footer hiding
print "<!-- _header: \"\" -->"
print "<!-- _footer: \"\" -->"
print ""
next
}
in_klausur && /^---$/ {
print "\n---\n"
in_klausur = 0
next
}
in_klausur {
# Skip marp directives (we add our own)
if (/<!-- _header:/ || /<!-- _footer:/ || /<!-- _backgroundColor:/) next
# Convert * bullets to - bullets (avoid fragments)
gsub(/^\* /, "- ")
gsub(/^ \* /, " - ")
gsub(/^ \* /, " - ")
print
}
' "$md_file" >> "$OUTPUT_FILE"
done
# Remove trailing --- and empty lines
perl -i -0777 -pe 's/\n*---\n*$/\n/' "$OUTPUT_FILE"
# Count slides
slide_count=$(grep -c '^---$' "$OUTPUT_FILE" 2>/dev/null || echo "0")
echo ""
echo "Generated: $OUTPUT_FILE"
echo "Total slides: $slide_count"