gdritter repos lib-static / 4878f33
Better error handling in shell scripts + more efficient impl of json-{list,dict} Getty Ritter 9 years ago
11 changed file(s) with 71 addition(s) and 48 deletion(s). Collapse all Expand all
6969 mkdir -p `dirname $@`
7070 bin/work.sh $(DATADIR) $< >$@
7171
72 $(OUTDIR)/category/%/index.html: $(DATADIR)/works/% $(DATADIR)/works/%/* templates/worklist.mustache templates/main.mustache
72 $(OUTDIR)/category/%/index.html: $(DATADIR)/works/% $(DATADIR)/works/%/* templates/list.mustache templates/main.mustache
7373 mkdir -p `dirname $@`
7474 bin/category.sh $(DATADIR) $< >$@
7575
76 $(OUTDIR)/category/index.html: templates/worklist.mustache templates/main.mustache
76 $(OUTDIR)/category/index.html: templates/list.mustache templates/main.mustache
7777 mkdir -p `dirname $@`
7878 bin/all-categories.sh $(DATADIR) >$@
7979
1 #!/bin/sh
1 #!/bin/sh -e
2
3 if [ "$#" -lt "1" ]; then
4 echo "Not enough arguments to $(basename $0)"
5 echo "Usage: $(basename $0) [data-dir]"
6 exit 1
7 fi
28
39 DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
410 PATH=$DIR:$PATH
612 cat $1/works.json \
713 | jq '[.[] | { slug: ("category/" + .slug), name: .category }]' \
814 | json-dict works - \
9 | mustache - templates/worklist.mustache \
15 | mustache - templates/list.mustache \
1016 | json-dict title 'Permanent Collections' contents - \
1117 | mustache - templates/main.mustache
1 #!/bin/sh
1 #!/bin/sh -e
2
3 if [ "$#" -lt "2" ]; then
4 echo "Not enough arguments to $(basename $0)"
5 echo "Usage: $(basename $0) [data-dir] [category-name]"
6 exit 1
7 fi
28
39 DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
410 PATH=$DIR:$PATH
612 SLUG=$(basename $2)
713 NAME=$(cat $1/works.json | jq ".[] | select(.slug == \"$SLUG\").category")
814 if [ "x$NAME" = "x" ]; then
9 echo "Unable to find category: $1" >&2
10 exit 1
15 echo "Unable to find category: $1" >&2
16 exit 1
1117 fi
1218
1319 json-list -c $2/*/metadata.yaml \
1420 | json-dict works - \
15 | mustache - templates/worklist.mustache \
21 | mustache - templates/list.mustache \
1622 | json-dict title $NAME contents - \
1723 | mustache - templates/main.mustache
55 import yaml
66
77 def coerce(arg):
8 if not arg: return None
89 if arg[0] == '@':
910 try:
1011 with open(arg[0]) as f: return coerce(f.read())
1415 except: pass
1516 try: return json.loads(arg)
1617 except: pass
17 try: return int(arg)
18 except: pass
19 try: return float(arg)
20 except: pass
21 if arg in ('true', 'True'): return True
22 if arg in ('false', 'False'): return False
23 if arg == 'null': return None
2418 return arg
2519
2620 if len(sys.argv[1:]) % 2 == 1:
1616 except: pass
1717 try: return json.loads(arg)
1818 except: pass
19 try: return int(arg)
20 except: pass
21 try: return float(arg)
22 except: pass
23 if arg in ('true', 'True'): return True
24 if arg in ('false', 'False'): return False
25 if arg == 'null': return None
2619 return arg
2720
2821 if sys.argv[1:] and (sys.argv[1] == '-c' or sys.argv[1] == '--cat-files'):
1 #!/bin/sh
1 #!/bin/sh -e
2
3 if [ "$#" -lt "2" ]; then
4 echo "Not enough arguments to $(basename $0)"
5 echo "Usage: $(basename $0) [data-dir] [link file]"
6 exit 1
7 fi
28
39 DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
410 PATH=$DIR:$PATH
1 #!/bin/sh
1 #!/bin/sh -e
2
3 if [ "$#" -lt "2" ]; then
4 echo "Not enough arguments to $(basename $0)"
5 echo "Usage: $(basename $0) [data-dir] [quip file]"
6 exit 1
7 fi
28
39 DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
410 PATH=$DIR:$PATH
11 #!/bin/sh -e
2
3 if [ "$#" -lt "2" ]; then
4 echo "Not enough arguments to $(basename $0)"
5 echo "Usage: $(basename $0) [data-dir] [quote file]"
6 exit 1
7 fi
28
39 DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
410 PATH=$DIR:$PATH
1 #!/bin/sh
1 #!/bin/sh -e
2
3 if [ "$#" -lt "2" ]; then
4 echo "Not enough arguments to $(basename $0)"
5 echo "Usage: $(basename $0) [data-dir] [work-dir]"
6 exit 1
7 fi
28
39 DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
410 PATH=$DIR:$PATH
1 {{! (pgnum, maxpg, works, show_cat, page='recent') }}
2 <div class="maintext">
3 {{#works}}
4 <div class="work">
5 <a href="/{{slug}}/">{{name}}</a>
6 {{#showcat}}
7 &mdash; <a href="/category/{{category}}/">{{category}}</a>
8 {{/showcat}}
9 </div>
10 {{/works}}
11 {{!
12 <div class="backforward">
13 $if pgnum > 0:
14 <span class="back">
15 <a href="/$page/?page=$(pgnum - 1)">previous</a>
16 </span>
17 $if pgnum < maxpg:
18 <span class="forward">
19 <a href="/$page/?page=$(pgnum + 1)">next</a>
20 </span>
21 </div>
22 }}
23 </div>
+0
-23
templates/worklist.mustache less more
1 {{! (pgnum, maxpg, works, show_cat, page='recent') }}
2 <div class="maintext">
3 {{#works}}
4 <div class="work">
5 <a href="/{{slug}}/">{{name}}</a>
6 {{#showcat}}
7 &mdash; <a href="/category/{{category}}/">{{category}}</a>
8 {{/showcat}}
9 </div>
10 {{/works}}
11 {{!
12 <div class="backforward">
13 $if pgnum > 0:
14 <span class="back">
15 <a href="/$page/?page=$(pgnum - 1)">previous</a>
16 </span>
17 $if pgnum < maxpg:
18 <span class="forward">
19 <a href="/$page/?page=$(pgnum + 1)">next</a>
20 </span>
21 </div>
22 }}
23 </div>