Files
uni/scripts/generate-index.sh
Michael Czechowski fa7faab48f add index.html generator script
generates styled course overview with pdf links and qr codes
2025-12-30 11:30:29 +01:00

162 lines
4.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Generate index.html for slide overview
# Usage: ./generate-index.sh <course_id> <build_dir>
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
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>$TITLE</title>
<style>
* { box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 2rem;
background: #1a1a2e;
color: #eee;
}
h1 { color: #fff; margin-bottom: 0.5rem; }
.subtitle { color: #888; margin-bottom: 2rem; }
.termin-row {
display: flex;
align-items: center;
gap: 1rem;
margin-bottom: 1rem;
}
.termin {
background: #16213e;
border-radius: 8px;
padding: 1.5rem;
text-decoration: none;
display: block;
flex: 1;
transition: transform 0.2s, background 0.2s;
}
.termin:hover { background: #1f4068; transform: translateX(5px); }
.termin h2 { color: #fff; margin: 0 0 0.5rem 0; font-size: 1.2rem; }
.termin .date { color: #4ecca3; font-size: 0.9rem; }
.termin .topic { color: #aaa; font-size: 0.95rem; margin-left: 1rem; }
.pdf {
background: #e94560;
color: #fff;
padding: 0.5rem 1rem;
border-radius: 4px;
text-decoration: none;
font-size: 0.85rem;
font-weight: 500;
transition: background 0.2s;
}
.pdf:hover { background: #ff6b6b; }
.qr-section {
margin-top: 2rem;
text-align: center;
}
.qr-section img {
max-width: 150px;
border-radius: 8px;
background: #fff;
padding: 0.5rem;
}
footer { margin-top: 2rem; color: #666; font-size: 0.85rem; text-align: center; }
footer a { color: #4ecca3; }
</style>
</head>
<body>
<h1>$COURSE</h1>
<p class="subtitle">$SUBTITLE<br>
HdM Stuttgart - WS 2025/26 - Michael Czechowski</p>
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="<a href=\"$pdf_filename\" class=\"pdf\">PDF</a>"
fi
cat >> "$BUILD_DIR/index.html" << LINK
<div class="termin-row">
<a href="$filename" class="termin">
<h2>$termin_label</h2>
<span class="date">$formatted_date</span>
<span class="topic">$topic</span>
</a>
$pdf_link
</div>
LINK
done
# Add QR code if exists
if [[ -f "$BUILD_DIR/qr-$COURSE.png" ]]; then
cat >> "$BUILD_DIR/index.html" << QRSECTION
<div class="qr-section">
<img src="qr-$COURSE.png" alt="QR Code">
<p style="color: #888; font-size: 0.8rem;">Scan to open on mobile</p>
</div>
QRSECTION
fi
cat >> "$BUILD_DIR/index.html" << FOOTER
<footer>
<a href="$REPO_URL">Git Repository</a> -
<a href="mailto:mail@librete.ch">Kontakt</a>
</footer>
</body>
</html>
FOOTER
echo "Generated $BUILD_DIR/index.html"