#!/bin/sh # ZODIAC - a simple static site generator # Copyright (c) 2011 Chase Allen James zod_lib=ZODLIB_PATH markdown_filter_cmd="awk -f $zod_lib/markdown.awk" proj=$1 target=$2 _zod_error() { echo -e ">>> ERROR: $*" >&2 exit 1 } [ ! "$1" ] || [ ! "$2" ] && { echo "usage: zod projectdir targetdir"; exit; } [ ! -d $proj ] && _zod_error "project directory does not exist" [ ! -d $target ] && _zod_error "target directory does not exist" helpers=$proj/helpers.awk [ -f $helpers ] && helper_opts="-f $(pwd)/$helpers" global_meta=$proj/global.meta [ -f $global_meta ] && global_meta_opts=$global_meta layout=$proj/main.layout [ -f $layout ] && layout_opts=$layout files=$(find $proj -type f \ ! -name "*.layout" \ ! -name "*.meta" \ ! -name "helpers.awk") for f in $files; do # Find the target directory if one must be created subdir=${f%/*} subdir=${subdir#$proj} if [ "$subdir" ]; then destination="$target$subdir" mkdir -p "$destination" else # There is no directory to create in target, # i.e. file is in the root of the project destination=$target fi ext=${f##*.} if [ $ext == "md" ] || [ $ext == "html" ]; then meta=${f%.$ext}.meta [ -f $meta ] && page_meta_opts=$meta [ $ext == "md" ] && filter_opts="" page=${f##*/} page=${page%.$ext}.html awk -f $zod_lib/render.awk \ -v markdown_filter_cmd="$markdown_filter_cmd" \ $helper_opts \ "$global_meta_opts" \ "$page_meta_opts" \ "$f" \ "$layout_opts" > "$destination/$page" else cp "$f" "$destination" # Copying a non-template file fi done