[<< | Prev | Index | Next | >>] Monday, February 07, 2000
Scripting the Journal - A Meta Entry
Very cool. (If I don't say so myself.) I've got my journal scripted so all I have to do is make an entry in a file named by the date (e.g., this file is 20000207), with the Title as the first line, and it automagically gets headerred and footerred and titled and indexed and dated and formatted and next-linked and all that.Here's the script:
#!/bin/csh -f # Run this when you add new 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" 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..." cd entries set entries=* cd .. echo "There are $#entries raw entries to date..." # It's easiest just to rebuild the index from scratch... /bin/rm -f Journal/index.html sed -f NameMappings < parts/indexHeader > Journal/index.html set previous="NONE" foreach entry ($entries) set dateString=`date -d $entry "$dateFmt"` if ($status != 0) then echo "WARNING: entry '$entry' cannot be parsed as a date. Please fix." continue endif set target="Journal/$entry.html" # To make 'next' links easy, we'll create a symlink # from the previous entry to this one: if ("$previous" != "NONE") then set nextlink="$previous.next.html" if (! -e "Journal/$nextlink") then echo Linking "$nextlink" to "$entry.html" ln -s "$entry.html" "Journal/$nextlink" endif endif set previous="$entry" set title=`head -1 entries/$entry | sed -f NameMappings` echo "<tr><td align=right><a href=$entry.html>${dateString}</a></td>" >> Journal/index.html echo "<td>$title</td></tr>" >> Journal/index.html # If the target already exists, we don't need to make it again: if (-e "$target") continue echo "New on ${dateString}: $title" # Here's where we actually put the pieces together into a target entry: echo "<html>" > "$target" echo "<title>$title</title>" >> "$target" sed -f NameMappings < parts/header >> "$target" echo "<br>" >> "$target" echo "<br>" >> "$target" echo "<center>" >> "$target" echo '<font face="Arial,Helvetica">' >> "$target" echo '<font size=+1>' >> "$target" echo "<h2>$dateString</h2>" >> "$target" echo "<h4><em>$title</em></h4>" >> "$target" echo "</center>" >> "$target" echo "<br>" >> "$target" echo "<br>" >> "$target" tail +2 "entries/$entry" | sed -f NameMappings >> "$target" echo "<br><br>[<a href=$entry.next.html>Next</a>]" >> "$target" echo "[<a href=index.html>Index</a>]<p>" >> "$target" sed -f NameMappings < parts/footer >> "$target" end sed -f NameMappings < parts/indexFooter >> Journal/index.html echo "Index updated."[<< | Prev | Index | Next | >>]