#!/usr/bin/env bash
set -e

if [ -z "$1" ]; then
  echo "Usage: ./build.sh <file.md> [pdf|html|both]"
  exit 1
fi

SRC="$1"
BASE="${SRC%.md}"
FORMAT="${2:-both}"

MARP="npx @marp-team/marp-cli@latest --no-stdin --html --theme upshift-theme.css --allow-local-files --image-scale 1"

if [ "$FORMAT" = "pdf" ] || [ "$FORMAT" = "both" ]; then
  $MARP "$SRC" -o "${BASE}.pdf"
fi

if [ "$FORMAT" = "html" ] || [ "$FORMAT" = "both" ]; then
  $MARP "$SRC" -o "${BASE}.html"
  sed -i 's|</head>|<link rel="icon" type="image/svg+xml" href="logo.svg"></head>|' "${BASE}.html"
fi
