-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sh
96 lines (82 loc) · 2 KB
/
script.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
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
#!/bin/bash
if [ -z "$var" ]
then
printf "Please provide SharePoint website name\n"
else
$sitename = $1
fi
function convert_file() {
# Convert file to html
pandoc -f dokuwiki -t html "$1" -o "$1"
}
function remove_newlines() {
# Remove newlines
outfile="${1/.txt/.html}"
tr -d '\n' < $1 >$outfile
}
function replace_hyphens() {
# Replace hyphens added by tr
sed -i 's/-//g' $outfile
}
function replace_urls() {
page_urls $1
image_urls $1
file_urls $1
}
function page_urls() {
sed -i "s/a href=\"\/\(.*\)\"/a href=\"\/sites\/$sitename\/Pages\/\1.aspx\"/g" $1
}
function image_urls() {
sed -i 's/img src=\"\/\(.*\)\"/img src=\"\/sites\/$sitename\/Documents\/media\/\1\"/g' $1
}
function file_urls() {
# Read more than one line input stream - as embed src usually over two lines...
sed -i '/./{H;$!d} ; x ; s/embed\nsrc=\"\/\(.*\)\/\([a-zA-Z0-9\s]*[.][a-zA-Z]*\)\".*>/a href=\"\/sites\/$sitename\/Documents\/\1\/\2\">\2<\/a>/g' $1
}
function escape_syntax() {
sed -i 's/[^\]\(\\[0-9]\)/\\\1/g' $1
}
function html_escape() {
# HTML escape
sed -i 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g' $outfile
}
function replace_in_template() {
sed -i 's/&/\\&/g; s/|/\\|/g' $outfile
txt=$(cat $outfile)
finalfile="${outfile/.html/.aspx}"
sed "s|REPLACEME|$txt|g" test/about.aspx > $finalfile
}
function caller_function() {
printf "Converting file %s " $1
printf "."
convert_file $1
printf "."
replace_urls $1
printf "."
escape_syntax $1
printf "."
remove_newlines $1
printf "."
replace_hyphens $outfile
printf "."
html_escape $outfile
printf "."
replace_in_template $outfile
printf "."
rm $1
printf "."
rm $outfile
printf " Finished \n"
}
export -f convert_file
export -f remove_newlines
export -f replace_hyphens
export -f replace_urls
export -f html_escape
export -f replace_in_template
export -f file_urls
export -f image_urls
export -f page_urls
export -f caller_function
export -f escape_syntax
find wiki/data/pages -type f -exec bash -c "caller_function \"{}\"" \;