: specifies the destination file for the diary.
-R : update the RSS and Atom feeds.
EOF
}
arg0=$(basename $0)
year=$(date '+%Y')
mode=diary
[ "$WEBBASE" = "" ] && WEBBASE="$HOME/Web"
diary="$HOME/Documents/Projects/self/diary-$year"
journaldir="$HOME/Sites/$USER/journal"
publish="$journaldir/journal-$year.html"
build="$journaldir/journal-$year.web"
rssfeed="$journaldir/journal-rss.xml"
atomfeed="$journaldir/journal-atom.xml"
journal="http://barella.org/Perette/Journal"
email="perette@barella.org"
spacetab=" "
direction=reverse
updatefeed=false
while getopts "pyjef:d:rRm?" option
do
case "$option" in
d)
publish="$OPTARG"
;;
p)
mode=publish ;;
y)
mode=dreams ;;
f)
diary="$OPTARG"
direction=forward
year=$(basename "$diary" | sed 's/diary-//')
publish="$journaldir/journal-$year.html"
build="$journaldir/journal-$year.web"
;;
j)
mode=journal
updatefeed=true ;;
e)
mode=edit ;;
r)
mode=read ;;
R)
updatefeed=true ;;
m)
mode=mirror ;;
?)
usage
exit 1
;;
esac
done
if [ "$mode" = "edit" ]
then
vi $diary
elif [ "$mode" = "read" ]
then
view $diary
exit 0
elif [ "$mode" = "publish" ]
then
:
else
echo >> $diary
date "+%Y-%m-%d %H:%M (%A) $mode" >> $diary
echo >> $diary
vi -c '$' $diary
fi
file=$(basename $diary)
if [ "$publish" -ot "$diary" -o "$mode" = "publish" ]
then
# The plan: Make a forward collection of reversed articles,
# then reverse the whole thing to get a reverse collection of
# forward articles.
articletemp="/var/tmp/$arg0.$$.tmp1"
maintemp="/var/tmp/$arg0.$$.tmp2"
pre=off
copy=off
newpara=false
linenum=0
(sed -e 's/&/\&/g' -e 's/"/\"/g' -e 's/\\/\\\\/g' \
-e 's/\</g' -e 's/>/\>/g' < "$diary";
echo "EOF-ETX") |
while IFS="" read aline
do
let linenum=linenum+1
case "$aline" in
[12][0-9][0-9][0-9]-[01][0-9]-[0-3][0-9]?*journal|EOF-ETX)
[ "$pre" = "on" ] &&
echo "" && pre=off
if [ -s "$articletemp" ]
then
if [ "$direction" = "reverse" ]
then
tail -r "$articletemp"
else
cat "$articletemp"
fi
fi
newpara=false
echo "" > "$articletemp"
copy=on
;;
[12][0-9][0-9][0-9]-[01][0-9]-[0-3][0-9]*)
copy=off
;;
[$spacetab-]*[^$spacetab]*|[a-zA-Z0-9][.\)]*|[1-9][0-9][.\)]*)
[ "$pre" = "off" -a "$copy" = "on" ] &&
echo "" >> "$articletemp" &&
pre=on && newpara=false
[ "$copy" = "on" ] && echo "$aline" >> "$articletemp"
;;
[Ii]mage:*)
image=$(echo "$aline" | cut -d: -f2 | awk '{print $1}')
fullpath=$(locate "$image" | grep "^$WEBBASE" |
grep "/Thumbnails/" | head -1)
if [ "$fullpath" != "" ]
then
imagepath=$(echo "$fullpath" | sed 's&/Thumbnails/&/&')
fullpath=$(echo "$fullpath" |
sed "s&^$WEBBASE&DIR_TOP&")
imagetitle=$(echo "$image" | sed 's/[-_]/ /g')
echo "_IMAGE($fullpath, ALT=\"$imagetitle\" ALIGN=RIGHT)" >> "$articletemp"
elif fullpath=$(locate "$image" | grep "^$WEBBASE" |
head -1); [ "$fullpath" != "" ]
then
fullpath=$(echo "$fullpath" |
sed "s&^$WEBBASE&DIR_TOP&")
imagetitle=$(echo "$image" | sed 's/[-_]/ /g')
echo "_THUMBNAIL($fullpath, 180, 150, ALT=\"$imagetitle\" ALIGN=RIGHT)" >> "$articletemp"
fi
;;
[Mm]ood:*)
mood=$(echo "$aline" | cut -d: -f2 | tr 'A-Z' 'a-z')
basemood=$(echo "$mood" |
sed -e 's/[^a-zA-Z]*//' -e 's/[^a-zA-Z]*$//')
if [ "$mood" != "" ]
then
echo "" >> "$articletemp"
if [ -f "$WEBBASE/Graphics/Mood/$basemood.gif" ]
then
echo "_IMAGE(DIR_GFX/Mood/$basemood.gif, ALT=\"$mood\", 50)" >> "$articletemp"
fi
echo "Mood: $mood" >> "$articletemp"
echo "
" >> "$articletemp"
fi
;;
*)
if [ "$copy" = "on" ]
then
[ "$pre" = "on" ] &&
echo "" >> "$articletemp" &&
pre=off && newpara=false
[ "$aline" != "" -a "$newpara" = "true" ] &&
newpara=false &&
echo "" >> "$articletemp"
[ "$aline" = "" ] && newpara=true
echo "$aline" >> "$articletemp"
fi
;;
esac
done | sed -e 's/^_\([A-Za-z][a-z]\)/\1/' \
-e 's/\([ ]\)_\([a-zA-Z]\)/\1\2/g' \
-e 's&\([a-zA-Z0-9]\)_\([^a-zA-Z0-9]\)&\1\2&g' \
-e 's&\([a-zA-Z0-9]\)_$&\1&' >> "$maintemp"
realname=$(finger $USER | head -1 | sed 's/.*Name://')
firstname=$(echo "$realname" | awk '{print $1}')
echo "m4_include(stddefs.m4)
_HEADER(\`\`$firstname's journal: $year'', \`\`\$Id: diary,v 1.11 2006/04/05 02:48:50 perette Exp $'')" > "$build"
[ -f "$journaldir/journalmenu.m4" ] &&
echo "m4_include(journalmenu.m4)" >> "$build"
echo "
$firstname's journal: $year
" >> "$build"
if [ "$direction" = "reverse" ]
then
tail -r "$maintemp" >> "$build"
else
cat "$maintemp" >> "$build"
fi
rm -f "$articletemp" "$maintemp"
if [ "$updatefeed" = "true" -a "$direction" = "reverse" ]
then
generate_feed "$diary"
generate_feed "$diary"
fi
cd "$journaldir"
if make depend && make && [ -x ~/bin/upload ]
then
~/bin/upload journal
fi
fi
exit 0