#!/usr/bin/env bash # Marp Docker Image IMAGE="marpteam/marp-cli:latest" # Display usage instructions usage() { echo "Usage:" echo " $0 init - Pulls or updates the Marp Docker image." echo " $0 serve [port] - Serves the specified directory via Docker (Default port: 8080)." echo " $0 convert - Converts the file to the specified format (pdf, pptx, html, png, jpeg)." exit 1 } # Check argument count if [ $# -lt 1 ]; then usage fi COMMAND=$1 shift case "$COMMAND" in init) echo "Pulling Marp Docker image..." docker pull "$IMAGE" echo "Initialization complete." ;; serve) TARGET_DIR=$1 PORT=${2:-8080} if [ -z "$TARGET_DIR" ]; then echo "Error: Please specify a directory." echo "Example: $0 serve ./presentations 8080" exit 1 fi DIR=$(realpath "$TARGET_DIR") if [ ! -d "$DIR" ]; then echo "Error: '$TARGET_DIR' is not a valid directory." exit 1 fi echo "Serving directory '$DIR' at http://localhost:$PORT (Press Ctrl+C to stop)..." docker run --rm -it --init \ -v "$DIR:/home/marp/app" \ -p "$PORT:8080" \ "$IMAGE" \ -s /home/marp/app \ --allow-local-files ;; convert) FILE=$1 FORMAT=$2 if [ -z "$FILE" ] || [ -z "$FORMAT" ]; then echo "Error: Missing parameters." echo "Usage: $0 convert " echo "Example: $0 convert presentation.md pdf" exit 1 fi DIR=$(dirname "$(realpath "$FILE")") BASENAME=$(basename "$FILE") OUTPUT_FILE="$(basename "$BASENAME" .md).$FORMAT" echo "Converting '$FILE' to '$FORMAT' format..." docker run --rm --init \ -v "$DIR:/home/marp/app" \ "$IMAGE" \ "/home/marp/app/$BASENAME" \ --output "/home/marp/app/$OUTPUT_FILE" \ --allow-local-files echo "Conversion completed: $OUTPUT_FILE" ;; *) echo "Invalid command: $COMMAND" usage ;; esac