-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate
executable file
·204 lines (165 loc) · 3.97 KB
/
generate
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
cwd=`pwd`
output="index.html"
index="<span class='logo'>Index</span>"
filter=*
verbose=false
copy=false
# Mostramos un disclaimer
function disclaimer {
printf "\e[1;31mMade with ❤ by ROJO 2 (http://rojo2.com)\e[0m"
}
# Show help
function show_help {
echo "Usage: ${0##*/} [-h] [-t TITLE] [-o OUTFILE] [-i PATH]
-p PATH use PATH instead of the current working directory
-o OUTFILE write result to OUTFILE instead of index.html
-t TITLE change TITLE on the navigation bar
-c copy template to input path
-h display this help and exit
-v verbose
"
disclaimer
exit 0
}
# Reset in case getopts have been used previously
OPTIND=1
while getopts "h?vco:p:t:" opt; do
case "$opt" in
h|\?)
show_help
;;
c)
copy=true
;;
v)
verbose=true
;;
o)
output=$OPTARG
;;
p)
cwd=$OPTARG
;;
t)
index=$OPTARG
;;
esac
done
out="$cwd/$output"
shift $((OPTIND-1))
function html_title {
echo "<h1>$1</h1>" >> $out
}
function html_open_list {
echo "<ul class='open-list invisible'>" >> $out
}
function html_open_foldable_list {
html_open_list
echo "<a href=\"#\" class='folder'><i class=\"fa fa-folder\"></i>${1##*/}</a>" >> $out
}
function html_close_list {
echo "</ul>" >> $out
}
function html_open_item {
echo "<li>" >> $out
}
function html_close_item {
echo "</li>" >> $out
}
function html_item_entry {
html_open_item
echo "<a href=\"$1\" target=\"payload\"><i class=\"fa fa-file\"></i>$2</a>" >> $out
html_close_item
}
# This function reads a template and outputs it
function html_template {
template=`cat template/$1.html`
echo "$template" >> $out
}
# This function generates the HTML header.
function html_header {
html_template "header"
}
# This function generates the HTML footer
function html_footer {
html_template "footer"
}
# This function generates the first html
# entry.
function html_first_entry {
local path=$1
local file
local basename
if $verbose; then
echo "Root: $path"
fi
html_title "$index"
html_open_list
for file in $path/$filter; do
basename="${file##*/}"
if [[ "$basename" = '*' ]]; then
continue
fi
if [[ -d $file ]]; then
if [[ $basename != "node_modules" ]] &&
[[ $basename != "bower_components" ]] &&
[[ $basename != "template" ]]; then
html_entry "$file"
else
if $verbose; then
echo "Ignoring: $basename"
fi
fi
else
if [[ $basename != "generate" ]] &&
[[ $basename != "index.html" ]]; then
html_item_entry "${file/$cwd\//}" "$basename"
fi
fi
done
html_close_list
}
# This function generates the html code for
# a path.
function html_entry {
local path=$1
local file
local basename
if $verbose; then
echo "Adding: $path"
fi
html_open_foldable_list $path
for file in $path/$filter; do
basename="${file##*/}"
if [[ "$basename" = '*' ]]; then
continue
fi
if [[ -d $file ]]; then
if [[ $basename != "node_modules" ]] &&
[[ $basename != "bower_components" ]]; then
html_open_item
html_entry "$file"
html_close_item
else
if $verbose; then
echo "Ignoring: $basename"
fi
fi
else
html_item_entry "${file/$cwd\//}" "$basename"
fi
done
html_close_list
}
# remove everythinug
echo "" > $out
# generate HTML
html_header
html_first_entry $cwd
html_footer
# copy the template to the destination
if $copy && [[ $cwd != `pwd` ]]; then
cp -R template/ $cwd
fi
disclaimer