zodiac/bin/zod.template

78 lines
1.7 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
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
2011-10-04 21:40:45 +02:00
helpers=$proj/helpers.awk
if [ -e $helpers ]; then
helper_opts="-f `pwd`/$helpers"
fi
2011-09-22 17:28:24 +02:00
global_meta=$proj/global.meta
2011-10-04 21:40:45 +02:00
if [ -e $global_meta ]; then
global_meta_opts=$global_meta
fi
layout=$proj/main.layout
if [ -e $layout ]; then
layout_opts=$layout
fi
2011-09-22 17:28:24 +02:00
2011-10-04 21:40:45 +02:00
files=$(find $proj -type f ! -name "*.layout" ! -name "*.meta" ! -name "*.awk")
for f in $files; do
2011-09-22 17:28:24 +02:00
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
2011-10-04 21:40:45 +02:00
if [ ! -z "$(find $f -name *.md)" ]; then
page_name=$(basename $f | sed 's/\.md//')
2011-09-22 17:28:24 +02:00
2011-10-04 21:40:45 +02:00
if [ -e $dir/$page_name.meta ]; then
page_meta_opts=$dir/$page_name.meta
2011-09-22 17:28:24 +02:00
fi
2011-10-04 21:40:45 +02:00
awk -f $ZODLIB/render.awk \
-v AWKLIB="$ZODLIB" \
$helper_opts \
$global_meta_opts \
$page_meta_opts \
$f \
$layout_opts > $targetpath/$page_name.html
2011-09-22 17:28:24 +02:00
2011-10-04 21:40:45 +02:00
else
cp $f $targetpath # Copying a non-template file
2011-09-22 17:28:24 +02:00
fi
done