-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmdweb
executable file
·84 lines (71 loc) · 1.66 KB
/
mdweb
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
#!/usr/bin/sh
###
#
# create a ./src directory inside your working directory
# containing head.html and foot.html inside it
#
###
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
printf "Usage: mdweb <src> <dst>\n\nsrc: html file\ndst: markdown file\n"
exit 0
fi
mdfile=$1
htmlfile=$2
if [ -z $mdfile ]; then
echo "mdweb: missing markdown source file"
exit 2
fi
if [ -z $htmlfile ]; then
echo "mdweb: missing html destination file"
exit 2
fi
# check if using markdown as source file
if echo $mdfile | grep -E -q ".+(\.md)$"; then
echo ">> src: \"$mdfile\""
else
echo "mdweb: $mdfile: wrong source file format"
exit 2
fi
# check if using html as destination file
if echo $htmlfile | grep -E -q ".+(\.html)$"; then
echo ">> dst: \"$htmlfile\""
else
echo "mdweb: $htmlfile: wrong destination file format"
exit 2
fi
# check if ./src dir exists including necessary files
if [ ! -d ./src ]; then
echo "mdweb: missing ./src directory"
exit 1
fi
if [ ! -f ./src/head.html ]; then
echo "mdweb: missing ./src/head.html"
exit 1
fi
if [ ! -f ./src/foot.html ]; then
echo "mdweb: missing ./src/foot.html"
exit 1
fi
# convert using pandoc
tmpfile=/tmp/$$_temp.html
if pandoc $mdfile -o $tmpfile; then
echo ">> converted \"$mdfile\" to \"$tmpfile\""
else
echo "mdweb: failed to convert $mdfile to $tmpfile"
exit 1
fi
# combine generated html file with head and foot
if cat ./src/head.html $tmpfile ./src/foot.html > $htmlfile; then
echo ">> generated $htmlfile"
else
echo "mdweb: failed to combie html files"
exit 1
fi
# cleanup
echo ">> cleaning up..."
if rm $tmpfile; then
echo ">> cleaned everything up. exiting..."
else
echo "mdweb: error cleaning up"
exit 1
fi