summaryrefslogtreecommitdiff
path: root/scripts/sh/wsctl
blob: fde1e93ff94f320099140d6c51aa08c259981061 (plain) (blame)
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
#!/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."