hbbs

bbs.hlirc.net
Log | Files | Refs | README | LICENSE

commit ccc323d47260877a37b3a8c480be969b537f3750
parent 52927d29e36361fe27749b74768322ebd5777b0f
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 13 Jun 2021 12:17:44 +0100

h/atom.sh: prototype hook

Diffstat:
Ahooks/atom.sh | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+), 0 deletions(-)

diff --git a/hooks/atom.sh b/hooks/atom.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +cwd=$(dirname $0) +. $cwd/../config.sh + +command -v dateconv >/dev/null || { + echo "dateconv(1) needed!" >&2 + exit 3 +} + +mkdir -p "$hook_atom_output" + +for d in $datadir/boards/* +do + board=$(basename "$d" | tr '[:lower:]' '[:upper:]') + awk -F"\t" -v "board=$board" ' + BEGIN { + printf "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + printf "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n" + printf "<title type=\"text\">%s</title>\n", board + printf "<subtitle type=\"text\">Postings from %s</subtitle>\n", board + } + { + gsub(/>/, "\&gt;", $0) + gsub(/</, "\&lt;", $0) + + cmd = sprintf("%s %s", "dateconv -i%d-%b-%Y -f%Y-%m-%dT%H:%M:%SZ", $3) + cmd | getline date + close(cmd) + + if ($6 == $7) { + title = $5 + stitle = title + } else { + title = sprintf("Re: %s", stitle) + } + + printf "\t<entry>\n" + printf "\t\t<published>%s</published>\n", date + printf "\t\t<title type=\"text\">[%s] <%s> %s</title>\n", board, $4, title + printf "\t\t<author><name>%s</name></author>\n", $4 + printf "\t</entry>\n" + } + END { + printf "</feed>\n" + }' < "$d/list" | tee "$hook_atom_output/$board.xml" +done | awk ' + BEGIN { + printf "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + printf "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n" + } + /^\t/ + END { + printf "</feed>\n" + }' > "$hook_atom_output/all.xml"