2011-09-22 17:28:24 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# ZODIAC - a simple static site generator
|
2011-09-22 17:43:18 +02:00
|
|
|
# Copyright (c) 2011 Chase Allen James <nx-zodiac@nu-ex.com>
|
2011-09-22 17:28:24 +02:00
|
|
|
|
2011-10-06 18:27:48 +02:00
|
|
|
zod_lib=ZODLIB_PATH
|
|
|
|
markdown_filter_cmd="awk -f $zod_lib/markdown.awk"
|
2011-09-22 17:28:24 +02:00
|
|
|
|
|
|
|
proj=$1
|
|
|
|
target=$2
|
|
|
|
|
2011-10-06 18:27:48 +02:00
|
|
|
_zod_error() {
|
|
|
|
echo -e ">>> ERROR: $*" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
2011-09-22 17:28:24 +02:00
|
|
|
|
2011-10-06 18:27:48 +02:00
|
|
|
[ ! "$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"
|
2011-10-04 21:40:45 +02:00
|
|
|
|
|
|
|
helpers=$proj/helpers.awk
|
2011-10-06 18:27:48 +02:00
|
|
|
[ -f $helpers ] && helper_opts="-f $(pwd)/$helpers"
|
2011-10-04 21:40:45 +02:00
|
|
|
|
2011-09-22 17:28:24 +02:00
|
|
|
global_meta=$proj/global.meta
|
2011-10-06 18:27:48 +02:00
|
|
|
[ -f $global_meta ] && global_meta_opts=$global_meta
|
2011-10-04 21:40:45 +02:00
|
|
|
|
|
|
|
layout=$proj/main.layout
|
2011-10-06 18:27:48 +02:00
|
|
|
[ -f $layout ] && layout_opts=$layout
|
|
|
|
|
|
|
|
files=$(find $proj -type f \
|
|
|
|
! -name "*.layout" \
|
|
|
|
! -name "*.meta" \
|
|
|
|
! -name "helpers.awk")
|
2011-09-22 17:28:24 +02:00
|
|
|
|
2011-10-04 21:40:45 +02:00
|
|
|
for f in $files; do
|
2011-09-22 17:28:24 +02:00
|
|
|
|
|
|
|
# Find the target directory if one must be created
|
2011-10-06 18:27:48 +02:00
|
|
|
subdir=${f%/*}
|
|
|
|
subdir=${subdir#$proj}
|
|
|
|
if [ "$subdir" ]; then
|
|
|
|
destination="$target$subdir"
|
|
|
|
mkdir -p "$destination"
|
2011-09-22 17:28:24 +02:00
|
|
|
else
|
|
|
|
# There is no directory to create in target,
|
|
|
|
# i.e. file is in the root of the project
|
2011-10-06 18:27:48 +02:00
|
|
|
destination=$target
|
2011-09-22 17:28:24 +02:00
|
|
|
fi
|
|
|
|
|
2011-10-06 18:27:48 +02:00
|
|
|
ext=${f##*.}
|
|
|
|
if [ $ext == "md" ] || [ $ext == "html" ]; then
|
|
|
|
|
|
|
|
meta=${f%.$ext}.meta
|
|
|
|
[ -f $meta ] && page_meta_opts=$meta
|
2011-09-22 17:28:24 +02:00
|
|
|
|
2011-10-06 18:27:48 +02:00
|
|
|
[ $ext == "md" ] && filter_opts=""
|
2011-10-04 23:34:34 +02:00
|
|
|
|
2011-10-06 18:27:48 +02:00
|
|
|
page=${f##*/}
|
|
|
|
page=${page%.$ext}.html
|
2011-09-22 17:28:24 +02:00
|
|
|
|
2011-10-06 18:27:48 +02:00
|
|
|
awk -f $zod_lib/render.awk \
|
|
|
|
-v markdown_filter_cmd="$markdown_filter_cmd" \
|
2011-10-04 21:40:45 +02:00
|
|
|
$helper_opts \
|
2011-10-06 18:27:48 +02:00
|
|
|
"$global_meta_opts" \
|
|
|
|
"$page_meta_opts" \
|
|
|
|
"$f" \
|
|
|
|
"$layout_opts" > "$destination/$page"
|
2011-09-22 17:28:24 +02:00
|
|
|
|
2011-10-04 21:40:45 +02:00
|
|
|
else
|
2011-10-06 18:27:48 +02:00
|
|
|
cp "$f" "$destination" # Copying a non-template file
|
2011-09-22 17:28:24 +02:00
|
|
|
fi
|
|
|
|
done
|