The "menugen.sh" script automatically generates HTML documentation based on information contained in a control file which specifies parent-child relationships between pages.
"menugen" provides the user with the ability to easily maintain and modify groups of web pages. This program creates a standard "look-and-feel" for user supplied WWW content using server side includes. It therefore assumes the web server, where these pages will be offered, supports server side includes.
To use "menugen", the user should create content and store it in files called "XXXXXXXX.content.shtml", where XXXXXXXX is some prefix file name defined by the user. "menugen" creates menus, links, headers, titles, footers, contact info links, etc, based on information stored in a user defined relationship file. The relationship file is assumed to be in the same directory with the "XXXXXXXX.content.shtml" files and is called "menugen.dat".
"menugen" allows users to modify the "look-and-feel" of all files in a directory by storing configuration information such as colors, font sizes, title info, etc in a file called "menugen.cfg".
The "-c" option will create a file called "menugen.cfg" if it does not already exist. If it does exist it will not overwrite it. To recreate the "menugen.cfg" file, you will first have to remove it. The "menugen.cfg" file contains user modifiable parameters such as font colors, font sizes background color, title and contact information.
One of the values defined in the "menugen.cfg" file is called "THEME". This is a title which is displayed at the top of every page. The title can be a two part title separated by a colon (:). The part of the title to the left of the colon will be displayed in a larger text. The part of the title to the right of the colon will be displayed in italics and a smaller text. All values in the configuration file may be changed to suit the users particular needs. The "menugen.cfg" file MUST be executeable.
The "menugen" program creates a menu file for each page which contains the relationships between each page, its parent page, and its child pages. The links displayed on the menu by default are that of the parent and children of each page. The "-g" option causes the grandchildren of each page to also be included in the menu.
Normally, if the static menu bar file exists, it is not overwritten in order to preserve any user customization of that file. However the "-S" option will cause the static menubar file to be overwritten with the default values. The static menu bar file is "staticbar.shtml".
The datafile describes the relationships between all the web pages in the current directory. The relationship between the pages is maintained via parent/child references. By default the relationships are read from a file called "menugen.dat" in the current directory. The "-f" option allows the user to specify a different file name. The datafile has the following format:
PARENT<space><space><space><space><space><space> CURRENT<space><space><space><space><space><space> SHORT DESCRIPTION
PARENT and CURRENT are file name prefixes and are usually limited to 8 characters or less. TAB characters between the fields is mandatory. PARENT is the parent of the CURRENT page. The SHORT DESCRIPTION is a description of the CURRENT page. An example of datafile would be:
NULL index Home Page index child1 Child 1 of index index child2 Child 2 of index index child3 Child 3 of index child1 child11 Child 1 of child1 child1 child12 Child 2 of child1 child1 child13 Child 3 of child1 child1 child14 Child 4 of child1 child2 child21 Child 1 of child2 child2 child22 Child 2 of child2 child2 child23 Child 3 of child2 child3 child31 Child 1 of child3 child3 child32 Child 2 of child3
In this example, the page "index" has three child pages called "child1", "child2", and "child3". The menu on the "index" page would reference these three pages. The page "child1" has four child pages called "child11", "child12", "child13", "child14". The menu on the "child1" page would reference these four pages. And so on for child pages "child2" and "child3".
The "-?" option displays a list of all available options and a description of each option.
Most graphical web browsers will show hypertext links as underlined text of a different color than normal text. When this program creates the menu bars, the links are configured NOT to have underlines. If you want the links in the menu bars to have underlines, use the "-u" option.
#!/usr/bin/ksh93
################################################################
if [ -s "./menugen.cfg" ]
then
if [ ! -x "./menugen.cfg" ]
then
if ! chmod 755 "./menugen.cfg"
then
echo "Unable to make \"menugen.cfg\" executable"
exit 6
fi
fi
. ./menugen.cfg
fi
THEME="${THEME:-'Default Theme: Default Subtheme'}"
CLR_TEXT="${CLR_TEXT:-'#000000'}"
CLR_BACKGRD="${CLR_BACKGRD:-'#FFFFFF'}"
CLR_LINK="${CLR_LINK:-'#0000FF'}"
CLR_ALINK="${CLR_ALINK:-'#777700'}"
CLR_VLINK="${CLR_VLINK:-'#770000'}"
CLR_MENUBORDER="${CLR_MENUBORDER:-'#ABADC9'}"
CLR_MENUBG="${CLR_MENUBG:-'#DDDDDD'}"
CLR_MENUTEXT="${CLR_MENUTEXT:-'#000000'}"
SIZ_BASEFONT="${SIZ_BASEFONT:-'4'}"
CONTACT_NAME="${CONTACT_NAME:-'Dana French'}"
CONTACT_EMAIL="${CONTACT_EMAIL:-'dfrench@mtxia.com'}"
DATAFILE="menugen.dat"
GRANDCHILD="0"
HTMLFILES="0"
MENUPOS="left"
################################################################
syntax()
{
[ "_${1}" != "_" ] && ( echo ""; echo "${1}" )
echo ""
echo "Syntax: menugen [-g] [-S] [-u] [-f datafile] | -c | -C | -h"
echo " -c = Create a default \"menugen.cfg\" file"
echo " -C = Overwrite \"menugen.cfg\" file, even if it already exists"
echo " -g = Show grandchild links in menus"
echo " -R = Position menu box on Right side of page"
echo " -S = If the static menu bar exists, overwrite it with the default"
echo " -f = Use data file specified by value \"datafile\""
echo " -u = Underline Menu Links"
echo " -n = Generate .html files"
echo " -h = Display help file"
echo ""
}
################################################################
mkconfig()
{
if [ -f "./menugen.cfg" ]
then
echo "\"menugen.cfg\" file already exists, not overwritten"
return 1
fi
echo "THEME=\"Default Theme: Default Subtheme\" # Title displayed at top of every page" > ./menugen.cfg
echo "CLR_TEXT=\"#000000\" # Text color (default=#000000)" >> ./menugen.cfg
echo "CLR_BACKGRD=\"#FFFFFF\" # Background color (default=#FFFFFF)" >> ./menugen.cfg
echo "CLR_LINK=\"#0000FF\" # Link color (default=#0000FF)" >> ./menugen.cfg
echo "CLR_ALINK=\"#777700\" # Active Link color (default=#777700)" >> ./menugen.cfg
echo "CLR_VLINK=\"#770000\" # Viewed Link color (default=#770000)" >> ./menugen.cfg
echo "CLR_MENUBORDER=\"#ABADC9\" # Menu Border color (default=#ABADC9)" >> ./menugen.cfg
echo "CLR_MENUBG=\"#DDDDDD\" # Menu Background color (default=#DDDDDD)" >> ./menugen.cfg
echo "CLR_MENUTEXT=\"#000000\" # Menu Text color (default=#000000)" >> ./menugen.cfg
echo "SIZ_BASEFONT=\"4\" # Base Font Size (default=4)" >> ./menugen.cfg
echo "CONTACT_NAME=\"Dana French\" # Person responsible for this Page (default=Dana French)" >> ./menugen.cfg
echo "CONTACT_EMAIL=\"dfrench@mtxia.com\" # Email address of person responsible for this page (default=dfrench@mtxia.com)" >> ./menugen.cfg
chmod 755 ./menugen.cfg
echo "\"menugen.cfg\" file was created in the current directory."
return 0
}
################################################################
mg_footer()
{
echo "
<!-- Begin included file \"footer.shtml\" -->
<P><!--#include file=\"hr.shtml\" --></P>
<P>
<FONT Size=\"2\">
<ADDRESS>
For information regarding this page, contact
<A Href=\"mailto:${CONTACT_EMAIL}\">
${CONTACT_NAME} ( ${CONTACT_EMAIL} )</A>
</ADDRESS>
</FONT>
</P>
<!-- End included file \"footer.shtml\" -->
"
}
################################################################
mg_hr()
{
echo "
<!-- Begin included horizontal rule file \"hr.shtml\" -->
<TABLE Border=\"0\" Width=\"100%\" Cellspacing=\"0\" Cellpadding=\"0\">
<TR><TD Bgcolor=\"${CLR_MENUBORDER}\"><FONT Size=\"1\"> </FONT></TD></TR></TABLE>
<!-- End included horizontal rule file \"hr.shtml\" -->
"
}
################################################################
mg_staticbar()
{
echo "
<!-- Begin included static linkbar file \"staticbar.shtml\" -->
"
if [ "_${UNDERLINE}" != "_1" ]
then
echo "
<STYLE>
<!--
A { Color:${CLR_MENUTEXT}; text-decoration:none; }
A:hover { text-decoration:underline;color:${CLR_MENUTEXT}; }
//-->
</STYLE>
"
fi
echo "
<P>
<TABLE Border=\"0\" Cellspacing=\"5\" Cellpadding=\"0\" Align=\"right\"><TR><TD Bgcolor=\"white\">
<TABLE Border=\"0\" Width=\"100%\" Cellspacing=\"0\" Cellpadding=\"1\" Align=\"left\"><TR><TD Bgcolor=\"${CLR_MENUBORDER}\">
<TABLE Border=\"0\" Width=\"100%\" Cellspacing=\"0\" Cellpadding=\"5\" Align=\"left\">
<P>
<TR>
<TD Bgcolor=\"${CLR_MENUBG}\" Align=\"left\" Valign=\"top\">
<FONT Size=\"2\" Color=\"${CLR_MENUTEXT}\"><STRONG>
<A Href=\"http://www.mtxia.com\"> TXU </A>
| <A Href=\"http://www.mtxia.com\"> Documentation </A>
| <A Href=\"http://www.mtxia.com\"> Mt Xia </A>
</STRONG></FONT>
</TD>
</TR>
</P>
</TABLE>
</TD></TR></TABLE>
</TD></TR></TABLE>
</P>
"
if [ "_${UNDERLINE}" != "_1" ]
then
echo "
<STYLE>
<!--
A { Color:${CLR_LINK}; text-decoration:underline; }
A:hover { text-decoration:underline;color:${CLR_LINK}; }
//-->
</STYLE>
"
fi
echo "
<!-- End included static linkbar file \"staticbar.shtml\" -->
"
}
################################################################
mg_titlebar()
{
THEME1="${THEME}"
THEME2=" "
if echo "${THEME}" | grep ":" > /dev/null 2>&1
then
THEME1="${THEME%%:*}"
THEME2="${THEME#*:}"
fi
echo "
<!-- Begin included file \"titlebar.shtml\" -->
<P><FONT Size=\"6\" Color=\"#000000\">
<BR><STRONG>${THEME1}:</STRONG></FONT>
<FONT Size=\"4\" Color=\"#000000\"><STRONG><I>${THEME2}</I></STRONG></FONT>
<BR><!--#include file=\"hr.shtml\" --></P>
<!-- End included file \"titlebar.shtml\" -->
"
}
################################################################
for OPT in "$@"
do
case "${OPT}" in
"-c") mkconfig; exit 3;;
"-C") rm -f "./menugen.cfg"; mkconfig; exit 5;;
"-h") syntax | more - "/usr/local/sh/README.menugen"; exit 4;;
"-g") GRANDCHILD="1";;
"-R") MENUPOS="right";;
"-S") rm -f "./staticbar.shtml";;
"-f") DATAFILE="${2}";;
"-n") HTMLFILES="1";;
"-u") UNDERLINE="1";;
"-?") syntax "Help"; exit 2;;
esac
if [ "_${DATAFILE}" = "_" -o ! -s "${DATAFILE}" ]
then
syntax "Invalid data file name"
exit 1
fi
shift 2>/dev/null
done
if [ ! -s "${DATAFILE}" ]
then
syntax "Invalid data file"
exit 1
fi
echo "${DATAFILE} will be used to define pages and relationships"
[ "_${GRANDCHILD}" = "_1" ] && echo "Grandchild links will be shown on menus"
[ ! -f "./staticbar.shtml" ] && mg_staticbar > ./staticbar.shtml
mg_titlebar > ./titlebar.shtml
mg_hr > ./hr.shtml
mg_footer > ./footer.shtml
################################################################
while read PARENTID1 PAGEID1 PAGENAME1
do
echo ""
grep "^${PAGEID1} " ${DATAFILE} > /tmp/tmp1${$}.out
PARENTNAME=`grep " ${PARENTID1} " ${DATAFILE} | head -1 | sed -e "s/ /:/g;s/ /:/g" | cut -d":" -f3`
echo "${PARENTNAME}"
echo " ${PAGENAME1}" | tr '[a-z]' '[A-Z]'
if echo "${PARENTID1}" | grep "^#" > /dev/null 2>&1
then
continue
fi
if [[ "_${MENUPOS}" = "_right" ]]
then
echo "
<HTML>
<!-- PARENTID1=\"${PARENTID1}\" -->
<!-- PAGEID1=\"${PAGEID1}\" -->
<!-- PAGENAME1=\"${PAGENAME1}\" -->
<HEAD>
<TITLE>${PAGENAME1} - ${THEME}</TITLE>
</HEAD>
<BODY Bgcolor=\"${CLR_BACKGRD}\" Text=\"${CLR_TEXT}\" Link=\"${CLR_LINK}\" Alink=\"${CLR_ALINK}\" Vlink=\"${CLR_VLINK}\">
<BASEFONT Size=\"${SIZ_BASEFONT}\">
<!--#include file=\"staticbar.shtml\" -->
<!--#include file=\"titlebar.shtml\" -->
<TABLE Cellspacing=\"0\" Cellpadding=\"0\" Border=\"0\">
<P><TR><TD Width=\"100%\" Valign="top">
<P><H2>${PAGENAME1}</H2></P>
<P><HR></P>
</TD><TD Align=\"right\" Valign=\"top\" rowspan=\"2\">
<!--#include file=\"${PAGEID1##*/}.menu.shtml\" -->
</TD></TR></P>
" > "${PAGEID1/#*\///tmp/}.shtml"
else
echo "
<HTML>
<!-- PARENTID1=\"${PARENTID1}\" -->
<!-- PAGEID1=\"${PAGEID1}\" -->
<!-- PAGENAME1=\"${PAGENAME1}\" -->
<HEAD>
<TITLE>${PAGENAME1} - ${THEME}</TITLE>
</HEAD>
<BODY Bgcolor=\"${CLR_BACKGRD}\" Text=\"${CLR_TEXT}\" Link=\"${CLR_LINK}\" Alink=\"${CLR_ALINK}\" Vlink=\"${CLR_VLINK}\">
<BASEFONT Size=\"${SIZ_BASEFONT}\">
<!--#include file=\"staticbar.shtml\" -->
<!--#include file=\"titlebar.shtml\" -->
<!--#include file=\"${PAGEID1##*/}.menu.shtml\" -->
<P><H2>${PAGENAME1}</H2></P>
<P><HR></P>
" > "${PAGEID1/#*\///tmp/}.shtml"
fi
################################################################
echo "
<!-- Begin included menu file \"${PAGEID1}.menu.shtml\" -->
" > "${PAGEID1/#*\///tmp/}.menu.shtml"
if [ "_${UNDERLINE}" != "_1" ]
then
echo "
<STYLE>
<!--
A { Color:${CLR_MENUTEXT}; text-decoration:none; }
A:hover { text-decoration:underline;color:${CLR_MENUTEXT}; }
//-->
</STYLE>
" >> "${PAGEID1/#*\///tmp/}.menu.shtml"
fi
echo "
<P Align=\"right\">
<TABLE Border=\"0\" Width=\"20%\" Cellspacing=\"5\" Cellpadding=\"0\" Align=\"left\"><TR><TD Bgcolor=\"white\">
<TABLE Border=\"0\" Width=\"100%\" Cellspacing=\"0\" Cellpadding=\"1\" Align=\"left\"><TR><TD Bgcolor=\"${CLR_MENUBORDER}\">
<TABLE Border=\"0\" Width=\"100%\" Cellspacing=\"0\" Cellpadding=\"5\" Align=\"left\">
<P>
<TR>
<TD Bgcolor=\"${CLR_MENUBG}\" Align=\"left\" Valign=\"top\">
<FONT Size=\"2\" Color=\"${CLR_MENUTEXT}\">
<I>Current:</I><STRONG>${PAGENAME1}</STRONG>
<BR><A Href=\"${PARENTID1}.shtml\"><I>Previous:</I>${PARENTNAME}</A>
" >> "${PAGEID1/#*\///tmp/}.menu.shtml"
if [ "_${PARENTNAME}" != "_Home Page" ]
then
echo "<BR><A Href=\"index.shtml\">Home Page</A>" >> "${PAGEID1/#*\///tmp/}.menu.shtml"
fi
echo "<BR>" >> "${PAGEID1/#*\///tmp/}.menu.shtml"
while read PARENTID2 PAGEID2 PAGENAME2
do
LINK="${PAGEID2}.shtml"
if echo "${PAGEID2}" | grep "#" > /dev/null 2>&1
then
LINK=`echo "${PAGEID2}"`
fi
echo " ${PAGENAME2}"
echo "<BR><A Href=\"${LINK}\">${PAGENAME2}</A>" >> "${PAGEID1/#*\///tmp/}.menu.shtml"
grep "^${PAGEID2} " ${DATAFILE} > /tmp/tmp2${$}.out
if [ "_${GRANDCHILD}" = "_1" ]
then
ICNT=0
echo "<FONT Size=\"1\">" >> "${PAGEID1/#*\///tmp/}.menu.shtml"
while read PARENTID3 PAGEID3 PAGENAME3
do
ICNT="1"
LINK="${PAGEID3}.shtml"
if echo "${PAGEID3}" | grep "#" > /dev/null 2>&1
then
LINK=`echo "${PARENTID3}.shtml${PAGEID3}"`
fi
echo " ${PAGENAME3}"
echo " <LI> <A Href=\"${LINK}\">${PAGENAME3}</A></LI>" >> "${PAGEID1/#*\///tmp/}.menu.shtml"
done < /tmp/tmp2${$}.out
echo "</FONT>" >> "${PAGEID1}.menu.shtml"
[ "_${ICNT}" != "_0" ] && echo "<BR>" >> "${PAGEID1/#*\///tmp/}.menu.shtml"
fi
done < /tmp/tmp1${$}.out
################################################################
echo "
</FONT>
</TD>
</TR>
</P>
</TABLE>
</TD></TR></TABLE>
</TD></TR></TABLE>
</P>
" >> "${PAGEID1/#*\///tmp/}.menu.shtml"
if [ "_${UNDERLINE}" != "_1" ]
then
echo "
<STYLE>
<!--
A { Color:${CLR_LINK}; text-decoration:underline; }
A:hover { text-decoration:underline;color:${CLR_LINK}; }
//-->
</STYLE>
" >> "${PAGEID1/#*\///tmp/}.menu.shtml"
fi
echo "
<!-- End included menu file \"${PAGEID1}.menu.shtml\" -->
" >> "${PAGEID1/#*\///tmp/}.menu.shtml"
################################################################
if [[ "_${MENUPOS}" = "_right" ]]
then
echo "
<P><TR><TD>
<!--#include file=\"${PAGEID1}.content.shtml\" -->
</TD></TR></P>
</TABLE>
</P>
" >> "${PAGEID1/#*\///tmp/}.shtml"
else
echo "
<!--#include file=\"${PAGEID1}.content.shtml\" -->
" >> "${PAGEID1/#*\///tmp/}.shtml"
fi
echo "<!--#include file=\"footer.shtml\" -->
</BODY>
</HTML>
" >> "${PAGEID1/#*\///tmp/}.shtml"
if [[ ${HTMLFILES} -eq 1 ]]
then
echo "
<HTML>
<!-- PARENTID1=\"${PARENTID1}\" -->
<!-- PAGEID1=\"${PAGEID1}\" -->
<!-- PAGENAME1=\"${PAGENAME1}\" -->
<HEAD>
<TITLE>${PAGENAME1} - ${THEME}</TITLE>
</HEAD>
<BODY Bgcolor=\"${CLR_BACKGRD}\" Text=\"${CLR_TEXT}\" Link=\"${CLR_LINK}\" Alink=\"${CLR_ALINK}\" Vlink=\"${CLR_VLINK}\">
<BASEFONT Size=\"${SIZ_BASEFONT}\">
" > "${PAGEID1/#*\///tmp/}.html"
cat "staticbar.shtml" >> "${PAGEID1/#*\///tmp/}.html"
cat "titlebar.shtml" >> "${PAGEID1/#*\///tmp/}.html"
cat "hr.shtml" >> "${PAGEID1/#*\///tmp/}.html"
if [[ "_${MENUPOS}" = "_right" ]]
then
echo "
<TABLE Cellspacing=\"0\" Cellpadding=\"0\" Border=\"0\">
<P><TR><TD Width=\"100%\">
<P><H2>${PAGENAME1}</H2></P>
<P><HR></P>
</TD><TD Align=\"right\" Valign=\"top\" rowspan=\"2\">
" >> "${PAGEID1}.html"
cat "${PAGEID1}.menu.shtml" >> "${PAGEID1/#*\///tmp/}.html"
echo "
</TD></TR></P>
<P><TR><TD>
" >> "${PAGEID1/#*\///tmp/}.html"
cat "${PAGEID1}.content.shtml" >> "${PAGEID1/#*\///tmp/}.html"
echo "
</TD></TR></P>
</TABLE>
</P>
" >> "${PAGEID1/#*\///tmp/}.html"
else
cat "${PAGEID1}.menu.shtml" >> "${PAGEID1/#*\///tmp/}.html"
echo "<P><H2>${PAGENAME1}</H2></P>
<P><HR></P>
" >> "${PAGEID1/#*\///tmp/}.html"
cat "${PAGEID1}.content.shtml" >> "${PAGEID1/#*\///tmp/}.html"
fi
cat "hr.shtml" >> "${PAGEID1/#*\///tmp/}.html"
cat "footer.shtml" >> "${PAGEID1/#*\///tmp/}.html"
echo "</BODY></HTML>" >> "${PAGEID1/#*\///tmp/}.html"
fi
done < ${DATAFILE}
rm -f /tmp/tmp1${$}.out
rm -f /tmp/tmp2${$}.out