/
butterfly.bash
executable file
·55 lines (48 loc) · 1.49 KB
/
butterfly.bash
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
#!/bin/bash
# Usage instructions:
# 1. Place script in root site directory
# 2. Create a header.btf, body.btf, and footer.btf in each
# directory (including the root), these will be combined
# into your index.html
# 3. If header.btf or footer.btf is missing in a subdirectory
# then the parent directory's members will be used
## Update the parent directory
rm index.html 2>/dev/null
touch index.html
cat general-head.btf >> index.html
cat specific-head.btf >> index.html
cat content-header.btf >> index.html
cat body.btf >> index.html
cat footer.btf >> index.html
## Update the child directories
ls_output=($(ls))
for item in ${ls_output[*]}
do
# We only care about non-hidden directories and
# directories with a butterfly body file
if [[ -d $item && -e $item/body.btf ]]
then
cd $item # Enter
rm index.html 2>/dev/null
touch index.html
# Put in the general header
cat ../general-head.btf >> index.html
# Use a local headaer if there is one
if [[ -e specific-head.btf ]]
then
cat specific-head.btf >> index.html
fi
# Put in the content header
cat ../content-header.btf >> index.html
# Use the local body
cat body.btf >> index.html
# Use a local footer if there is one
if [[ -e footer.btf ]]
then
cat footer.btf >> index.html
else
cat ../footer.btf >> index.html
fi
cd .. # Exit
fi
done