back to index

AutoIDXgen

Why

Maintaining descriptions of projects is a hassle, especially in 4:30AM when the developer finished a project, finished updating its own page, and wants to sleep. The index page is then often forgotten or neglected. This tool allows storing project descriptions in the index pages of individual projects instead of keeping them in separate file in parent directory.

How

The script, when executed, outputs the defined page header (stored within the script) to the predefined output file (./index.php by default). Then it scans all the subdirectories, and extracts the descriptions from there, forming a table of two columns, with the subdirectory name, and with the description. The description can be stored in README.html file, which Apache in default configuration adds to the autogenerated index. If this file isn't present, the project's name and description are extracted from the index.php file, where it is stored in a comment in a grep-friendly format. Example from this file itself:

<? /*
IDXNAME:AutoIDXgen
IDXDESC:Simplifies maintenance of project list description webpages
IDXDESC:by allowing storing the informations in the projects' pages.
*/ ?>

Editing this section is easier, as it is in plain view, making it less prone to forgetting to update. The mkindex script then has to be run. Alternatively, it can be run daily from crontab, in the worst case keeping the site nonupdated for only a day.

If the "IDXBOLD:" line is present in the index.php file, the link to the directory is shown in bold font. Useful for highlighting a project that's bigger or more important than the other ones.

The script contains a "safety belt" routine; before writing the output file, the script checks for its presence. If the file is present, the "AutoIDXgen autogenerated" string presence is checked for. If not present, the script refuses to overwrite the output file. This can save you a lot of work.

Download

Get the script here: mkindex.sh

Script list:

#!/bin/bash
OUT=index.php

# safety belt
if [ -f $OUT ]; then
  if [ "`grep "^AutoIDXgen generated" $OUT`" == "" ]; then
   echo Error: Refusing to overwrite $OUT as I am not sure I should.
   exit 1
  fi
fi

cat > $OUT << EOF
<HTML>
<HEAD>
<TITLE>Page Title</TITLE>
<H1>Page Title</H1>
<HR>
<TABLE WIDTH=100% CELLSPACING=10>
EOF

for x in *; do
  if [ -d "$x" ]; then
    BOLD="";NOBOLD="";
    if [ -f "$x/index.php" ]; then
      if [ "`grep "^IDXBOLD:" "$x/index.php"`" ]; then
	BOLD="<B>";NOBOLD="</B>";
      fi
    fi
    echo "<TR><TD VALIGN=TOP>$BOLD<A HREF=\"$x\">$x</A>$NOBOLD</TD><TD>" >> $OUT
    if [ -f "$x/README.html" ]; then
     cat "$x/README.html" >> $OUT
    elif [ -f "$x/index.php" ]; then
     PROJECTNAME="`grep "^IDXNAME:" "$x/index.php"|cut -b 9-`"
     if [ "$PROJECTNAME" ]; then
       echo "<B>$PROJECTNAME</B> - " >> $OUT
     fi
     grep "^IDXDESC:" $x/index.php|cut -b 9- >> $OUT
    else
     echo "&nbsp;" >> $OUT
    fi
    echo "</TD></TR>" >> $OUT
  fi
done

cat >> $OUT << EOF
</TABLE>
<HR>
Some other comments for the project page.
</BODY>
</HTML>
EOF

If you have any comments or questions about the topic, please let me know here:
Your name:
Your email:
Spambait
Leave this empty!
Only spambots enter stuff here.
Feedback: