rework dev server: hmr for all courses, per-course targets, root index

- make dev serves all courses on port 1312 with marp live reload
- make dev-b/dev-c for single course on 1313/1314
- dev-kill only kills specific ports instead of all marp processes
- add generate-root-index.sh for prod build overview page
- cleanup function uses exec + trap instead of pid files
This commit is contained in:
2026-04-09 22:10:48 +02:00
parent c1277cc737
commit c57db78c52
4 changed files with 198 additions and 39 deletions

View File

@@ -1,12 +1,16 @@
#!/usr/bin/env bash
# Simplified development server for HdM slides
# Starts single Marp server for all courses
# Development server for HdM slides
# Usage:
# ./dev-server.sh - Marp live server for all courses (port 1312)
# ./dev-server.sh 223015b 1313 - Marp live server for single course
# ./dev-server.sh 223015c 1314 - Marp live server for single course
set -e
# Configuration
SLIDES_DIR="slides"
DEV_PORT=3000
COURSE="${1:-}"
DEV_PORT="${2:-1312}"
# Colors
GREEN='\033[0;32m'
@@ -14,40 +18,27 @@ BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Cleanup function
cleanup() {
echo -e "\n${RED}Shutting down dev server...${NC}"
pkill -f "marp-cli.*--server" 2>/dev/null || true
exit 0
}
# Kill existing processes on our port
kill_existing() {
echo -e "${BLUE}Cleaning up existing processes...${NC}"
pkill -9 -f "marp-cli" 2>/dev/null || true
fuser -k $DEV_PORT/tcp 2>/dev/null || true
sleep 1
# Kill existing process on our port only
kill_port() {
fuser -k "$DEV_PORT/tcp" 2>/dev/null || true
sleep 0.5
}
# Main
trap cleanup SIGINT SIGTERM
trap 'echo -e "\n${RED}Shutting down...${NC}"; kill 0; exit 0' SIGINT SIGTERM
kill_existing
kill_port
echo -e "${GREEN}Starting development server...${NC}"
echo ""
echo -e " Server: ${BLUE}http://localhost:$DEV_PORT${NC}"
echo -e " Slides: ${BLUE}$SLIDES_DIR/${NC}"
echo ""
echo -e "Available courses:"
echo -e " 223015b: ${BLUE}http://localhost:$DEV_PORT/223015b/${NC}"
echo -e " 223015c: ${BLUE}http://localhost:$DEV_PORT/223015c/${NC}"
echo ""
echo -e "Press ${RED}Ctrl+C${NC} to stop the server"
if [ -n "$COURSE" ]; then
SERVE_DIR="$SLIDES_DIR/$COURSE"
echo -e "${GREEN}Marp dev server${NC} · ${BLUE}$COURSE${NC}"
else
SERVE_DIR="$SLIDES_DIR"
echo -e "${GREEN}Marp dev server${NC} · ${BLUE}all courses${NC}"
fi
echo -e " ${BLUE}http://localhost:$DEV_PORT${NC}"
echo -e " ${BLUE}$SERVE_DIR/${NC}"
echo ""
# Start single Marp server for all slides
PORT=$DEV_PORT npx @marp-team/marp-cli --server "$SLIDES_DIR/"
# Wait for process to exit
wait
PORT=$DEV_PORT exec npx @marp-team/marp-cli --server "$SERVE_DIR/"