zodiac/bin/zod.template

70 lines
1.6 KiB
Plaintext
Raw Normal View History

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
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
_zod_error() {
echo -e ">>> ERROR: $*" >&2
exit 1
}
2011-09-22 17:28:24 +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
[ -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
[ -f $global_meta ] && global_meta_opts=$global_meta
2011-10-04 21:40:45 +02:00
layout=$proj/main.layout
[ -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
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
destination=$target
2011-09-22 17:28:24 +02:00
fi
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
page=${f##*/}
page=${page%.$ext}.html
2011-09-22 17:28:24 +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 \
"$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
cp "$f" "$destination" # Copying a non-template file
2011-09-22 17:28:24 +02:00
fi
done