#!/bin/sh # ZODIAC - a simple static site generator # Copyright (c) 2011 Chase Allen James ZODLIB=ZODLIB_PATH proj=$1 target=$2 if [ -z "$1" ] || [ -z "$2" ]; then echo "usage: zod projectdir targetdir" exit fi if [ ! -e $proj ]; then echo "error: project directory does not exist" exit fi if [ ! -e $target ]; then echo "error: target directory does not exist" exit fi helpers=$proj/helpers.awk if [ -e $helpers ]; then helper_opts="-f `pwd`/$helpers" fi global_meta=$proj/global.meta if [ -e $global_meta ]; then global_meta_opts=$global_meta fi layout=$proj/main.layout if [ -e $layout ]; then layout_opts=$layout fi files=$(find $proj -type f ! -name "*.layout" ! -name "*.meta" ! -name "*.awk") for f in $files; do dir=$(dirname $f) # Find the target directory if one must be created # Start by pulling the project directory out of the filepath # with awk and then removing the filename with sed targetdir=$(awk "BEGIN { split(\"$f\",a,\"$proj/\"); print a[2] }" | sed "s/`basename $f`//") targetpath=$target/$targetdir if [ ! -z "$targetdir" ]; then mkdir -p $target/$targetdir else # There is no directory to create in target, # i.e. file is in the root of the project targetpath=$target fi file_basename=$(basename $f) file_extension=$(echo $file_basename | awk -F . '{print $NF}') file_name=$(echo $file_basename | sed -e 's/\.md//' -e 's/\.html//') # If the file's extension wasn't replaced (i.e. same as basename) then # we know it isn't a template. if [ $file_name != $file_basename ]; then if [ -e $dir/$file_name.meta ]; then page_meta_opts=$dir/$file_name.meta fi awk -f $ZODLIB/render.awk \ -v AWKLIB="$ZODLIB" \ $helper_opts \ $global_meta_opts \ $page_meta_opts \ $f \ $layout_opts > $targetpath/$file_name.html else cp $f $targetpath # Copying a non-template file fi done