zodiac/bin/zod.template

83 lines
1.9 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 23:34:34 +02:00
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//')
2011-09-22 17:28:24 +02:00
2011-10-04 23:34:34 +02:00
# 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
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 \
2011-10-04 23:34:34 +02:00
$layout_opts > $targetpath/$file_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