#!/bin/bash

ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
TARGET="$ROOT/build"
CONTENT="$ROOT/content"
COMMON_OPTIONS="--defaults "$ROOT/defaults.yaml""
FILENAME="l-humain-cette-espece-primitive"
EPUBCHECK="/opt/epubcheck-4.2.4/epubcheck.jar"

if [ -d "$TARGET" ]; then rm -rf "$TARGET"; fi

hunspell content/**/*.md

# epub
mkdir -p $TARGET/epub
pandoc $COMMON_OPTIONS -o "$ROOT/build/epub/$FILENAME.epub"
java -jar $EPUBCHECK "$ROOT/build/epub/$FILENAME.epub"

# html
mkdir -p $TARGET/html
pandoc $COMMON_OPTIONS -o "$ROOT/build/html/$FILENAME.html"

# pdf
mkdir -p $TARGET/pdf
pandoc $COMMON_OPTIONS -o "$ROOT/build/pdf/$FILENAME.pdf"