1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
#!/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 <<HEAD
<!DOCTYPE html>
<meta charset="utf8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>$title</title>
<style>
body{max-width:48em;font:20px/1.4 serif;margin:auto;padding:1em;
margin-bottom:4em;}
footer{position:fixed;bottom:0;left:0;padding:1em;background:white;}
dt{font-weight:bold;}
</style>
<body>
<!-- LIST_START -->
<h1>$title</h1>
HEAD
cat
cat <<FOOT
<!-- LIST_END -->
<footer>
$(test "$2" && printf '<a href="%s">%s</a>' "${2%%,*}" "${2##*,}")
$(case "$1" in (*index*)
echo '<ul style="margin:0;padding:0;">'
printf '<li style="list-style:none;margin:0"><a href="%s">%s</a></li>\n' \
"$BASE_URL/feed.xml" feed \
"https://git.acdw.net/ll" source \
"https://www.acdw.net" home
echo "</ul>"
;; esac)
</footer>
</body></html>
FOOT
}
# Library
list()(tag="$1";shift;echo "<$tag>"; sed 1d|awk "$@"; echo "</$tag>")
# unordered list
ul()(list ul '/^$/{next}{printf "<li>%s</li>\n",$0}')
# ordered list
ol()(list ol '/^$/{next}{printf "<li>%s</li>\n",$0}')
# anchor (link) list
al()(list ul -F"\n" -vRS= '{printf "<li><a href=\"%s\">%s</a></li>\n",$1,$2}')
# definition list
dl()(list dl -F"\n" -vRS= '{printf "<dt>%s</dt>\n<dd>%s</dd>\n",$1,$2}')
rss() {
cat <<HEAD
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>$(sed 1q index.al)</title>
<link href="$BASE_URL/feed.xml" rel="self" />
<link href="$BASE_URL" />
<id>$BASE_URL</id>
<rights>$SITE_COPYRIGHT</rights>
<updated>$(date +%FT%TZ)</updated>
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 "<entry>\n<id>%s</id>\n", url
printf "<link rel=\"alternate\" href=\"%s\" />\n", url
printf "<title>%s</title>\n", title
printf "<author><name>%s</name></author>\n", author
printf "<updated>%s</updated>\n", updated
printf "<content type=\"html\"><![CDATA[%s]]></content>\n",
slurp(file)
printf "</entry>\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
</feed>
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 "$@"
|