#!/usr/bin/env sh

BLOG_DIR=${BLOG_DIR:-$PWD}
BLOG_TITLE="zane.town"
BLOG_URL="https://$BLOG_TITLE"
POSTS_DIR="$BLOG_DIR/posts"
IMAGES_DIR="$BLOG_DIR/images"
TREE_FLAGS="--dirsfirst --info -C -L 1"
TREE_IGNORES="-I gen -I index.html"

/usr/local/bin/tree $TREE_FLAGS $TREE_IGNORES -H $BLOG_URL -T $BLOG_TITLE > index.html

if [ -f "$IMAGES_DIR/generate.sh" ]; then
  cd $IMAGES_DIR && sh "$IMAGES_DIR/generate.sh"
else
  echo "images/generate.sh not found"
fi

if [ -f "$POSTS_DIR/generate.sh" ]; then
  cd $POSTS_DIR && sh "$POSTS_DIR/generate.sh"
else
  echo "posts/generate.sh not found"
fi

echo "Done!"
