#!/bin/sh

# Auto-generate a list of topics I've blogged about

topicfile=$HOME/web/blog/newtopics.html

cat << HEADEREOF >$topicfile
<html>
<head>
<title>Shallow Thoughts Archives</title>
<style type="text/css" title="Blogstyle">
 @import "/blog/blog.css";
</style>
</head>
<body>
<div id='content'>
<a class="title" href="http://shallowsky.com/blog/">
<div id='blogtitle'>
<h1 class="title">Shallow Thoughts Archive</h1>
<span class="description">Akkana's Musings on Open Source, Science, and Nature.</span>
</div>
</a>
<h2>Shallow Thoughts Archive</h2>
<p>
This is a list of all the entries on the
<a href="http://shallowsky.com/blog/">Shallow Thoughts</a> blog.
<p>
The list is auto-generated: the topics are in alphabetical order,
entries within topics in reverse chronological order.
<p>
I don't expect it's useful for browsing, but it's a good place to
search for keywords.
</p>

HEADEREOF

techdirs="linux linux/laptop linux/kernel linux/install linux/editors gimp programming tech tech/web tech/security tech/hardware science science/astro science/geology mapping conferences conferences/lca2008 conferences/lca2009"

nontechdirs="nature nature/birds nature/squirrels nature/trails education humor misc photo headlines blogging writing speaking travel travel/tasmania travel/melbourne08 travel/mojave travel/southpark travel/sydney travel/anasazi politics politics/election04 politics/rights"

echo "<p>" >>$topicfile
echo "<b>Technical categories:</b>" >>$topicfile
for dir in $techdirs ; do
  echo "<a href=\"#$dir\">$dir</a> |" >>$topicfile
done
echo "</p><p>" >>$topicfile
echo "<h3>Non-technical categories:</h3>" >>$topicfile
for dir in $nontechdirs ; do
  echo "<a href=\"#$dir\">$dir</a> |" >>$topicfile
done
echo "</p>" >>$topicfile

list_dir() {
#  if [ $dir = '.' ] || [ $dir = './images' ]; then
#    continue
#  fi
#  dir=$(echo $dir | sed 's_^./__')
  dir="$1"
  echo "<a name=\"$dir\">" >>$topicfile
  echo -n "$dir "
  echo " " >>$topicfile
  echo '<div class="story">' >>$topicfile
  echo "<h2 class='story'>$dir</h3>" >>$topicfile
  echo "<ul>" >>$topicfile
  files=$(/bin/ls -t $dir/*.blx 2> /dev/null)
  if [ $? = 2 ]; then
    continue
  fi

  for fil in $files ; do
    title=$(head -1 $fil)
    htmlfil=$(echo $fil | sed 's/\.blx/.html/')
    tags=$( grep '^#tags ' $fil | sed 's/^#tags //')
    echo "<li><a href='/blog/$htmlfil'>$title</a> <i>(Tags: $tags)</i>" >>$topicfile
  done
  echo "</ul>" >>$topicfile
  echo '</div>' >>$topicfile
}

echo "<h2>Technical Topics</h2>" >> $topicfile
for dir in $techdirs ; do
  list_dir $dir
done
echo ""
echo "<h2>Non-technical Topics</h2>" >> $topicfile
for dir in $nontechdirs ; do
  list_dir $dir
done
echo "Done."

#cat $HOME/web/blogfiles/foot.html >>$topicfile
