Better error handling in shell scripts + more efficient impl of json-{list,dict}
Getty Ritter
9 years ago
69 | 69 |
mkdir -p `dirname $@`
|
70 | 70 |
bin/work.sh $(DATADIR) $< >$@
|
71 | 71 |
|
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
|
73 | 73 |
mkdir -p `dirname $@`
|
74 | 74 |
bin/category.sh $(DATADIR) $< >$@
|
75 | 75 |
|
76 | |
$(OUTDIR)/category/index.html: templates/worklist.mustache templates/main.mustache
|
| 76 |
$(OUTDIR)/category/index.html: templates/list.mustache templates/main.mustache
|
77 | 77 |
mkdir -p `dirname $@`
|
78 | 78 |
bin/all-categories.sh $(DATADIR) >$@
|
79 | 79 |
|
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
|
2 | 8 |
|
3 | 9 |
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
4 | 10 |
PATH=$DIR:$PATH
|
|
6 | 12 |
cat $1/works.json \
|
7 | 13 |
| jq '[.[] | { slug: ("category/" + .slug), name: .category }]' \
|
8 | 14 |
| json-dict works - \
|
9 | |
| mustache - templates/worklist.mustache \
|
| 15 |
| mustache - templates/list.mustache \
|
10 | 16 |
| json-dict title 'Permanent Collections' contents - \
|
11 | 17 |
| 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
|
2 | 8 |
|
3 | 9 |
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
4 | 10 |
PATH=$DIR:$PATH
|
|
6 | 12 |
SLUG=$(basename $2)
|
7 | 13 |
NAME=$(cat $1/works.json | jq ".[] | select(.slug == \"$SLUG\").category")
|
8 | 14 |
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
|
11 | 17 |
fi
|
12 | 18 |
|
13 | 19 |
json-list -c $2/*/metadata.yaml \
|
14 | 20 |
| json-dict works - \
|
15 | |
| mustache - templates/worklist.mustache \
|
| 21 |
| mustache - templates/list.mustache \
|
16 | 22 |
| json-dict title $NAME contents - \
|
17 | 23 |
| mustache - templates/main.mustache
|
5 | 5 |
import yaml
|
6 | 6 |
|
7 | 7 |
def coerce(arg):
|
| 8 |
if not arg: return None
|
8 | 9 |
if arg[0] == '@':
|
9 | 10 |
try:
|
10 | 11 |
with open(arg[0]) as f: return coerce(f.read())
|
|
14 | 15 |
except: pass
|
15 | 16 |
try: return json.loads(arg)
|
16 | 17 |
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
|
24 | 18 |
return arg
|
25 | 19 |
|
26 | 20 |
if len(sys.argv[1:]) % 2 == 1:
|
16 | 16 |
except: pass
|
17 | 17 |
try: return json.loads(arg)
|
18 | 18 |
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
|
26 | 19 |
return arg
|
27 | 20 |
|
28 | 21 |
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
|
2 | 8 |
|
3 | 9 |
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
4 | 10 |
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
|
2 | 8 |
|
3 | 9 |
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
4 | 10 |
PATH=$DIR:$PATH
|
1 | 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] [quote file]"
|
| 6 |
exit 1
|
| 7 |
fi
|
2 | 8 |
|
3 | 9 |
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
4 | 10 |
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
|
2 | 8 |
|
3 | 9 |
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
4 | 10 |
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 |
— <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>
|
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 | |
— <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>
|