forked from tvheadend/tvheadend-documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.sh
executable file
·53 lines (44 loc) · 1.84 KB
/
convert.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
#! /bin/sh
echo "This utility will batch convert all md files to html for use in tvheadend"
echo
echo "All existing like-named html files in the target directory will be over-written"
echo "without further prompt"
if [ -z "$1" ] || [ -z "$2" ]; then
echo
echo "Insufficient number of arguments provided"
echo
echo "Usage: convert <sourcedir> <targetdir>"
exit
fi
echo
echo "** Using input directory" $1
echo "** Using output directory" $2
echo
read -p "Press [Enter] to contine, or [Ctrl-C] to abort..." null
for inputfile in $1/*.md
do
outputfile=$2/`basename $inputfile .md`.html
echo "Converting "$inputfile
# File header/disclaimer
echo "<!-- ***** WARNING! This file is auto-generated ***** -->" > $outputfile
echo >> $outputfile
echo "<!-- Do not edit it by hand if you want to keep your changes. -->" >> $outputfile
echo "<!-- All changes *must* be made in the source markdown and then carried-->" >> $outputfile
echo "<!-- through the pandoc conversion that creates these html files. -->" >> $outputfile
echo >> $outputfile
echo "<!-- Make changes on https://github.com/ProfYaffle/tvheadend-documentation -->" >> $outputfile
echo >> $outputfile
# Version and date
echo "<!-- File created on" `date` " -->" >> $outputfile
echo "<!-- Created with" `pandoc -v | head -1` " -->" >> $outputfile
echo >> $outputfile
# HTML - pandoc conversion inside tvheadend-specifc <div>
# Note the sed to change the path from what pandoc generates to what the
# tvh webserver expects: change "../icons/xyz.png" to "static/icons/xyz.png"
# Intentionally looking to match more string to keep it all sane
echo "<div class=\"hts-doc-text\">" >> $outputfile
pandoc $inputfile | sed 's/\(\<img class \= iconimg src=\"\)\.\.\(\/icons\/.*\.png\)/\1static\2/g' >> $outputfile
echo "</div>" >> $outputfile
echo "Saved as" $outputfile
echo
done