support spaces in files and use find correctly
This commit is contained in:
parent
1df2294732
commit
d4f03b0314
4
Makefile
4
Makefile
@ -7,9 +7,10 @@ all:
|
|||||||
@echo Compiled
|
@echo Compiled
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
@echo Installing zod executable to ${PREFIX}/bin
|
@echo Installing zod executables to ${PREFIX}/bin
|
||||||
@mkdir -p ${PREFIX}/bin
|
@mkdir -p ${PREFIX}/bin
|
||||||
@cp bin/zod ${PREFIX}/bin
|
@cp bin/zod ${PREFIX}/bin
|
||||||
|
@cp bin/zod_render ${PREFIX}/bin
|
||||||
@echo Installing awk lib files to ${AWKLIB}
|
@echo Installing awk lib files to ${AWKLIB}
|
||||||
@mkdir -p ${AWKLIB}
|
@mkdir -p ${AWKLIB}
|
||||||
@cp lib/render.awk ${AWKLIB}
|
@cp lib/render.awk ${AWKLIB}
|
||||||
@ -19,6 +20,7 @@ install: all
|
|||||||
uninstall:
|
uninstall:
|
||||||
@echo Uninstalling zod executable
|
@echo Uninstalling zod executable
|
||||||
@rm ${PREFIX}/bin/zod
|
@rm ${PREFIX}/bin/zod
|
||||||
|
@rm ${PREFIX}/bin/zod_render
|
||||||
@echo Uninstalling awk lib files
|
@echo Uninstalling awk lib files
|
||||||
@rm -rf ${AWKLIB}
|
@rm -rf ${AWKLIB}
|
||||||
@echo Uninstallation Complete
|
@echo Uninstallation Complete
|
||||||
|
@ -3,67 +3,23 @@
|
|||||||
# ZODIAC - a simple static site generator
|
# ZODIAC - a simple static site generator
|
||||||
# Copyright (c) 2011 Chase Allen James <nx-zodiac@nu-ex.com>
|
# Copyright (c) 2011 Chase Allen James <nx-zodiac@nu-ex.com>
|
||||||
|
|
||||||
zod_lib=ZODLIB_PATH
|
ZOD_LIB=ZODLIB_PATH
|
||||||
markdown_filter_cmd="awk -f $zod_lib/markdown.awk"
|
ZOD_PROJECT=$1
|
||||||
|
ZOD_TARGET=$2
|
||||||
proj=$1
|
|
||||||
target=$2
|
|
||||||
|
|
||||||
_zod_error() {
|
_zod_error() {
|
||||||
echo -e ">>> ERROR: $*" >&2
|
echo -e ">>> ERROR: $*" >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
[ ! "$1" ] || [ ! "$2" ] && { echo "usage: zod projectdir targetdir"; exit; }
|
[ "$#" -ne 2 ] && { echo "usage: zod projectdir targetdir"; exit; }
|
||||||
[ ! -d $proj ] && _zod_error "project directory does not exist"
|
[ ! -d "$ZOD_PROJECT" ] && _zod_error "project directory does not exist"
|
||||||
[ ! -d $target ] && _zod_error "target directory does not exist"
|
[ ! -d "$ZOD_TARGET" ] && _zod_error "target directory does not exist"
|
||||||
|
|
||||||
helpers=$proj/helpers.awk
|
export ZOD_LIB ZOD_PROJECT ZOD_TARGET
|
||||||
[ -f $helpers ] && helper_opts="-f $(pwd)/$helpers"
|
|
||||||
|
|
||||||
global_meta=$proj/global.meta
|
find "$ZOD_PROJECT" -type f \
|
||||||
[ -f $global_meta ] && global_meta_opts=$global_meta
|
! -name "*.layout" \
|
||||||
|
! -name "*.meta" \
|
||||||
layout=$proj/main.layout
|
! -name "helpers.awk" \
|
||||||
[ -f $layout ] && layout_opts=$layout
|
-exec /home/nuex/_dev/zodiac/bin/zod_render {} \;
|
||||||
|
|
||||||
files=$(find $proj -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
|
|
||||||
|
46
bin/zod_render
Executable file
46
bin/zod_render
Executable 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
|
Loading…
Reference in New Issue
Block a user