#!/bin/sh
# Config
BASE_URL=https://www.acdw.net/lists
SITE_TITLE="a listlog"
SITE_COPYRIGHT="Case Duckworth"
BACK_LINK=index.html,back
wrap() {
title="$(sed 1q "$1")"
cat <
$title
$title
HEAD
cat
cat <
FOOT
}
# Library
list()(tag="$1";shift;echo "<$tag>"; sed 1d|awk "$@"; echo "$tag>")
# unordered list
ul()(list ul '/^$/{next}{printf "%s\n",$0}')
# ordered list
ol()(list ol '/^$/{next}{printf "%s\n",$0}')
# anchor (link) list
al()(list ul -F"\n" -vRS= '{printf "%s\n",$1,$2}')
# definition list
dl()(list dl -F"\n" -vRS= '{printf "%s\n%s\n",$1,$2}')
rss() {
cat <
$(sed 1q index.al)
$BASE_URL
$SITE_COPYRIGHT
$(date +%FT%TZ)
HEAD
# entries
awk -F"\n" -vRS= \
-vbase="$BASE_URL" \
-vauthor="$SITE_COPYRIGHT" \
'NR==1{next}
{ url=$1; title=$2; updated=$3;
file=url; sub(base "/", "", file)
printf "\n%s\n", url
printf "\n", url
printf "%s\n", title
printf "%s\n", author
printf "%s\n", updated
printf "\n",
slurp(file)
printf "\n"
}
function slurp (file, out, bodyp) {
oldRS=RS; RS="\n"
while ((getline < file) > 0) {
if ($0 ~ /LIST_END/) bodyp = 0
if (bodyp) out = out (out?"\n":"") $0
if ($0 ~ /LIST_START/) bodyp = 1
}
RS=oldRS
return out
}'
cat <
FOOT
}
modtime() {
mtime="$(stat -c%Y "$1" 2>/dev/null ||
stat -f%Sm -t%FT%TZ "$1" 2>/dev/null)"
if test -n "$mtime"
then
# busybox date
date -u -d "@$mtime" +%FT%TZ
fi
}
# Main
main() {
printf "%s\n\n" "$SITE_TITLE" > index.al
ls -t *.ul *.dl *.ol *.al 2>/dev/null |
sed '/index.al/d' |
while read -r lst
do
printf >&2 "Processing %s..." "$lst"
"${lst##*.}" < "$lst" |
wrap "$lst" "$BACK_LINK" > "${lst%%.*}.html"
printf '%s\n%s\n%s\n\n' \
"$BASE_URL/${lst%%.*}.html" \
"$(sed 1q "$lst")" \
"$(modtime "$lst")" \
>> index.al
echo >&2 ok
done
printf >&2 "Processing index..."
al < index.al | wrap index.al > index.html &&
echo >&2 ok
printf >&2 "Processing rss..."
rss < index.al > feed.xml &&
echo >&2 ok
}
main "$@"