summaryrefslogtreecommitdiff
path: root/help3xsl/convert2html.sh
blob: 3cfe860d91dfb0c97167ac94def80b730d303e46 (plain)
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
#/bin/bash
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Convert localized XHP files and TREE files to HTML.
#
# Syntax: convert2html tarball productversion source
#
# Example
# ./convert2html.sh buildtargets_5403.tar.gz 5.4 libreoffice-help-5.4.0.3.tar.xz
#
# This script convert localized XHP and TREE files available as tarballs into
# a set of html pages.
#
# Conversion is done by listing the available languages in the tarball and
# executing the XSLT transformations on each XHP and tree files.
#
# Note: tarball, source and productversion must match.
#
# Special case for converting en-US XHP files to HTML. The en-US source is
# taken from the published helpcontent2 source tarball.
#
# companion files are moved to the right position in the html folder
# Media files are added too.
#

function getBookmark() {
###########################################
# Extract <bookmarks_value> from each XHP file and build a <ul> list
# in a javascript file
#
# Function called by main routine
#
# $1 is Language
# $2 is productversion
# $3 is the tarname folder
###########################################

local outdir=$(pwd)'/html/'$2'/'$1

local sourcedir=$3/HelpTranslatePartTarget/$1/helpcontent2/source
local ffile=$outdir/bookmarks.js
rm -f $ffile
local ffile2=$(mktemp)
local stub2=\'
local xslfile=get_bookmark.xsl

local param1=' --stringparam Language '$1' --stringparam productversion '$2

###########################################
# bookmarks for modules
###########################################
for i in CALC CHART WRITER DRAW IMPRESS MATH BASIC
do
local stub1='document.getElementById("bookmark'$i'").innerHTML='\'\\
sfind=$sourcedir'/'$(echo 'text/s'$i | tr '[:upper:]' '[:lower:]')
param=$param1' --stringparam app '$i
rm -f $ffile2
find $sfind -type f -name "*.xhp" -exec xsltproc $param $xslfile {} + >> $ffile2
echo $stub1 >> $ffile
sort -k3b -t\> -s -o $ffile2 $ffile2
awk 'NF' $ffile2 >> $ffile
echo $stub2 >> $ffile
done

###########################################
# Case of SHARED
###########################################
stub1='document.getElementById("bookmarkSHARED").innerHTML='\'\\
rm -f $ffile2
param=$param1' --stringparam app SHARED'
find $sourcedir'/text/shared' -type f -name "*.xhp" -exec xsltproc $param $xslfile {} + >> $ffile2
echo $stub1 >> $ffile
sort -k3b -t\> -s -o $ffile2 $ffile2
awk 'NF' $ffile2 >> $ffile
echo $stub2 >> $ffile

###########################################
# Case of Explorer (BASE)
###########################################
stub1='document.getElementById("bookmarkBASE").innerHTML='\'\\
rm -f $ffile2
param=$param1' --stringparam app BASE'
find $sourcedir'/text/shared/explorer/database' -type f -name "*.xhp" -exec xsltproc $param $xslfile {} + >> $ffile2
echo $stub1 >> $ffile
sort -k3b -t\> -s -o $ffile2 $ffile2
awk 'NF' $ffile2 >> $ffile
echo $stub2 >> $ffile
rm -f $ffile2
}

###########################################
# Main routine
###########################################

tarname=$1
productversion=$2
source=$3

sourceDir=$(pwd)

###########################################
# Un-tar localized XHP and TREE files
###########################################
#tarname=${tarball:0:17}
rm -rf $tarname
#tar -zxf $tarball
cp -r /var/tmp/$tarname .
###########################################
# Un-tar source en-US XHP and TREE files
###########################################

sourceName=$(tar -tf $source | head -1 | cut -f1 -d"/")
rm -rf $sourceName
tar -xf $source

###########################################
# Location of the merged l10n help files from sourceDir
###########################################
langDirSource=$tarname/HelpTranslatePartTarget/
enSource=$sourceName/helpcontent2

###########################################
#
# Hack: copy en-US from source help tarball to HelpTranslatePartTarget and HelpTreeTarget
#
###########################################
rm -rf $langDirSource/en-US
mkdir -p $langDirSource/en-US/helpcontent2
cp -r $enSource/* $langDirSource/en-US/helpcontent2

###########################################
#
# Process the en-US tree files
#
###########################################
ALL_TREE='sbasic  scalc  schart  shared  simpress  smath  swriter'
for i in $ALL_TREE
do
cp -r $sourceDir'/'$enSource'/source/auxiliary/'$i.tree $tarname/HelpTreeTarget/$i'/en-US.tree'
done
###########################################
#
# Location of the resulting html
#
###########################################
outDir=$sourceDir/html/$productversion/

filter=$sourceDir/online_transform.xsl

###########################################
#
# clean and recreate the target html folder
#
###########################################

rm -rf $sourceDir/html
mkdir -p $sourceDir/html/$productversion

###########################################
#
# Create the bookmark2file.js map.
#
# This file contains a map that convert bookmarks from LibreOffice apps into
# an URL of the corresponding page.
# The URL arriving is converted inside index.html and redirected
#
###########################################
stub1='var map={'
stub2='};'
sfind=$langDirSource'en-US/helpcontent2/source/text/'
ffile=$outDir/bookmark2file.js
ffile2=$(mktemp)
rm -f $ffile2 $ffile
find $sfind -type f -name "*.xhp" -exec xsltproc get_url.xsl {} + > $ffile2
echo $stub1 >> $ffile
awk 'NF' $ffile2 >> $ffile
echo $stub2 >> $ffile
rm -f $ffile2

for lang in $(ls $langDirSource)
#for lang in pt-BR fr
do
        echo 'Processing language '$lang
        mkdir -p  $outDir/$lang
        getBookmark $lang $productversion $tarname &

        pPath=$langDirSource$lang'/helpcontent2/source'
        xsltparm='--stringparam Language '$lang' --stringparam local no --stringparam productversion '$productversion' --stringparam root '$pPath'/'

        # iterate all xhp files

        for filep in $(find $pPath -name *.xhp)
        do
#         echo $filep
               DIR=${filep##*/source}
               name=${DIR:0:-3}
               outFile=$outDir$lang$name'html'
               xsltproc $xsltparm -o $outFile online_transform.xsl $filep
        done

###########################################
#
# Process tree files
#
###########################################

treeFileHTML=html/$productversion/$lang/contents.js

touch $treeFileHTML
echo 'document.getElementById("Contents").innerHTML='$'\047''\'>$treeFileHTML

xsltparm='--stringparam lang '$lang' --stringparam productversion '$productversion
for tree in $ALL_TREE
do
treeSourceFile=$tarname/HelpTreeTarget/$tree/$lang.tree
treeTemp2=$(mktemp)

xsltproc $xsltparm -o $treeTemp2 get_tree.xsl $treeSourceFile

awk 'NF' $treeTemp2>>$treeFileHTML

rm -f $treeTemp2
done

echo $'\047'';'>>$treeFileHTML
echo 'Conversion to HTML finished for '$lang
done
###########################################
# Process sitemap index for productversion
###########################################
url='https://help.libreoffice.org'

ALL_LANGS=$(ls $outDir | sed 's/media//')
ALL_LANGS=$(echo $ALL_LANGS | sed 's/bookmark2file.js//')
echo $ALL_LANGS
sitemap=$outDir/sitemap.xml

rm -f $sitemap
touch $sitemap

echo '<?xml version="1.0" encoding="UTF-8"?>' > $sitemap
echo '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'>>$sitemap

for lang1 in $ALL_LANGS
do
echo '<sitemap>' >>$sitemap
echo '<loc>'$url'/'$productversion'/sitemap-'$lang1'.xml</loc>' >>$sitemap
echo '<lastmod>'$(date -I)'</lastmod>'>>$sitemap
echo '</sitemap>'>>$sitemap

###########################################
#
# Process sitemap for productversion-lang
#
###########################################
f=$outDir'/sitemap-'$lang1'.xml'

rm -f $f
touch $f

echo '<?xml version="1.0" encoding="UTF-8"?>' > $f
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' >> $f


dd=./html/$productversion/$lang1

for ff in $(find $dd -name "*.html")
do
echo '<url><loc>'$url'/'${ff:7}'</loc></url>' >>$f
done
echo '</urlset>'>>$f

done
echo '</sitemapindex>'>>$sitemap

###########################################
#
# copy some service files
#
###########################################

#cp help.html index.html html/
cp normalize.css default.css help.js fuse.js paginathing.js $outDir
cp -r $enSource/source/media $outDir
mkdir -p $outDir/media/icon-themes
#cp -a ../../icon-themes/galaxy/* $outDir/media/icon-themes/
#ln -s $productversion html/latest

exit