restructure: rename termin to kapitel, flatten folder structure
- rename slide files: YYYY-MM-DD-termin-N-topic.md → NN-topic.md - flatten folders: courses/X/slides/ → slides/X/ - replace "Termin" with "Kapitel" in all content - add klausur extraction script (make klausur) - update Makefile, generate-index.sh, dev-server.sh - add README.md with full documentation
This commit is contained in:
112
scripts/extract-klausur.sh
Executable file
112
scripts/extract-klausur.sh
Executable file
@@ -0,0 +1,112 @@
|
||||
#!/usr/bin/env bash
|
||||
# Extract klausur-relevant slides from all kapitel
|
||||
# Usage: ./extract-klausur.sh <course_id>
|
||||
# Output: slides/<course>/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 <!-- _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 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 '<!-- _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"
|
||||
Reference in New Issue
Block a user