Revision 13449 (by tjaden, 2010/07/10 02:01:49) Improve web site styling, reducing use of tables for layout.

This also required a slight change to the way we process pages.
Previously we concatenated the header, content and footer files together
and ran once them through Pandoc, but that messes up some element
nesting as Pandoc introduces a new div for each header, without any way
to explicitly close it. Thus our footer divs would appear within the
div of the last content header. Now we run the header and footer
through Pandoc first, then prepend and append the generated HTML when
processing the content.

Rename inc.* to INC.*. Combine inc.a.header and inc.a.sidebar into
one file.
#!/bin/sh
set -e

export LC_COLLATE=C

TOP=$(pwd)
PANDOC=${PANDOC:-pandoc}
STYLESHEET=web_style.css

check_for_pandoc () {
    if ! which "$PANDOC" >/dev/null 2>&1
    then
        # Make things a little easier on SF.net servers.
        export PATH="$PATH:/home/groups/a/al/alleg/pandoc/bin"
        if ! which "$PANDOC" >/dev/null 2>&1
        then
            echo "$PANDOC not found in PATH"
            exit 1
        fi
    fi
}

page_files () {
    if test -d "$1"
    then
        revdatesort $1/*
    else
        echo "$1"
    fi
    echo INC.links
}

# Reverse any series of filenames containing dates.
revdatesort () {(
    acc=
    for x in "$@"
    do
        case "$x" in
            *[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]*)
                acc="$x $acc"
                ;;
            *)
                echo "$acc"
                acc=
                echo "$x"
                ;;
        esac
    done
    echo "$acc"
)}

get_title () {
    grep -e "^$1=" "$TOP/en/META.title" | cut -d '=' -f 2-
}

# main
#-------

if test $# -ne 2
then
    echo "usage: $0  "
    exit 1
fi

check_for_pandoc

indir="$( dirname $1 )"
inpage="$( basename $1 )"
case "$2" in
    /*) outdir="$2" ;;
    *)  outdir="$PWD/$2" ;;
esac
outpage="${outdir}/${inpage}.html"

# Sanity check that don't overwrite an input file by passing wrong args.
case "$outpage" in
    */OUT/*)
        ;;
    *)
        echo "Refusing to write to ${outpage}."
        exit 2
        ;;
esac

test -d "$outdir" || mkdir "$outdir"

cd "$indir"

page_files=$( page_files "$inpage" )
title="$( get_title $inpage )"

"$PANDOC" $page_files                           \
    --include-in-header INC.head                \
    --include-before-body INC.bodystart.html    \
    --include-after-body INC.bodyend.html       \
    --title-prefix "$title"                     \
    --css "$STYLESHEET"                         \
    --standalone                                \
    --output "$outpage"

# vim: ft=sh sts=4 sw=4 et: