#!/bin/bash
#	Useage:	makehowtoindex	title
#	(c) Thierry Vignaud <tvignaud@mandrakesoft.com>, MandrakeSoft.
#	This soft is released under the GNU GPL (see http://ww.gnu.org for further
#	information)
#
#   Modified by Ivan Zakharyaschev <vanyaz@mccme.ru> for Mandrake RE, 
#    ALT Linux Team, March 2001.
#
#   Modified by Maxim Dzumanenko <mvd@altlinux.ru>
#
#   It should be invoked like this:
#
#       makehowtoindex Language metaElem1 metaElem2 ...
#
#   where metaElem's are some HTML-elements to be inserted into the HEAD
#   of the generated document (useful for including Content-Type/charset
#   meta-information).

LANG=$1
shift

# Meta information can be included: one line per one commandline argument
oldIFS="$IFS"
IFS=$'\n'
METAs="$*"
IFS="$oldIFS"
unset oldIFS

if [ -d html ]; then
	mv html/* .
	rmdir html
fi

{ 

cat <<EOF
<HTML><HEAD>
$METAs
<TITLE>$LANG HOWTOs and mini-HOTOWs</TITLE>
<!-- Index.html for "$LANG" Howtos & mini-Howtos -->
<!-- Copyright 2000 Thierry Vignaud <tvignaud@mandrakesoft.com>, MandrakeSoft -->
<!-- Modified by Ivan Zakharyaschev <vanyaz@mccme.ru> for Mandrake RE, 
<!--  ALT Linux Team, March 2001. -->
<!-- Distribuable under terms of GPL Licence -->
</HEAD>
<BODY BGCOLOR=WHITE>
<FONT face="Verdana, Arial, Helvetica, sans-serif" size="2">

<TABLE BORDER="0"><TR><TD  colspan="2"><img src="/usr/share/doc/HOWTO/HTML/howto_title.png">
<TR><TD WIDTH="11%" BGCOLOR="#ffcc00"><IMG SRC="/usr/share/doc/HOWTO/HTML/howto.png">
<TD WIDTH="89%" BGCOLOR="#ffcc00">
<H1 Align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"> 
<font size="5" color="#666699">HOWTOs</font></font></h1>
<TR><td width="11%" bgcolor="#CCCCFF">&nbsp;</td>
<td width="89%">
<UL>
EOF


process_list ()
{
	local TITLE titleElem='<\(TITLE\|title\)>\(.\+\)</\(TITLE\|title\)>'
	for file in $HOWTOS_LIST
	do
 		TITLE="$(< "$file.dsc")"
 		echo "<LI><A HREF=\"$file/index.html\">${TITLE:-${file##*/}}</A>"
	done
}

#HOWTOS_LIST=$(ls *.html|sed -e 's!.html!!g'|egrep '*-HOWTO$')
HOWTOS_LIST=$(ls *.dsc|sed -e 's/\.dsc//')

process_list

cat <<EOF
</UL></TD>
<TR><TD>
<BR><BR><BR>
<tr>
    <td width="11%" height="24" bgcolor="#FFCC00">
      <div align="center"><img src="/usr/share/doc/HOWTO/HTML/minihowto.png" width="48"
height="48"></div>
    </td>
    <td width="89%" height="24" bgcolor="#FFCC00">
      <div align="center"><font face="Verdana, Arial, Helvetica, sans-serif"
size="3"><b><font size="5" color="666699">Mini-HOWTOs
    </td>
  </tr>
  <tr>
    <td width="11%" bgcolor="#CCCCFF">&nbsp;</td>
    <td width="89%">

<UL>

EOF

HOWTOS_LIST=$(ls mini/*.dsc|sed -e 's/\.dsc//')
process_list
cat <<EOF
</UL></TABLE>
</FONT>
</BODY></HTML>
EOF

} > index.html
