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
|
#!/usr/bin/env bash
# Contents compilee
# ./contents_compile.sh <collection> <type>
# ./contents_compile.sh illich article
start=`date +%s%N`
cd `dirname $0`
COLLECTION=$1
TYPE=$2
cd ../../content/$COLLECTION/contents/$TYPE
AUTHOR=`cat ../../conf/local.php | grep author | cut -d "'" -f4`
COPYRIGHT=`cat ../../conf/local.php | grep copyright | cut -d "'" -f4`
SITE=`cat ../../conf/local.php | grep title | cut -d "'" -f4`
CODENAME=`cat ../../conf/local.php | grep codename | cut -d "'" -f4`
UNIVERSE=`cat ../../conf/local.php | grep universe | cut -d "'" -f4`
BASEURL=`cat ../../../../platform/www/conf/farm.ini | grep basedomain | cut -d '"' -f 2`
echo "#### STARTING TO COMPILE! Collection: $1 Type: $2. Press a key to proceed..."
read
# Clean previous files
rm index*
echo "" > index.txt
# Define languages to generate
LANGS=("en" "es")
for lng in ${LANGS[@]}; do
echo "Generating files for lang: $lng"
echo "" > index.$lng.txt
rm -rf ../../data/pages/$lng/$TYPE/*
cd ../../data/pages/$lng/$TYPE/
ln -s ../../../../contents/$TYPE/index.$lng.txt index.txt
cd $OLDPWD
done
echo "" > index.es.txt
for i in `ls -d */`; do
echo ""
echo ""
echo ""
echo "#### PROCESSING: $i"
FOLDER=$i
YEAR=`echo $i | cut -d '-' -f1`
cd $i
rm *.md *.pdf *.info
LANGORIG=`cat index | grep langorig | cut -d "@" -f 4 | cut -d "_" -f 3`
# echo $LANGORIG
TITLEORIG=`cat index | grep titleorig | cut -d "_" -f3`
# echo $TITLEORIG
# echo "************************"
# echo "LANGORIG: $LANGORIG"
# echo "TYPE: $TYPE"
# echo "i: $i"
# echo "************************"
# echo "************************"
# read
if [[ -f $LANGORIG.txt ]]
then
echo "The version in the original language is already processed"
for j in `ls *.txt`; do
LANG=`echo $j | cut -d '.' -f1`
echo "**** $LANG"
# Creates the $TYPE directory
if [[ ! -d ../../../data/pages/$LANG/$TYPE/$i ]]
then
echo "Create the $TYPE directory for $i in $LANG"
mkdir ../../../data/pages/$LANG/$TYPE/$i
fi
TAGS=()
TAGLIST=""
EXTRATAGS=""
# Creates the index file
echo "Regenerate the index for $i in $LANG"
INDEX="../../../data/pages/$LANG/$TYPE/$i/index.txt"
TITLE_MD=`head -n1 $LANG.txt`
TITLE=`echo $TITLE_MD | sed s/\#\ //`
head -n1 $LANG.txt > $INDEX
echo "" >> $INDEX
TITLELANG=`head -n1 $LANG.txt | sed s/\#\ //`
cat index >> $INDEX
if [[ -f LANG.notes ]]
then
cat $LANG.notes >> $INDEX
fi
if [[ $TYPE != "book" ]]
then
sed -i "s/\*YEAR\*/$YEAR/g" $INDEX
fi
if [ $(grep -c "LANG_authors" $INDEX) -eq 1 ]
# if grep "LANG_authors" $INDEX
then
sed -i "s/LANG_authors@#:\*\*/LANG_authors\@\#:\*\* $AUTHOR;/g" $INDEX
AUTHORS=`grep "LANG_authors" $INDEX | cut -d '*' -f6 | sed s/\;/\ and/g | sed s/^\ // | sed s/:\ //`
else
# only main author
AUTHORS=$AUTHOR
fi
if [ $(grep -c "LANG_publicationdate" $INDEX) -eq 1 ]
# if grep "LANG_publicationdate" $INDEX
then
PUBDATE=`grep "LANG_publicationdate" $INDEX | cut -d '*' -f6 | sed s/\;/\ and/g | sed s/^\ //`
else
# Use year if full date is not defined
PUBDATE=$YEAR
fi
if [[ $TYPE == "book" ]]
then
YEAR=$PUBDATE
fi
if grep "LANG_translators" $INDEX
then
TRANSLATORS=`grep "LANG_translators" $INDEX | cut -d '*' -f6 | sed s/\;/\ and/g | sed s/^\ // | sed s/:\ //`
else
# no translators
TRANSLATORS=""
fi
KEY=`echo $FOLDER | sed 's/\///'`
# http://illich.acerv.uz/en:$TYPE:1900-testing:index
URL="https://$CODENAME.$BASEURL/$LANG/$TYPE/$KEY:index"
URLDATE=`date +"%Y-%m-%d"`
echo "" >> $INDEX
echo "@ARTICLE{$UNIVERSE-$CODENAME-$KEY-$LANG,
author = {$AUTHORS},
title = {$TITLE},
year = {$YEAR},
date = {$PUBDATE},
origdate = {$PUBDATE},
language = {$LANG},
origlanguage = {$LANGORIG},
translator = {$TRANSLATORS},
url = {$URL},
urldate = {$URLDATE}
}" > $LANG.bib
echo "Generated $LANG.bib"
cat $LANG.bib >> ../index.$LANG.bib
echo "" >> ../index.$LANG.bib
echo "\`\`\`" >> $INDEX
cat $LANG.bib >> $INDEX
echo "\`\`\`" >> $INDEX
echo "~~NOTOC~~" >> $INDEX
echo "
* Authors: $AUTHORS
* Rights holder: $COPYRIGHT
* Original publication: $YEAR
* Original language: $LANGORIG
* Translator: $TRANSLATORS
-----
* URL: $URL
* Generated: $URLDATE
" > $LANG.md.info
LINES=`wc -l $LANG.txt`
if [[ $LINES > 2 ]]; then
# If the files contains more than one line, we consider the original $TYPE is complete and not pending
TAGS=("${TAGS[@]}" available)
else
TAGS=("${TAGS[@]}" pending)
fi
for j in "${TAGS[@]}"
do
if [ -z "$TAGLIST" ]
then
TAGLIST="$j"
else
TAGLIST="$TAGLIST $j"
fi
done
# Add tags in the tags file in the object folder
if [[ -f tags ]]
then
EXTRATAGS=`cat tags | awk '{print}' ORS=' '`
fi
echo "{{tag>$TAGLIST $EXTRATAGS}}" >> $INDEX
# Creates the link to the text in the specific language
cd ../../../data/pages/$LANG/$TYPE/$i
if [[ ! -f text.txt ]]
then
ln -s ../../../../../contents/$TYPE/$i$LANG.txt text.txt
fi
if [[ ! -f notes.txt ]]
then
ln -s ../../../../../contents/$TYPE/$i$LANG.notes notes.txt
fi
if [[ ! -f index.bib ]]
then
ln -s ../../../../../contents/$TYPE/$i$LANG.bib index.bib
fi
cd -
if [[ $TITLELANG == $TITLEORIG ]]
then
echo "* [[$LANG:$TYPE:$FOLDER:index|$YEAR - $TITLELANG]]" >> ../index.$LANG.txt
else
echo "* [[$LANG:$TYPE:$FOLDER:index|$YEAR - $TITLELANG]] (*$TITLEORIG*)" >> ../index.$LANG.txt
fi
done
#echo "* $YEAR - $TITLEORIG" >> ../index.txt
echo "* [[$LANGORIG:$TYPE:$FOLDER:index|$YEAR - $TITLEORIG]]" >> ../index.txt
# Creates the $TYPE directory
else
echo "La version en el idioma original NO esta procesada, entonces marcamos como pendiente y creamos un index"
echo "LANGORIG: $LANGORIG"
echo "TYPE: $TYPE"
echo "i: $i"
# read
if [[ ! -d ../../../data/pages/$LANGORIG/$TYPE/$i ]]
then
echo "Create the $TYPE directory for $i in $LANGORIG"
mkdir ../../../data/pages/$LANGORIG/$TYPE/$i
fi
# Creates the index file
echo "Creates the index file for $i in $LANGORIG"
INDEX="../../../data/pages/$LANGORIG/$TYPE/$i/index.txt"
echo $INDEX
# TITLEORIG=`cat index | grep titleorig | cut -d "_" -f3`
echo "# $TITLEORIG" > $INDEX
echo "" >> $INDEX
cat index >> $INDEX
cat $LANGORIG.notes >> $INDEX
echo "" >> $INDEX
echo "~~NOTOC~~" >> $INDEX
sed -i "s/\*YEAR\*/$YEAR/g" $INDEX
sed -i "s/LANG_authors@#:\*\*/LANG_authors\@\#:\*\* $AUTHOR;/g" $INDEX
TAGS=("${TAGS[@]}" available)
for j in "${TAGS[@]}"
do
if [ -z "$TAGLIST" ]
then
TAGLIST="$j"
else
TAGLIST="$TAGLIST $j"
fi
done
# Add tags in the tags file in the object folder
if [[ -f tags ]]
then
EXTRATAGS=`cat tags | awk '{print}' ORS=' '`
fi
echo "{{tag>$TAGLIST $EXTRATAGS}}" >> $INDEX
echo "* **[[$LANGORIG:$TYPE:$FOLDER:index|$YEAR - $TITLEORIG]]**" >> ../index.txt
fi
echo "*** I will generate the MD files"
../../../../../platform/bin/doku2md.sh $COLLECTION $TYPE $i
echo "*** I will generate the PDF files"
# read
cp *.md "../../../../../platform/bin/pandoc/$TYPE"
cp *.info "../../../../../platform/bin/pandoc/$TYPE"
../../../../../platform/bin/pandoc/$TYPE/run.sh
cp ../../../../../platform/bin/pandoc/$TYPE/*.pdf .
rm ../../../../../platform/bin/pandoc/$TYPE/*.pdf
rm ../../../../../platform/bin/pandoc/$TYPE/*.md
cd ..
echo ""
done
echo "Running decades... "
IFS=$'\n'
case $TYPE in
book)
for file in `ls index*.txt`; do
sort -n -t '|' -k2 -o $file $file
sed -i 's/$/\n/' $file
done
;;
*)
for file in `ls index*.txt`; do
mv $file $file.old
echo "***** $file"
for name in `cat $file.old`; do
YEAR=`echo $name | cut -d ':' -f 3 | cut -d '-' -f 1`
DECADE=${YEAR:0:3}
#echo "YEAR: $YEAR"
#echo "DECADE: $DECADE"
if [[ $DECADE_PRE != $DECADE ]]; then
echo "" >> $file
echo '### '$DECADE'0' >> $file
echo "" >> $file
fi
echo $name >> $file
DECADE_PRE=$DECADE
echo "" >> $file
done
done
rm *.old
;;
esac
end=`date +%s%N`
echo "Execution time was `expr $end - $start` nanoseconds."
|