diff options
Diffstat (limited to 'scripts/sh/wsctl')
-rwxr-xr-x | scripts/sh/wsctl | 64 |
1 files changed, 64 insertions, 0 deletions
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="<table><tr><th>date</th> <th>type</th> <th>title</th></tr>\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<tr><td>$(sed -n 2p $f)</td> <td>$type</td> <td><a href=\"/$type/$(basename "$f")\">$(sed -n 1p $f)</td></a></tr>\n" + done + + out="$header$(printf "$out" | sort -rk 1)\n</table>\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." |