-
Notifications
You must be signed in to change notification settings - Fork 16
/
gencontent.sh
executable file
·348 lines (287 loc) · 9.38 KB
/
gencontent.sh
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#!/bin/bash
# debug mode
#~ set -x
# gencontent.sh
# Generates the *.html files in the content/ directory on the
# plugins.geany.org website
#
# (C) Copyright 2010 by Dominic Hopf <[email protected]>
# Version: 1.2.0
# Last Change: 2013-04-15
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# ChangeLog:
# 2013-04-15 Volodymyr Kononenko <[email protected]>
# * the plugin listing (left side navigation bar) is now being generated
# from all plugins, available in master branch
# * if the plugin had different page in previous Geany versions, these
# pages are also being generated. Links to them are included in the
# bottom of plugin page
# * fixed checking exceptions in EXCLUDE_PLUGINS
#
# 2011-12-17 Dominic Hopf <[email protected]>
# * generate .html files from READMEs for the latest Geany-Plugins version
# instead of git master
#
# 2011-12-11 Dominic Hopf <[email protected]>
# * use the new Git repository
#
# 2010-01-21 Dominic Hopf <[email protected]>
# * remove unneccessary code which is trying to patch files but not working
# correctly
#
# 2010-01-21 Dominic Hopf <[email protected]>
# * add a sanity check, if the README file for a plugin exists
#
# 2010-01-09 Dominic Hopf <[email protected]>
# * write first version of this file with basic functionality
# ATTENTION: If you change any path below, don't forget the trailing slashes,
# they are very important and the script will not work correctly if they are
# missing!
# SOURCESDIR is the directory, where the README files will be found
SOURCESDIR=${HOME}"/.tmp/geany-plugins/"
WORKDIR=$(pwd)"/"
# CONTENTDIR is the directory, where the generated HTML files will be put
CONTENTDIR=${WORKDIR}"content/"
# LOGDIR is the directory where to put any logfiles and information about the
# generation of the content files
LOGDIR=${WORKDIR}"gencontent_logs/"
# plugins to exclude from the nightly re-generation via rst2html because they
# have a separate HTML page not generated from the README file
declare -a EXCLUDE_PLUGINS=( geanylua jsonprettifier quick_open_file togglebar pynav )
RST2HTML=$(which rst2html)
TIDY=$(which tidy)
# List of plugins, available in the letest release
declare -a RELEASE_PLUGIN_LIST
# List of plugins, available in the letest release
declare -a MASTER_PLUGIN_LIST
if [ ! -x "$RST2HTML" ]
then
echo "rst2html not found. Exiting."
exit 127
fi
if [ ! -x "$TIDY" ]
then
echo "tidy not found. Exiting."
exit 127
fi
in_array()
{
declare -a arr=("${!2}")
found=0
for i in "${arr[@]}"
do
if [ "${i}" == "$1" ]; then
found=1
fi
done
return ${found}
}
function prepare_source_dir()
{
if [ ! -d "${SOURCESDIR}" ]; then
echo -e "Directory containing sources $SOURCESDIR could not be found.\nTrying to clone from git...\n"
git clone https://github.com/geany/geany-plugins.git ${SOURCESDIR}
fi
if [ $? -ne 0 ]; then
echo "git clone failed. Exiting..."
exit 1
fi
}
function prepare_content_dir()
{
if [ ! -d "${CONTENTDIR}" ]; then
echo -e "Directory containing contents $CONTENTDIR could not be found!\n"
exit 1
fi
}
function prepare_log_dir()
{
mkdir -p ${LOGDIR}
}
function add_to_navigation()
{
dir=$1
title=$(echo ${dir} | sed 's/\([a-z]\)\([a-zA-Z0-9]*\)/\u\1\2/g')
echo "<li><a href=\"${dir}.html\">${title}</a></li>" >> "${CONTENTDIR}geany-plugins-listing.html"
}
function is_plugin()
{
f=$1
cd ${SOURCESDIR}
if [ -d "${f}" ] && [ "${f}x" != "buildx" ] && [ "${f}x" != "pox" ]; then
return 1
else
return 0
fi
}
# Generates geany-plugins-listing.html - the file which is included as navigation
function gen_plugins_listing_html()
{
cd ${SOURCESDIR}
echo "Checking out master branch..."
git checkout master
echo "Updating master branch..."
git pull
cd ${WORKDIR}
# reset old geany-plugins-listing.html
rm -f ${CONTENTDIR}"geany-plugins-listing.html"
for dir in $(ls ${SOURCESDIR})
do
is_plugin ${dir}
if [ $? -eq 1 ]; then
add_to_navigation ${dir}
MASTER_PLUGIN_LIST+=("${dir}")
fi
done
}
function gen_html_from_readme()
{
plugin="$1"
dir="$2"
LOGFILE="${LOGDIR}${plugin}_log_"$(date "+%Y-%m-%d")
cd ${CONTENTDIR}
# TODO: newer versions of rst2html may face problems with the configuration files encoding
$RST2HTML -s --config=${CONTENTDIR}"rst2html_config.conf" ${SOURCESDIR}${plugin}/README ${SOURCESDIR}.README.html 2> $LOGFILE
cd - > /dev/null
retcode=$?
if [ ${retcode} -ne 0 ]; then
echo -e "$RST2HTML exited with ${retcode}.\n\n"
fi
$TIDY -config ${WORKDIR}tidy.conf .README.html >> $LOGFILE 2>&1
case "$?" in
1)
echo -e "$TIDY exited with 1. There were warnings."
;;
2)
echo "$TIDY exited with 2. There were errors.\n\n"
;;
*)
echo -e "$TIDY exited with $?. Everything should be fine.\n"
;;
esac
echo -e "Result:\t${dir}${plugin}.html\nLog:\t${LOGFILE}\n"
echo -e "\n\n" >> $LOGFILE
# since tidy just outputs spaces, not tabs, we'll replace those spaces
# with tabs again ourself
sed -i "s/ /\t/g" .README.html
# remove hard-coded references to https://plugins.geany.org and make the links
# protocol-relative to not break SSL
sed -i "s,https://plugins.geany.org/,//plugins.geany.org/,g" .README.html
cp .README.html ${dir}${plugin}.html
echo -e "\n\n" >> ${LOGFILE}
}
function gen_plugin_pages()
{
cd $SOURCESDIR
for fname in $(ls ${SOURCESDIR})
do
is_plugin ${fname}
if [ $? -ne 1 ]; then
continue
fi
RELEASE_PLUGIN_LIST+=(${fname})
in_array ${fname} EXCLUDE_PLUGINS[@]
if [ $? -eq 1 ]; then
continue
fi
prevtag=""
for tag in $(git tag | tac)
do
git checkout -q ${tag}
if [ ${tag} == $(git tag | tail -n 1) ]; then
if [ -s ${SOURCESDIR}${fname}/README ]; then
gen_html_from_readme ${fname} ${CONTENTDIR}
else
echo -e "File ${SOURCESDIR}${fname}/README not found.\nYou might want to have a look whats up there.\nCopying no-readme-template instead."
cp ${WORKDIR}/templates/no-readme-template.html ${CONTENTDIR}${fname}.html
sed -i "s/{plugin_name}/${fname}/g" ${CONTENTDIR}${fname}.html
prevtag=${tag}
continue
fi
else
diff=$(git diff ${prevtag} -- ${fname}/README)
if [ -n "${diff}" ]; then
# diff output is not empty
mkdir -p ${CONTENTDIR}${tag}
gen_html_from_readme ${fname} ${CONTENTDIR}${tag}"/"
fi
fi
prevtag=${tag}
done
git checkout -q $(git tag | tail -n 1)
done
}
# The function generates pages for plugins, which are missing in release
# but are present in master branch
function gen_new_plugins_pages()
{
git checkout master
for plugin in ${MASTER_PLUGIN_LIST[@]}
do
in_array ${plugin} RELEASE_PLUGIN_LIST[@]
if [ $? -eq 0 ]; then
gen_html_from_readme ${plugin} ${CONTENTDIR}
fi
done
}
function add_links_to_old_pages()
{
declare -A header_added
for plugin in ${RELEASE_PLUGIN_LIST[@]}
do
header_added["${plugin}"]=0
done
for tag in $(ls ${CONTENTDIR})
do
if [ ! -d ${CONTENTDIR}${tag} ]; then
# this is not dir with old pages. Skip it
continue
fi
for plugin in $(ls ${CONTENTDIR}${tag} | awk -F'.' '{print $1}')
do
if [ ${header_added[${plugin}]} -eq 0 ]; then
# Adding header
echo -e "<div class=\"section\" id=\"docs-for-previous-versions\">\n<h3>\nDocs for previous versions\n</h3>\n<p>\n<ul>\n" >> ${CONTENTDIR}${plugin}.html
header_added["${plugin}"]=1
fi
echo -e "<li><a href=\"index.php?site=${tag}/${plugin}\">${tag}</a></li>\n" >> ${CONTENTDIR}${plugin}.html
done
done
# closing opened tags
for plugin in "${!header_added[@]}"
do
if [ ${header_added[${plugin}]} -eq 1 ]; then
echo -e "</ul>\n</p>\n</div>" >> ${CONTENTDIR}${plugin}.html
$TIDY -config ${WORKDIR}tidy.conf ${CONTENTDIR}${plugin}.html > /dev/null 2>&1
fi
done
}
# clean up any unneccessary files
function clean_up()
{
# delete logfiles older than 7 days
find $LOGDIR -mtime +7 -delete
}
function main()
{
prepare_source_dir
prepare_content_dir
prepare_log_dir
gen_plugins_listing_html
gen_plugin_pages
gen_new_plugins_pages
add_links_to_old_pages
clean_up
}
main