zodiac/bin/zod_render

60 lines
1.4 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# render a zodiac page
2011-10-06 23:52:34 +02:00
zod_lib="$1"
proj="$2"
target="$3"
f="$4"
md_builtin="awk -f $zod_lib/markdown.awk"
2011-10-06 23:49:17 +02:00
[ -f "$proj/helpers.awk" ] && helper_opts="$proj/helpers.awk"
2011-10-08 02:28:42 +02:00
[ -f "$proj/filters.config" ] && filter_opts="$proj/filters.config"
2011-10-06 23:49:17 +02:00
[ -f "$proj/global.meta" ] && global_meta_opts="$proj/global.meta"
[ -f "$proj/main.layout" ] && layout_opts="$proj/main.layout"
# Find the target directory if one must be created
subdir=${f%/*}
2011-10-06 23:49:17 +02:00
subdir=${subdir#$proj}
if [ "$subdir" ]; then
2011-10-06 23:49:17 +02:00
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
2011-10-06 23:49:17 +02:00
destination="$target"
fi
ext=${f##*.}
# Add filter support provided by the filters.config file
[ "$filter_opts" ] && supported="$supported $(zod_supported_extensions "$zod_lib" "$filter_opts")"
for supported_ext in "$supported"; do
[ $ext == "$supported_ext" ] && { is_supported=true; break }
done
if [ "$is_supported" ]; then
meta=${f%.$ext}.meta
[ -f "$meta" ] && page_meta_opts="$meta"
2011-10-06 23:49:17 +02:00
set -- -f "$zod_lib/render.awk"
[ "$helper_opts" ] && set -- "$@" -f "$helper_opts"
set -- "$@" -v markdown_filter_cmd="$md_builtin" \
2011-10-08 02:28:42 +02:00
"$filter_opts" \
"$global_meta_opts" \
"$page_meta_opts" \
"$f" \
"$layout_opts"
2011-10-06 23:55:18 +02:00
page=${f##*/}
page=${page%.$ext}.html
awk "$@" > "$destination/$page"
else
cp "$f" "$destination" # Copying a non-template file
fi