COURSE="${1:-223015b}"
BUILD_DIR="${2:-build/$COURSE}"
# Course-specific configuration
case "$COURSE" in
223015b)
TITLE="223015b - Dateiformate, Schnittstellen, Speichermedien"
SUBTITLE="Dateiformate, Schnittstellen, Speichermedien & Distributionswege"
REPO_URL="https://git.librete.ch/hdm/223015b"
;;
223015c)
TITLE="223015c - Internettechnologien"
SUBTITLE="Internettechnologien"
REPO_URL="https://git.librete.ch/hdm/223015c"
;;
*)
TITLE="$COURSE - HdM Slides"
SUBTITLE="Lecture Slides"
REPO_URL="https://git.librete.ch/hdm/$COURSE"
;;
esac
cat > "$BUILD_DIR/index.html" << HEADER
$TITLE
$COURSE
$SUBTITLE
HdM Stuttgart - WS 2025/26 - Michael Czechowski
HEADER
# Generate links for each termin (sorted)
for html in $(ls "$BUILD_DIR"/2*.html 2>/dev/null | sort); do
filename=$(basename "$html")
# Extract components from filename
date=$(echo "$filename" | grep -oE '^[0-9]{4}-[0-9]{2}-[0-9]{2}')
termin_num=$(echo "$filename" | grep -oE 'termin-[0-9]+' | grep -oE '[0-9]+')
topic_raw=$(echo "$filename" | sed -E 's/^[0-9]{4}-[0-9]{2}-[0-9]{2}-termin-[0-9]+-//' | sed 's/\.html$//')
# Format topic: replace - with space, capitalize
topic=$(echo "$topic_raw" | sed 's/-/ /g' | sed 's/.*/\u&/')
# Format date
if [[ "$date" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
formatted_date=$(date -d "$date" "+%d.%m.%Y" 2>/dev/null || echo "$date")
else
formatted_date="TBA"
fi
# Handle termin number
if [[ "$termin_num" == "0" ]]; then
termin_label="Einfuhrung"
else
termin_label="Termin $termin_num"
fi
pdf_filename="${filename%.html}.pdf"
# Check if PDF exists
pdf_link=""
if [[ -f "$BUILD_DIR/$pdf_filename" ]]; then
pdf_link="PDF"
fi
cat >> "$BUILD_DIR/index.html" << LINK
LINK
done
# Add QR code if exists
if [[ -f "$BUILD_DIR/qr-$COURSE.png" ]]; then
cat >> "$BUILD_DIR/index.html" << QRSECTION
Scan to open on mobile
QRSECTION
fi
cat >> "$BUILD_DIR/index.html" << FOOTER
FOOTER
echo "Generated $BUILD_DIR/index.html"