aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt-odlux/readthedocs/convert.sh
blob: 261c7ecc721b0d6b2e578afaa792def85998b7aa (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
#!/bin/bash

# Source definition
PATH_SOURCE_HELPSERVER="../helpserver/provider/src/main/resources/help"

# Destination
PATH_TARGET="./target"
PATH_DOC_USERDOC_DST="$PATH_TARGET/docs/guides/onap-user"

echo_sep() {
  echo "== $1 ====================================="
}

# Main

# Create PATH in dst
echo_sep "create target"
mkdir -p "$PATH_DOC_USERDOC_DST"

# Convert src MD -> dst RST
echo_sep "Converting md to rst files"
markdown_files=$(find "$PATH_SOURCE_HELPSERVER/sdnr" -type f -iname "*.md")

for file in ${markdown_files[@]}; do
  append_name=`echo "$file" | awk -F"/" '{print $(NF-1)}'`
  f="$(basename -- $file)"
  if [ "${f,,}" = "readme.md" ]; then
    rstfile="$append_name.rst"
  else
    rstfile="${f%.md}.rst"
  fi

  echo "$file to $PATH_DOC_USERDOC_DST/$rstfile"
  pandoc -s --toc -f markdown -t rst $file > "$PATH_DOC_USERDOC_DST/$rstfile"
done

# Copy PNG to dst
echo_sep "Copy PNG files from helpserver"
png_files=$(find "$PATH_SOURCE_HELPSERVER/sdnr" -type f -iname "*.png")
for file in ${png_files[@]}; do
  f="$(basename -- $file)"
  echo "$file to $f"
  cp $file "$PATH_DOC_USERDOC_DST/$f"
done

# Copy src to dst
echo_sep "Copy additional src files"
cp -r ./src/docs "$PATH_TARGET"

# Fix
echo_sep "Fix src"
# Fix abbreviations.rst
FN1="$PATH_DOC_USERDOC_DST/abbreviations.rst"
echo "Fix broken links: $FN1"
sed -i 's/ < / <h/' $FN1 
sed -i -E 's/\| http(.*) \|/\| ttp\1  \|/' $FN1
sed -i -E 's/\|  <http(.*) \|/\| <http\1  \|/' $FN1
# Fix end  

echo_sep "================Done=========================================="