Example script: buildslidelist.ksh


   1: #!/bin/ksh
   2: #
   3: # $Header: /afs/northstar/ufac/richard/projects/class-web-builder/RCS/buildslidelist,v 1.12 2005/03/19 05:15:13 richard Exp $
   4: #
   5: # Create a slide list suitable for a menu frame, from the named .html files.
   6: # The "ID" tags for the index list are not derived from the file names, but from
   7: # the numbers in the "slide.order" file, which is assumed to exist.
   8: #
   9: # This script is used in conjunction with buildhtml and buildslidelist.
  10: #
  11: # 2001/10 Richard Brittain, Dartmouth College
  12: 
  13: # Solaris has two versions of grep - make sure we get the right one by tweeking $PATH
  14: PATH=/usr/xpg4/bin:$PATH; export PATH
  15: 
  16: # Make sure we get these only from the .conf file
  17: unset author keywords description
  18: 
  19: # Read in the config file setting various optional features.  Look only in the current directory
  20: [[ -r ./buildhtml.conf ]] && . ./buildhtml.conf
  21: 
  22: # Default is to make links to a different frame, named "mainplusnav"
  23: # Option -n = no-frames version - links do not reference a different target.
  24: # Option -h = suppress headers - don't put out the 'printable' etc. links at top. (used in the printable pages).  This
  25: #             creates a .htinc - includable HTML, no <HEAD>,<BODY> etc.
  26: # Option -e = "expanded" list, with subheadings from the <H> tags of the pages.
  27: target="target=mainplusnav"
  28: headers=yes
  29: frames=yes
  30: expanded=
  31: while getopts nhe o ; do
  32:    case $o in
  33:    n) target= ; frames= ;;
  34:    h) headers= ;;
  35:    e) expanded=yes ;;
  36:    esac
  37: done
  38: shift $OPTIND-1
  39: 
  40: # The introduction page is $1 - special treatment
  41: intro=$1; shift
  42: 
  43: # Set body background variable
  44: 
  45: # <BODY BACKGROUND=background> image or colour.  Default is white, special value "none"
  46: # omits the tag and lets the browser default be used
  47: body_bg="${body_bg:-white}"
  48: case $body_bg in
  49: (*.gif|*.jpg) 
  50:    # Assume it is an image
  51:    bodytag="background=$body_bg" ;;
  52: none)
  53:    # We don't want any background
  54:    bodytag= ;;
  55: *)
  56:    # Assume it is a colour - need a different syntax
  57:    bodytag="BGCOLOR=$body_bg" ;;
  58: esac
  59: 
  60: doctype=${doctype:-"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"}
  61: 
  62: if [[ -n "$headers" ]]; then
  63:    # Generate standard <HEAD>:
  64: 
  65:    print "$doctype"
  66:    print "<html>"
  67:    print "<head>"
  68:    print "<!-- This was created automatically by buildhtml - do not edit -->"
  69:    [[ -n "$author" ]]      && print '<meta name="AUTHOR" content="'"$author"'">'
  70:    [[ -n "$keywords" ]]    && print '<meta name="keywords" content="'"$keywords"'">'
  71:    [[ -n "$description" ]] && print '<meta name="description" content="'"$description"'">'
  72:    if [[ -n "$frames" ]]; then
  73:       # The "framed" slide list has a standard title (probably won't ever be seen though)
  74:       ftitle="Class slide list"
  75:    else
  76:       # The "noframes" slide list needs a better title for the site as a whole
  77:       # Generate the slide list TITLE from the TITLE of $intro.  Tag must be a single line.
  78:       file="$intro"
  79:       ftitle=$(grep -i '^ *<TITLE' $file | sed -e 's/.*<[tT][iI][tT][lL][eE]>//' -e 's/<\/[tT][iI][tT][lL][eE]>.*//')
  80:    fi
  81:    print "<title>$ftitle</title>"
  82:    print "</head>"
  83: 
  84:    print "<body $bodytag>"
  85: 
  86:    # Generate standard links for preface
  87: 
  88:    if [[ -z "$frames" ]]; then
  89:       # Non-framed header with title and links for text-only, printable version, framed version
  90:       print '<h1>'"$ftitle"'</h1>'
  91:       print '<table width=100%>'
  92:       print '<tr>'
  93:       print '  <td align="left"><font size=-1><a href="/cgi-bin/betsie.cgi">Text-only</a></font></td>'
  94:       print '  <td align="center"><font size=-1><a href="print_pages.shtml" target=_top>Printable</a></font></td>'
  95:       print '  <td align="right"><font size=-1><a href="index.html" target=_top>Framed version</a></font></td>'
  96:       print '</tr>'
  97:       print '</table>'
  98:    else
  99:       # Framed header with links for text-only, printable version, framed and frameless versions
 100:       print '<table width=100%>'
 101:       print '<tr>'
 102:       print '  <td align="left"><font size=-1><a href="/cgi-bin/betsie.cgi">Text-only</a></font></td>'
 103:       print '  <td align="right"><font size=-1><a href="print_pages.shtml" target=_top>Printable</a></font></td>'
 104:       print '</tr>'
 105:       print '<tr>'
 106:       print '  <td align="left"><font size=-1><a href="index.html" target=_top>Frames</a></font></td>'
 107:       print '  <td align="right"><font size=-1><a href="'$intro'" target=_top>No Frames</a></font></td>'
 108:       print '</tr>'
 109:       print '</table>'
 110:    fi
 111:    print "<hr>"
 112: 
 113:    # The first two links are fixed - Introduction ==> $intro (first argument)
 114:    #                                 Research Computing ==> ~rc
 115:    #
 116:    print '<a href="'$intro'#top" '$target'> Introduction </a><br>'
 117:    print '<br>'
 118:    print '<a href="http://www.dartmouth.edu/~rc" $target> Research Computing Home</a><br>'
 119: 
 120:    # Generate the link to the "expanded" or "contracted version as needed (and framed/frameless too)
 121:    if [[ -z "$expanded" ]]; then
 122:       # This is the "non-expanded" version - make a link to the expanded version.  There is never a target for this link.
 123:       if [[ -n "$frames" ]]; then 
 124:          print '<a href="slide_list_expanded.html"><img src="right.gif" border=0 height=15 width=15 alt="Expand sections"></a>'
 125:       else
 126:          print '<a href="slide_list_noframes_expanded.html"><img src="right.gif" border=0 height=15 width=15 alt="Expand sections"></a>'
 127:       fi
 128:    else
 129:       # This is the "expanded" version - make a link back to the non-expanded version
 130:       if [[ -n "$frames" ]]; then 
 131:          print '<a href="slide_list.html"><img src="down.gif" border=0 height=15 width=15 alt="Contract sections"></a>'
 132:       else
 133:          print '<a href="slide_list_noframes.html"><img src="down.gif" border=0 height=15 width=15 alt="Contract sections"></a>'
 134:       fi
 135:    fi
 136:    print "<br>"
 137: else
 138:    # No headers - skip all standard HTML preface, but put out a <HR> and a newpage flag for the printed output
 139:    print '<hr>'
 140:    print '<p align="center" class="newpage">Table of Contents</p>'
 141: fi
 142: 
 143: # Generate the main body of the Table of Contents
 144: # A Table for the numbers and Titles looks much better in normal mode, but doesn't look so good 
 145: # under Betsie.
 146: print "<table>"
 147: 
 148: # The links are generated from the named arguments, by extracting the <TITLE>
 149: # The File ID tag is extracted from the order number in the slide.order file.
 150: 
 151: for file in "$@"; do
 152:    if [[ ! -r $file ]]; then
 153:       print "$file unreadable - skipping"
 154:       continue
 155:    fi
 156:    # Generate the index string from the TITLE tag.  Tag must be a single line.
 157:    # We could also grab the first H1 tag instead.
 158:    ftitle=$(grep -i '^ *<TITLE' $file | sed -e 's/.*<[tT][iI][tT][lL][eE]>//' -e 's/<\/[tT][iI][tT][lL][eE]>.*//')
 159:    
 160:    case $file in
 161:    *.html)  html=html  ;;
 162:    *.shtml) html=shtml ;;
 163:    *.htm)   html=htm   ;;
 164:    *)       html=      ;;
 165:    esac
 166: 
 167:    # Generate the index number from the slide.order list. 
 168:    fid=$(grep " $file\$" slide.order | awk '{print $1}')
 169:    # If that didn't work, just strip the .html from the file name and use that.
 170:    [[ -z $fid ]] && fid=${file%.$html}
 171: 
 172:    # Explicitly code the target frame for each link
 173:    # For the 3-frame setup, we need to make links to the *.frameset.html files, but we've been
 174:    # given the plain .html filenames, so generate the new names. href=${file%.$html}.frameset.html
 175:    # For the 2-frame setup, just link to the .html files, with the appropriate target.
 176:    print "<tr><td align="right">$fid.</td><td><a href=$file#top $target>$ftitle</a></td></tr>"
 177: 
 178:    if [[ -n "$expanded" ]]; then
 179:       # Make indented sub-categories based on the named anchors in the HTML file
 180:       # Skip the H1 tags, because every file will have one of those.
 181:       # Note that this makes the slide list file dependant on the _contents_ of the slides,
 182:       # not just the ordering of the slides (changes the Makefile rules)
 183:       # Leading and trailing spaces in the tag values will not work, so they should be excluded 
 184:       # when creating the tags.
 185:       if grep -q '<a name="L[2-5]-' $file; then
 186:          # This code actually lets us expand a single item if we wish - may use this later
 187:          print '<!--#if expr="${QUERY_STRING} = '${file%.$html}'" -->'
 188:          print "<tr><td></td><td><small>"
 189:          grep '<a name="L[2-5]-' $file | sed -e's!^.*name="L\([2-5]\)-\([^"]*\)".*$!\1 \2!' | \
 190:             while read level tag; do
 191:             ## print -u2 level=$level tag=\"$tag\" 
 192:             # crude indentation based on subheading level
 193:             case $level in
 194:             2) print -n "&nbsp;" ;;
 195:             3) print -n "&nbsp;&nbsp;" ;;
 196:             4) print -n "&nbsp;&nbsp;&nbsp;" ;;
 197:             5) print -n "&nbsp;&nbsp;&nbsp&nbsp;" ;;
 198:             esac
 199:             print "<a href=\"$file#L$level-$tag\" $target>$tag</a><br>"
 200:          done
 201:          print "</small></td></tr>"
 202:          print "<!--#endif -->"
 203:       fi
 204:    fi
 205: done
 206: 
 207: print "</table>"
 208: # Could put additional navigation at bottom of index, but these have been moved to every content page
 209: # for better action in 'frameless' mode.
 210: if [[ -n "$headers" ]]; then
 211:    print "</body> "
 212:    print "</html>"
 213: fi
 214: exit 0



  last modified 09/02/2006 Introduction Table of Contents
(frame/no frame)
Printable
(single file)
© Dartmouth College