support spaces in files and use find correctly

This commit is contained in:
nuex 2011-10-06 17:28:51 -04:00
parent 1df2294732
commit d4f03b0314
3 changed files with 61 additions and 57 deletions

View File

@ -7,9 +7,10 @@ all:
@echo Compiled
install: all
@echo Installing zod executable to ${PREFIX}/bin
@echo Installing zod executables to ${PREFIX}/bin
@mkdir -p ${PREFIX}/bin
@cp bin/zod ${PREFIX}/bin
@cp bin/zod_render ${PREFIX}/bin
@echo Installing awk lib files to ${AWKLIB}
@mkdir -p ${AWKLIB}
@cp lib/render.awk ${AWKLIB}
@ -19,6 +20,7 @@ install: all
uninstall:
@echo Uninstalling zod executable
@rm ${PREFIX}/bin/zod
@rm ${PREFIX}/bin/zod_render
@echo Uninstalling awk lib files
@rm -rf ${AWKLIB}
@echo Uninstallation Complete

View File

@ -3,67 +3,23 @@
# ZODIAC - a simple static site generator
# Copyright (c) 2011 Chase Allen James <nx-zodiac@nu-ex.com>
zod_lib=ZODLIB_PATH
markdown_filter_cmd="awk -f $zod_lib/markdown.awk"
proj=$1
target=$2
ZOD_LIB=ZODLIB_PATH
ZOD_PROJECT=$1
ZOD_TARGET=$2
_zod_error() {
echo -e ">>> ERROR: $*" >&2
exit 1
}
[ ! "$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"
[ "$#" -ne 2 ] && { echo "usage: zod projectdir targetdir"; exit; }
[ ! -d "$ZOD_PROJECT" ] && _zod_error "project directory does not exist"
[ ! -d "$ZOD_TARGET" ] && _zod_error "target directory does not exist"
helpers=$proj/helpers.awk
[ -f $helpers ] && helper_opts="-f $(pwd)/$helpers"
export ZOD_LIB ZOD_PROJECT ZOD_TARGET
global_meta=$proj/global.meta
[ -f $global_meta ] && global_meta_opts=$global_meta
layout=$proj/main.layout
[ -f $layout ] && layout_opts=$layout
files=$(find $proj -type f \
find "$ZOD_PROJECT" -type f \
! -name "*.layout" \
! -name "*.meta" \
! -name "helpers.awk")
for f in $files; do
# Find the target directory if one must be created
subdir=${f%/*}
subdir=${subdir#$proj}
if [ "$subdir" ]; then
destination="$target$subdir"
mkdir -p "$destination"
else
# There is no directory to create in target,
# i.e. file is in the root of the project
destination=$target
fi
ext=${f##*.}
if [ $ext == "md" ] || [ $ext == "html" ]; then
meta=${f%.$ext}.meta
[ -f $meta ] && page_meta_opts=$meta
page=${f##*/}
page=${page%.$ext}.html
awk -f $zod_lib/render.awk \
-v markdown_filter_cmd="$markdown_filter_cmd" \
$helper_opts \
"$global_meta_opts" \
"$page_meta_opts" \
"$f" \
"$layout_opts" > "$destination/$page"
else
cp "$f" "$destination" # Copying a non-template file
fi
done
! -name "helpers.awk" \
-exec /home/nuex/_dev/zodiac/bin/zod_render {} \;

46
bin/zod_render Executable file
View File

@ -0,0 +1,46 @@
#!/bin/sh
# render a zodiac page
# used internally by zod (uses file as single argument)
f="$*"
markdown_filter_cmd="awk -f $ZOD_LIB/markdown.awk"
[ -f "$ZOD_PROJECT/helpers.awk" ] && helper_opts="$ZOD_PROJECT/helpers.awk"
[ -f "$ZOD_PROJECT/global.meta" ] && global_meta_opts="$ZOD_PROJECT/global.meta"
[ -f "$ZOD_PROJECT/main.layout" ] && layout_opts="$ZOD_PROJECT/main.layout"
# Find the target directory if one must be created
subdir=${f%/*}
subdir=${subdir#$ZOD_PROJECT}
if [ "$subdir" ]; then
destination="$ZOD_TARGET$subdir"
mkdir -p "$destination"
else
# There is no directory to create in target,
# i.e. file is in the root of the project
destination="$ZOD_TARGET"
fi
ext=${f##*.}
if [ $ext == "md" ] || [ $ext == "html" ]; then
meta=${f%.$ext}.meta
[ -f "$meta" ] && page_meta_opts="$meta"
page=${f##*/}
page=${page%.$ext}.html
set -- -f "$ZOD_LIB/render.awk"
[ "$helper_opts" ] && set -- "$@" -f "$helper_opts"
set -- "$@" -v markdown_filter_cmd="$markdown_filter_cmd" \
"$global_meta_opts" \
"$page_meta_opts" \
"$f" \
"$layout_opts"
awk "$@" > "$destination/$page"
else
cp "$f" "$destination" # Copying a non-template file
fi