-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconvert_to_rst.sh
executable file
·66 lines (62 loc) · 3.06 KB
/
convert_to_rst.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
#!/bin/bash
# Project Clearwater - IMS in the Cloud
# Copyright (C) 2016 Metaswitch Networks Ltd
#
# 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, along with the "Special Exception" for use of
# the program along with SSL, set forth below. 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
# <http://www.gnu.org/licenses/>.
#
# The author can be reached by email at [email protected] or by
# post at Metaswitch Networks Ltd, 100 Church St, Enfield EN2 6BQ, UK
#
# Special Exception
# Metaswitch Networks Ltd grants you permission to copy, modify,
# propagate, and distribute a work formed by combining OpenSSL with The
# Software, or a work derivative of such a combination, even if such
# copying, modification, propagation, or distribution would otherwise
# violate the terms of the GPL. You must comply with the GPL in all
# respects for all of the code used other than OpenSSL.
# "OpenSSL" means OpenSSL toolkit software distributed by the OpenSSL
# Project and licensed under the OpenSSL Licenses, or a work based on such
# software and licensed under the OpenSSL Licenses.
# "OpenSSL Licenses" means the OpenSSL License and Original SSLeay License
# under which the OpenSSL Project distributes the OpenSSL toolkit software,
# as those licenses appear in the file LICENSE-OPENSSL.
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]; then
SED='sed -ri'
else
SED='sed -E -i.bak'
fi
rm -rf autogenerated_rst_docs/*.rst autogenerated_rst_docs/_static/* || true
for filename in docs/*.md
do
# Change docs/xyz.md to just xyz.md
filename_base=$(basename "$filename")
# Change xyz.md to just xyz
filename_without_suffix=${filename_base%.*}
target="autogenerated_rst_docs/${filename_without_suffix}.rst"
docker container run --rm --volume "$PWD":/data pandoc/core:2.8.0.1 \
--wrap=auto \
--columns=360 \
--from markdown_github+superscript \
--to rst "$filename" \
-o "$target"
# Change all the internal references to .md files so they refer to the generated .html files
# Use a restricted regex match so we don't accidentally convert external links like https://github.com/Metaswitch/sprout/blob/master/docs/Development.md to https://github.com/Metaswitch/sprout/blob/master/docs/Development.html
$SED "s/<([\.0-9a-zA-Z_]+)\.md/<\1.html/g" $target
rm "autogenerated_rst_docs/${filename_without_suffix}.rst.bak" 2>/dev/null || true
done
echo "Copying assets"
cp -a docs/img/* autogenerated_rst_docs/_static 2>/dev/null
cp -a docs/css autogenerated_rst_docs/_static 2>/dev/null
cp -a index.rst autogenerated_rst_docs/index.rst
cp -a sphinx.py autogenerated_rst_docs/conf.py