#!/bin/ksh
#
# $Header: /afs/northstar/ufac/richard/projects/class-web-builder/RCS/buildslidelist,v 1.12 2005/03/19 05:15:13 richard Exp $
#
# Create a slide list suitable for a menu frame, from the named .html files.
# The "ID" tags for the index list are not derived from the file names, but from
# the numbers in the "slide.order" file, which is assumed to exist.
#
# This script is used in conjunction with buildhtml and buildslidelist.
#
# 2001/10 Richard Brittain, Dartmouth College
# Solaris has two versions of grep - make sure we get the right one by tweeking $PATH
PATH=/usr/xpg4/bin:$PATH; export PATH
# Make sure we get these only from the .conf file
unset author keywords description
# Read in the config file setting various optional features. Look only in the current directory
[[ -r ./buildhtml.conf ]] && . ./buildhtml.conf
# Default is to make links to a different frame, named "mainplusnav"
# Option -n = no-frames version - links do not reference a different target.
# Option -h = suppress headers - don't put out the 'printable' etc. links at top. (used in the printable pages). This
# creates a .htinc - includable HTML, no
, etc.
# Option -e = "expanded" list, with subheadings from the tags of the pages.
target="target=mainplusnav"
headers=yes
frames=yes
expanded=
while getopts nhe o ; do
case $o in
n) target= ; frames= ;;
h) headers= ;;
e) expanded=yes ;;
esac
done
shift $OPTIND-1
# The introduction page is $1 - special treatment
intro=$1; shift
# Set body background variable
# image or colour. Default is white, special value "none"
# omits the tag and lets the browser default be used
body_bg="${body_bg:-white}"
case $body_bg in
(*.gif|*.jpg)
# Assume it is an image
bodytag="background=$body_bg" ;;
none)
# We don't want any background
bodytag= ;;
*)
# Assume it is a colour - need a different syntax
bodytag="BGCOLOR=$body_bg" ;;
esac
doctype=${doctype:-""}
if [[ -n "$headers" ]]; then
# Generate standard :
print "$doctype"
print ""
print ""
print ""
[[ -n "$author" ]] && print ''
[[ -n "$keywords" ]] && print ''
[[ -n "$description" ]] && print ''
if [[ -n "$frames" ]]; then
# The "framed" slide list has a standard title (probably won't ever be seen though)
ftitle="Class slide list"
else
# The "noframes" slide list needs a better title for the site as a whole
# Generate the slide list TITLE from the TITLE of $intro. Tag must be a single line.
file="$intro"
ftitle=$(grep -i '^ *//' -e 's/<\/[tT][iI][tT][lL][eE]>.*//')
fi
print "$ftitle"
print ""
print ""
# Generate standard links for preface
if [[ -z "$frames" ]]; then
# Non-framed header with title and links for text-only, printable version, framed version
print ''"$ftitle"'
'
print ''
else
# Framed header with links for text-only, printable version, framed and frameless versions
print ''
fi
print "
"
# The first two links are fixed - Introduction ==> $intro (first argument)
# Research Computing ==> ~rc
#
print ' Introduction
'
print '
'
print ' Research Computing Home
'
# Generate the link to the "expanded" or "contracted version as needed (and framed/frameless too)
if [[ -z "$expanded" ]]; then
# This is the "non-expanded" version - make a link to the expanded version. There is never a target for this link.
if [[ -n "$frames" ]]; then
print '
'
else
print '
'
fi
else
# This is the "expanded" version - make a link back to the non-expanded version
if [[ -n "$frames" ]]; then
print '
'
else
print '
'
fi
fi
print "
"
else
# No headers - skip all standard HTML preface, but put out a
and a newpage flag for the printed output
print '
'
print 'Table of Contents
'
fi
# Generate the main body of the Table of Contents
# A Table for the numbers and Titles looks much better in normal mode, but doesn't look so good
# under Betsie.
print ""
# The links are generated from the named arguments, by extracting the
# The File ID tag is extracted from the order number in the slide.order file.
for file in "$@"; do
if [[ ! -r $file ]]; then
print "$file unreadable - skipping"
continue
fi
# Generate the index string from the TITLE tag. Tag must be a single line.
# We could also grab the first H1 tag instead.
ftitle=$(grep -i '^ *//' -e 's/<\/[tT][iI][tT][lL][eE]>.*//')
case $file in
*.html) html=html ;;
*.shtml) html=shtml ;;
*.htm) html=htm ;;
*) html= ;;
esac
# Generate the index number from the slide.order list.
fid=$(grep " $file\$" slide.order | awk '{print $1}')
# If that didn't work, just strip the .html from the file name and use that.
[[ -z $fid ]] && fid=${file%.$html}
# Explicitly code the target frame for each link
# For the 3-frame setup, we need to make links to the *.frameset.html files, but we've been
# given the plain .html filenames, so generate the new names. href=${file%.$html}.frameset.html
# For the 2-frame setup, just link to the .html files, with the appropriate target.
print "| $fid. | $ftitle |
"
if [[ -n "$expanded" ]]; then
# Make indented sub-categories based on the named anchors in the HTML file
# Skip the H1 tags, because every file will have one of those.
# Note that this makes the slide list file dependant on the _contents_ of the slides,
# not just the ordering of the slides (changes the Makefile rules)
# Leading and trailing spaces in the tag values will not work, so they should be excluded
# when creating the tags.
if grep -q ''
print " | "
grep '$tag "
done
print " |
"
print ""
fi
fi
done
print "
"
# Could put additional navigation at bottom of index, but these have been moved to every content page
# for better action in 'frameless' mode.
if [[ -n "$headers" ]]; then
print " "
print ""
fi
exit 0