#!/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."