ssw

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit f2305bb13115bf2889b43baae4f5ea4e732a6c67
parent 65894b65652e80820e3fc576015236ef0fd16b8d
Author: Rubén Santos <kojicomics@openmailbox.org>
Date:   Fri Dec  2 19:55:51 +0100

Added first ssw commit

Diffstat:
ssw | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+), 0 deletions(-)
diff --git a/ssw b/ssw @@ -0,0 +1,52 @@ +#!/bin/sh + +die() { echo $*; exit 1; } + +gen_html() { + cmd="$("$PPROC" < "$1")" + tmpfile=$(mktemp) + eval "$cmd" > $tmpfile + type 'ongen' &>/dev/null && ongen $1 + $PARSER < $tmpfile > $tmpfile.out + [ -n "$page_layout" ] || page_layout="$LAYOUT" + sed \ + -e 's^{%\s*title\s*%}^'"$page_title"'^' \ + -e "s/{%\s*description\s*%}/$page_description/" \ + -e "/{%\s*content\s*%}/ r $tmpfile.out" \ + -e "s/{%\s*content\s*%}//" \ + "$LDIR/$page_layout" > "$2" + rm $tmpfile; rm $tmpfile.out +} + +DIR=$1 +cd "$DIR" || die "Wrong directory: $DIR" +CWD=$(pwd) + +[ -f config.sh ] && . ./config.sh +[ -n "$EXT" ] || EXT=".smu" +[ -n "$PARSER" ] || PARSER="smu" +[ -n "$PPROC" ] || PPROC="sapp" +[ -n "$IN" ] || IN="src"; IDIR="$CWD/$IN" +[ -n "$OUT" ] || OUT="output"; ODIR="$CWD/$OUT" +[ -n "$LAYOUT" ] || LAYOUT="default.html"; +[ -n "$LAYOUTS" ] || LAYOUTS="layouts"; LDIR="$CWD/$LAYOUTS" + +cd "$IDIR" || die "Input directory does not exist: $IDIR" +mkdir -p $ODIR +cp -rf * $ODIR +rm -f $(find $ODIR -type f -iname "*$EXT") + +if [ -f "$CWD/.timestamp" ]; then + FILES=$(find . -anewer "$CWD/.timestamp" -type f -iname "*$EXT" | sed -e 's#^\./##') +else + FILES=$(find . -type f -iname "*$EXT" | sed -e 's#^\./##') +fi + +for f in $FILES; do + of="$(echo $f | sed -e "s,$EXT$,.html,g")" + printf "\033[1m$f\033[0m\n" + gen_html "$f" "$ODIR/$of" +done + +touch "$CWD/.timestamp" +type 'onexit' &>/dev/null && onexit