#!/bin/tcsh -f
# Run this when you add or change entries and want them
# to be incorporated into the formatted journal.
# What format should dates be displayed in? (see "man date")
set dateFmt="+%A, %B %d, %Y"
# Do you want the index in forward or reverse chronological order?
#set order=forward
set order=reverse
# NOTE Neither of these dirs should be a child of Journal:
# Where are you going to put images (relative to Journal/)?
set imsDir="../ims"
# Where do you want to keep scripts (relative to Journal/)?
set scriptsDir="/home/simon/scripts"
# The rest of this script is generic.
# (I.e., you shouldn't need to change anything below here.)
if (! -d entries) then
echo "'entries' source directory doesn't exist."
exit 1
endif
if (! -d parts) then
echo "'parts' source directory doesn't exist."
exit 1
endif
if (! -d Journal) then
echo "Journal target directory doesn't exist. Make it."
exit 1
endif
echo "Searching for new entries..."
# For now, we'll just use files containing a ".h" in their name
# to signify highlights:
#
cd entries
set entries=*
set entriesH=*.h*
cd ..
echo "There are $#entries raw entries to date ($#entriesH highlights)..."
# It's easiest just to rebuild the index from scratch...
# We'll throw the index entries into a temp file so we
# can stick it together with header and footer later.
# (This also lets us reverse the order at that time if
# we choose...):
echo -n "" > Journal/index.tmp
# Let's also make a Highlights index:
echo -n "" > Journal/indexh.tmp
# Backing up from the begining drops you back in the index:
set prevFile="index.html"
set prevFileH="indexh.html"
while ($#entries > 0)
# Pull the next entry off the list:
set entry="$entries[1]"
shift entries
# And if it's the same as the next highlight entry,
# make a note of it and pull it off the highlight list too:
set highlight="0"
if ($#entriesH > 0) then
if ("$entry" == "$entriesH[1]") then
set highlight="1"
shift entriesH
endif
endif
# Check and make sure the file's name has a reasonable format:
set dateString=`date -d $entry:r:r "$dateFmt"`
if ($status != 0) then
echo "WARNING: entry '$entry:r:r' ($entry) cannot be parsed as a date. Please fix."
continue
endif
# Project the name of the Next entry:
if ($#entries > 0) then
set nextFile="$entries[1].html"
else
set nextFile="index.html"
endif
# Project the names of the next Highlight entry:
if ($#entriesH > 0) then
set nextFileH="$entriesH[1].html"
else
set nextFileH="indexh.html"
endif
# Source and destination files:
set entryFile="entries/$entry"
set target="Journal/$entry.html"
# Extract the title of the entry:
set title=`head -1 $entryFile | sed -f NameMappings`
# Count the images in the entry:
set numims=`grep " 0) then
set imnote="($numims)"
else
set imnote=""
endif
# Count the mp3's in the entry:
set nummps=`grep ".mp3" $entryFile | wc -l`
if ($nummps > 0) then
set mpnote="($nummps)"
else
set mpnote=""
endif
# Add the entry to the index:
echo -n "