Skip to content

Commit 5f7997d

Browse files
committed
Documentation converter script.
JerryScript-DCO-1.0-Signed-off-by: István Kádár ikadar@inf.u-szeged.hu
1 parent 0898bf4 commit 5f7997d

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tools/update-webpage.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
3+
# Copyright 2015-2016 Samsung Electronics Co., Ltd.
4+
# Copyright 2016 University of Szeged
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
if [ $# -ne 1 ]; then
19+
echo "Please, specify your gh-pages clone directory: update-webpage <gh-pages clone dir>"
20+
exit 1
21+
fi
22+
23+
gh_pages_dir=$1
24+
docs_dir=`dirname $(readlink -f $0)`"/../docs"
25+
26+
GETTING_STARTED_MD="01.GETTING-STARTED.md"
27+
API_REFERENCE_MD="02.API-REFERENCE.md"
28+
API_EXAMPLES_MD="03.API-EXAMPLE.md"
29+
INTERNALS_MD="04.INTERNALS.md"
30+
31+
declare -A titles
32+
33+
titles[$GETTING_STARTED_MD]="Getting Started"
34+
titles[$API_REFERENCE_MD]="API Reference"
35+
titles[$API_EXAMPLES_MD]="API Examples"
36+
titles[$INTERNALS_MD]="Internals"
37+
38+
for docfile in $docs_dir/*.md; do
39+
docfile_base=`basename $docfile`
40+
41+
permalink=`echo $docfile_base | cut -d'.' -f 2 | tr '[:upper:]' '[:lower:]'`
42+
missing_title=`echo $permalink | tr '-' ' '`
43+
44+
# generate appropriate header for each *.md
45+
echo "---" > $gh_pages_dir/$docfile_base
46+
echo "layout: page" >> $gh_pages_dir/$docfile_base
47+
echo "title: ${titles[$docfile_base]:-$missing_title}" >> $gh_pages_dir/$docfile_base
48+
echo "permalink: /$permalink/" >> $gh_pages_dir/$docfile_base
49+
echo "---" >> $gh_pages_dir/$docfile_base
50+
echo >> $gh_pages_dir/$docfile_base
51+
echo "* toc" >> $gh_pages_dir/$docfile_base
52+
echo "{:toc}" >> $gh_pages_dir/$docfile_base
53+
echo >> $gh_pages_dir/$docfile_base
54+
55+
# the file itself removing underscores inside links
56+
gawk \
57+
'
58+
!/\[.*\]\(#/ {
59+
print $0
60+
}
61+
62+
/\[.*\]\(#/ {
63+
link_start_pos = index($0, "](#");
64+
line_beg = substr($0, 1, link_start_pos+2);
65+
line_remain = substr($0, link_start_pos+3);
66+
link_end_pos = index(line_remain, ")")
67+
link = substr(line_remain, 1, link_end_pos-1);
68+
line_end = substr(line_remain, link_end_pos)
69+
70+
# delete underscores form the link
71+
gsub(/_/, "", link);
72+
73+
printf "%s%s%s\n", line_beg, link, line_end
74+
}
75+
' $docfile >> $gh_pages_dir/$docfile_base
76+
77+
# fix image links
78+
sed -i -r -e 's/^!\[.*\]\(/&{{ site.baseurl }}\//' $gh_pages_dir/$docfile_base
79+
sed -i -r -e 's/^!\[.*\]\(\{\{ site\.baseurl \}\}\/img.*$/&{: class="thumbnail center-block img-responsive" }/' $gh_pages_dir/$docfile_base
80+
81+
# update images
82+
cp -Ru $docs_dir/img $gh_pages_dir
83+
done

0 commit comments

Comments
 (0)