#! /bin/sh # # build_html.sh - Command line utility for auto-building HTML-pages # Copyright (C) 2003 Tommi Saviranta # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # # Version: build_html.sh v0.1.3 16-Nov-2003 tsaviran@cs.helsinki.fi # How to use (no spellcheking, no sanity-checking): # # FILES define which files (separated by white spaces) are to be generated # source files must be names _FOOBAR where FOOBAR is name in FILES # target files will be named FOOBAR.html # Note: If filename contains a slash like FOO/_BAR, target file will be # called FOO/BAR.html and FOO/_BAR will be used to generate it. This is # different from format where filename "FOO" will build FOO.html while # _FOO is used to generate it. # # source files must contain following lines: # ":: TITLE=" # ":: KEYWORDS=<keywords>" # ":: DESCRIPTION=<description>" # where <title> is page title etc. # All other lines beginning with "::" are stripped out from target files # # Default keywords can be defined in DEFKEYS # # Finally, generated files begin with contents of file header.html followed # by contents of _FOOBAR, ending with footer.html. # # Good luck. ;-) # In this example I have used "find" to list some files FILES=$(find . -name '_*') # ..but files could be defined just by saying FILES="foo bar" DEFKEYS="" for FILE in $FILES; do echo "$FILE" T="_$FILE" SFILE=$(echo $T | sed -e 's/_\(.*\)\/_\(.*\)/\1\/_\2/') TITLE=$(grep ':: TITLE' $SFILE | sed -e 's/.*=\(.*\)/\1/') KEYWORDS=$(grep ':: KEYWORDS' $SFILE | sed -e 's/.*=\(.*\)/\1/') DESCRIPTION=$(grep ':: DESCRIPTION' $SFILE | sed -e 's/.*=\(.*\)/\1/') KEYWORDS="$DEFKEYS $KEYWORDS" HEADERTITLE=$(echo "::: $TITLE" | sed -e 's/\//\\\//') TITLE=$(echo "$TITLE" | sed -e 's/\//\\\//') KEYWORDS=$(echo "$KEYWORDS" | sed -e 's/\//\\\//') DESCRIPTION=$(echo "$DESCRIPTION" | sed -e 's/\//\\\//') test -f _tmp_ && rm -f _tmp_ sed -e "s/HEADERTITLE/$HEADERTITLE/; s/KEYWORDS/$KEYWORDS/; s/DESCRIPTION/$DESCRIPTION/; s/TITLE/$TITLE/" <header.html >_tmp_ grep -v '^::' "$SFILE" >>_tmp_ TARGET="$FILE.html" TARGET=$(echo $TARGET | sed -e 's/\(.*\)\/_\(.*\.html\)/\1\/\2/') cat _tmp_ footer.html >"$TARGET" chmod 644 "$TARGET" rm -f _tmp_ done