#!/bin/sh
#
# .mkindex.sh - Script acquires a list of files to be
# processed from the current directory
# and generate an index.html and even an
# all-index.html file (there's a list of
# core names to suppress in the .hide file
# that won't be placed in the default
# index file).
# Author: Jack C Lipton, liptonsoup1951@yahoo.com
#
HTML=index.html # target file
INFO=.sort
TMP=/tmp/mkindexT.$$
ICQPAGE=jclICQ.html # ICQ Panel file, pasted from ICQ
CVPAGE=CV.html # Curriculum Vitae (yeah, right)
#HUMORPAGE=Humor.html # Potentially humorous material
#
# Here's the index file prefix. You can tell that I like
# shell "here" documents, can't you?
#
cat >${HTML}+ <<INDEXHTML
<HTML>
<HEAD>
<TITLE>Jack C Lipton's Story Page</TITLE>
</HEAD>
<BODY>
<H1 align=center>Jack C Lipton's Story Page</H1>
<CENTER>
<B>Contacting Me</B><BR>
<B>eMail:</B>
<A HREF="mailto:liptonsoup1951@yahoo.com">
<TT>liptonsoup1951@yahoo.com</TT>
</A> <BR>
<B>ICQ#:</B>
<A HREF="http://web.icq.com/wwp?Uin=174178749">
<TT>174178749</TT>
</A> <BR>
INDEXHTML
#
# ICQ Panel is optional- named and existing
#
[ ! -z "$ICQPAGE" ] && [ -f $ICQPAGE ] && \
cat >>${HTML}+ <<INDEXHTML
(or use my <A HREF="$ICQPAGE">panel</A>) <BR>
INDEXHTML
#
# CV (Background) Page optional - named and existing
#
[ ! -z "$CVPAGE" ] && [ -f $CVPAGE ] && \
cat >>${HTML}+ <<INDEXHTML
<B>More Personal information:</B>
<A HREF="$CVPAGE"> CV </A> <BR>
INDEXHTML
#
# A humor page is optional, but must be both named and exist
#
[ ! -z "$HUMORPAGE" ] && [ -f $HUMORPAGE ] && \
cat >>${HTML}+ <<INDEXHTML
<B>Potentially Humorous Items:</B>
<A HREF="$HUMORPAGE"> Humor </A> <BR>
INDEXHTML
#
# Insert "test" pages (for now)
#
cat >>${HTML}+ <<INDEXHTML
<BR>
<B>Profile test pages:</B>
<A HREF="squick.html"> Squicks </A>,
<A HREF="affinity.html"> Affinities </A>,
<A HREF="affinity2.html"> 2nd Affinities format </A>
<BR>
<BR>
INDEXHTML
#
# Insert the baseline for w/ some "favorites" and the like
#
cat >>${HTML}+ <<INDEXHTML
<BR> <BR>
<IMG SRC="kiss-small.jpg"> <BR>
<I>The "<B>Boss</B>" and I</I>
<BR> <BR>
<H2 SIZE=+2>Warning</H2>
<TT>
This page links to <B><I>adult</I></B> material. <BR>
<BR>
If you are under 18 years of age (or live somewhere where <BR>
the perusal of adult-oriented material is illegal) you <BR>
really *should* use the browser's "BACK" button to leave. <BR>
<BR>
Material linked here likely to be offensive to <BR>
*somebody*. If you're uncomfortable with sex <BR>
and sexual issues, you also should "BACK" out <BR>
of this page too. It's your choice to proceed. <BR>
<BR>
<B>You have been warned.</B> <BR>
</TT>
</CENTER>
<BR><BR>
<H2>ASSTR</H2>
<UL>
<LI> <A HREF="http://www.asstr.org/main.html"> Main </A>,
<A HREF="http://www.asstr.org/authors.html"> Authors </A>,
<A HREF="http://www.asstr.org/authors_new.html"> New Authors </A>,
<A HREF="http://www.asstr.org/profiles.html"> Author Profiles </A>
<LI> <A HREF="http://www.asstr.org/archives.html"> Collections </A>,
<A HREF="http://www.asstr.org/search.html"> Search </A> <BR>
<LI> <B>Favorites:</B>
<A HREF="http://www.asstr.org/~Rui_Favorites/"> All Time... </A>,
<A HREF="http://www.asstr.org/~artie/"> Artie </A>,
<A HREF="http://www.asstr.org/~davidb234/"> davidb234 </A>,
<A HREF="http://www.asstr.org/~Dorsai/"> Dorsai </A>
<LI> <B>FTP:</B>
<A HREF="ftp://ftp.asstr.org/pub/Authors/"> Authors </A>,
<A HREF="ftp://ftp.asstr.org/pub/Collections/"> Collections </A>
</UL>
<H2>Useful Links</H2>
<UL>
<LI> <B>Searching:</B>
<A HREF="http://www.google.com/">Google</A>
(<A HREF="http://www.google.com/advanced_search">Advanced</A>),
<A HREF="http://groups.google.com/">UseNet News</A>
(<A HREF="http://groups.google.com/advanced_group_search">Advanced</A>)
</UL>
<H2>Stories</H2>
<UL>
INDEXHTML
#
# OK, here's where the fun begins. We copy the prefix to
# the all-index file to reduce the points of maintenance.
#
# Yes, I *am* that lazy.
#
cp ${HTML}+ all-${HTML}+
#
# This works through the file names. If I really wanted
# to be subtle I'd probably map each file into the titles
# and sort against that. Perhaps another day I'll do so.
# But not today, obviously. Again, I slapped this together
# pretty quickly.
#
>$INFO # make sure the file is empty
echo "Bringing in header information:"
for F in *.x
do
echo -e "\r \r$F \c"
# isolate name so we can check whether this should be displayed
CORENAME=`echo $F | awk -F. '{print $1}'` # independant of ext
#CORENAME=`basename $F .x`
#
# grab information from the SHS headers...
# This is most convenient using the text file...
#
TITLE=`head -15 $F | grep '^Title: ' | sed 's/^Title: //'`
INCOMPLETE=`echo "$TITLE" | grep -i incomplete | wc -l`
if [ $INCOMPLETE != 0 ]
then
TITLE=`echo "$TITLE" | sed 's/ ([Ii]ncomplete)//'`
fi
if [ -z "$TITLE" ]
then
#
# If SHS headers not in place we'll need to cheat.
# This does that. (I hope)
#
TITLE=`head -15 $F | grep -v '^$' | head -1 | sed 's/^[ ][ ]*//'`
PART=""
CODES=""
SUMMARY=""
UNIVERSE=""
WORDS=`cat $F | wc -w` # count the words
else
PART=`head -15 $F | grep '^Part: ' | sed 's/^Part: //'`
CODES=`head -15 $F | grep '^Keywords: ' | sed 's/^Keywords: //'`
SUMMARY=`head -15 $F | grep '^Summary: ' | sed 's/^Summary: //'`
UNIVERSE=`head -15 $F | grep '^Universe: ' | sed 's/^Universe: //'`
[ "$UNIVERSE" = "n/a" ] && UNIVERSE=
WORDS=`cat $F | wc -w` # count the words
fi
echo "$CORENAME|$UNIVERSE|$TITLE|$PART|$CODES|$SUMMARY|$WORDS|$INCOMPLETE" >>$INFO
done
echo -e "\r \r\c"
#
# OK, we have extracts of all files now in $INFO; We'll sort this
# by the universe & title...
#
sort -t '|' +1 $INFO >${INFO}+
cutover $INFO
FILES=`cat $INFO | awk '-F|' '{print $1}'` # sorted list of files
#
# Now we'll build the actual linkages for the web page from the sorted
# file- which simplifies matters enormously...
#
for CORENAME in $FILES
do
# isolate name so we can check whether this should be displayed
F=$CORENAME.x # text version of file
WF=$CORENAME.html # HTML version of file
HIDDEN=`grep "^$CORENAME$" .hide | wc -l`
echo -e "$F ... \c" >/dev/tty
# echo "$CORENAME|$UNIVERSE|$TITLE|$PART|$CODES|$SUMMARY|$WORDS" >>$INFO
TITLE="`grep "^$CORENAME|" $INFO | awk '-F|' '{print $3}'`"
PART="`grep "^$CORENAME|" $INFO | awk '-F|' '{print $4}'`"
CODES="`grep "^$CORENAME|" $INFO | awk '-F|' '{print $5}'`"
UNIVERSE="`grep "^$CORENAME|" $INFO | awk '-F|' '{print $2}'`"
SUMMARY="`grep "^$CORENAME|" $INFO | awk '-F|' '{print $6}'`"
WORDS="`grep "^$CORENAME|" $INFO | awk '-F|' '{print $7}'`"
INCOMPLETE="`grep "^$CORENAME|" $INFO | awk '-F|' '{print $8}'`"
#
# Report the title associated with the file name
#
echo -e "$TITLE $PART \c" >/dev/tty
#
# We encapsulate the following to reduce the need for
# individual redirections of stdout; Also, it goes to
# a temporary file so that it can be conditionally
# appended to the index files under construction...
#
(
echo -e " <LI> <A HREF=\"$WF\">\n\t\t$TITLE \c"
[ ! -z "$PART" ] && echo -e " [$PART] \c"
echo -e "\n\t</A> \c"
[ $INCOMPLETE != 0 ] && echo -e "<B><I>Incomplete</B></I> \c"
[ ! -z "$CODES" ] && echo -e "($CODES) \c"
echo -e "<A HREF=\"revu-$WF\">(review this story)</A> "
[ ! -z "$SUMMARY" ] && echo -e "<BR>\n\t$SUMMARY"
[ ! -z "$WORDS" ] && echo -e "<BR>\n\t$WORDS words"
echo -e "<BR>\n"
) >$TMP
#
# The "all" index file gets it regardless, but if it's
# amongst the "hidden" it won't be seen on the default
# index file...
#
cat $TMP >>all-${HTML}+
[ $HIDDEN = 0 ] && cat $TMP >>${HTML}+
echo "" >/dev/tty
done
#
# Each index file needs to be closed out. We'll do that here.
#
cat >$TMP <<INDEXHTML
</UL>
<HR SIZE=5>
<CENTER>
Copyright (c) 2002 - Jack C. Lipton<BR>
</CENTER>
</BODY>
</HTML>
INDEXHTML
cat $TMP >>${HTML}+
cat $TMP >>all-${HTML}+
#
# If any actual changes have been made to the newly generated files
# bring them "current" so we're live with the updated file. This
# keeps the index files from being updated at the published site
# UNLESS actual changes have been made.
#
for F in ${HTML} all-${HTML}
do
diff ${F} ${F}+ >$TMP
if [ -s $TMP ]
then
cutover $F
else
rm -f ${F}+
touch $F
fi
done
#
# Perform clean-up of volatile files
#
rm -f $TMP
exit 0 # all done!