Create wt-odlux directory
[ccsdk/features.git] / sdnr / wt-odlux / readthedocs / convert.sh
1 #!/bin/bash
2
3 # Source definition
4 PATH_SOURCE_HELPSERVER="../helpserver/provider/src/main/resources/help"
5
6 # Destination
7 PATH_TARGET="./target"
8 PATH_DOC_USERDOC_DST="$PATH_TARGET/docs/guides/onap-user"
9
10 echo_sep() {
11   echo "== $1 ====================================="
12 }
13
14 # Main
15
16 # Create PATH in dst
17 echo_sep "create target"
18 mkdir -p "$PATH_DOC_USERDOC_DST"
19
20 # Convert src MD -> dst RST
21 echo_sep "Converting md to rst files"
22 markdown_files=$(find "$PATH_SOURCE_HELPSERVER/sdnr" -type f -iname "*.md")
23
24 for file in ${markdown_files[@]}; do
25   append_name=`echo "$file" | awk -F"/" '{print $(NF-1)}'`
26   f="$(basename -- $file)"
27   if [ "${f,,}" = "readme.md" ]; then
28     rstfile="$append_name.rst"
29   else
30     rstfile="${f%.md}.rst"
31   fi
32
33   echo "$file to $PATH_DOC_USERDOC_DST/$rstfile"
34   pandoc -s --toc -f markdown -t rst $file > "$PATH_DOC_USERDOC_DST/$rstfile"
35 done
36
37 # Copy PNG to dst
38 echo_sep "Copy PNG files from helpserver"
39 png_files=$(find "$PATH_SOURCE_HELPSERVER/sdnr" -type f -iname "*.png")
40 for file in ${png_files[@]}; do
41   f="$(basename -- $file)"
42   echo "$file to $f"
43   cp $file "$PATH_DOC_USERDOC_DST/$f"
44 done
45
46 # Copy src to dst
47 echo_sep "Copy additional src files"
48 cp -r ./src/docs "$PATH_TARGET"
49
50 # Fix
51 echo_sep "Fix src"
52 # Fix abbreviations.rst
53 FN1="$PATH_DOC_USERDOC_DST/abbreviations.rst"
54 echo "Fix broken links: $FN1"
55 sed -i 's/ < / <h/' $FN1 
56 sed -i -E 's/\| http(.*) \|/\| ttp\1  \|/' $FN1
57 sed -i -E 's/\|  <http(.*) \|/\| <http\1  \|/' $FN1
58 # Fix end  
59
60 echo_sep "================Done=========================================="