From 82abadcecc7534b4847238ee2a977f33256b0439 Mon Sep 17 00:00:00 2001 From: George Abbott Date: Sun, 26 Jan 2025 11:37:22 +0000 Subject: sh --- scripts/sh/wsctl | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 scripts/sh/wsctl (limited to 'scripts/sh/wsctl') diff --git a/scripts/sh/wsctl b/scripts/sh/wsctl new file mode 100755 index 0000000..fde1e93 --- /dev/null +++ b/scripts/sh/wsctl @@ -0,0 +1,64 @@ +#!/bin/sh +# wsctl - scripts for general admin of the website + +usage() { + echo "wsctl [gen-wr-index | gen-wr-index-html | ls | today | week]" +} + +list() { + header="date\ttype\twc\ttitle\n" + for f in $(find $WWW_DEFAULT_PATH/src/wv \ + $WWW_DEFAULT_PATH/src/poetry $WWW_DEFAULT_PATH/src/prose \ + $WWW_DEFAULT_PATH/src/blog -type f | sort -k 3) ; do + out="$out$(sed -n 2p $f) $(basename "$(dirname "$f")") $(wc -w "$f" | awk '{print $1}') $(sed -n 1p $f)\n" + done + + out="$header$(printf "$out" | sort -rk 1)\n" + printf "$out" +} + +gen_wr_idx() { + header="date type title\n" + for f in $(find $WWW_DEFAULT_PATH/src/wv \ + $WWW_DEFAULT_PATH/src/poetry $WWW_DEFAULT_PATH/src/prose \ + $WWW_DEFAULT_PATH/src/blog -type f | sort -k 3) ; do + out="$out$(sed -n 2p $f) $(basename "$(dirname "$f")") $(sed -n 1p $f)\n" + done + + out="$header$(printf "$out" | sort -rk 1)\n" + + printf "$out" + +} + +gen_wr_idx_html() { + header="\n" + for f in $(find $WWW_DEFAULT_PATH/src/wv \ + $WWW_DEFAULT_PATH/src/poetry $WWW_DEFAULT_PATH/src/prose \ + $WWW_DEFAULT_PATH/src/blog -type f | sort -k 3) ; do + type="$(basename "$(dirname "$f")")" + out="$out\t\n" + done + + out="$header$(printf "$out" | sort -rk 1)\n
date type title
$(sed -n 2p $f) $type $(sed -n 1p $f)
\n" + + printf "$out" +} + +today() { + list | grep "$(date +%Y-%m-%d)" +} + +week() { + # TODO + echo "" +} + +[ -z "$WWW_DEFAULT_PATH" ] && echo "WWW_DEFAULT_PATH not set" && exit 1 +[ "$1" = "gen-wr-index" ] && gen_wr_idx && exit 0 +[ "$1" = "gen-wr-index-html" ] && gen_wr_idx_html && exit 0 +[ "$1" = "today" ] && today && exit 0 +[ "$1" = "ls" ] && list && exit 0 +[ "$1" = "help" ] && usage && exit 0 + +echo "No command passed; run wsctl help for info." -- cgit v1.2.1