#!/bin/sh
# 
# DIRECTIFY: Create the Image Directory for a Game.

if [ -f .header ]
   then
   cat .header >index.html
fi

# Get rid of garbage.

find . -type f -size -5 -print -maxdepth 1 | grep jpg | xargs rm -f

# Make a list of subdirectories, adding icons if there is one.

echo "<TABLE WIDTH=100%>" >>index.html

for each in [A-Z]*
    do
    if [ -d "$each" ]
       then
       echo "<TR><TD BGCOLOR=#004400 ALIGN=CENTER>" >>index.html
       echo "<TD ALIGN=CENTER BGCOLOR=#002200><FONT FACE=Arial Size=+2 COLOR=#FFFFFF><B>$each</B>" >>index.html
       echo "<BR><I><small>(`ls $each/* | grep -v index.html | wc -l` Images)</I></small></FONT>" >>index.html
    fi
    done
echo "</TABLE><P>" >>index.html

# Now, go in and make thumbnails. This kills the processor.

              if [ ! -f .descs ]
                 then
                 touch .descs
              fi

       for father in *
           do
           if [ ! "$father" = "index.html" ]
              then
              if [ ! -d "$father" ]
                 then
                 if [ ! -f ".thumbs/$father" ]
                    then
                    echo "Thumbnailing $directory/$father...."
                    cp "$father" ".thumbs/$father"
                    mogrify -geometry 100 ".thumbs/$father"
                 fi

              DESC="`grep $father .descs | cut -f2- -d' '`"
              echo "<A HREF=\"$father\"><IMG ALT=\"$DESC\" SRC=\".thumbs/$father\" HEIGHT=130 BORDER=0></A>" >>index.html

# Ahh! Recursion! If the directory has images, go in there too.
  
              else
              if [ -d "$father/.thumbs" ]
                 then
                 echo "[%] Found a $father sub-directory. Making a page."
                 cd $father
                 /webdocs/computist/directify
                 cd ..
              fi
              fi
           fi
           done

if [ -f .footer ]
   then
   cat .footer >>index.html
fi

