-
Notifications
You must be signed in to change notification settings - Fork 11
/
update_html
executable file
·75 lines (62 loc) · 2.44 KB
/
update_html
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
#!/usr/bin/env bash
#This is to update html (i) updating links (ii) include header and footer
title="A Journey in Signal Processing with Jupyter"
listOfFiles=$*
for f in $listOfFiles
do
filename=$(basename -- "$f")
dir=$(dirname "$f")
extension="${filename##*.}"
#filename="${filename%.*}"
#echo Updating $filename
if [ "$extension" == "html" ]
then
htmlFile=$dir/$filename
ipynbFile=$dir/${filename%.html}.ipynb
else
ipynbFile=$dir/$filename
htmlFile=$dir/${filename%.ipynb}.html
fi
htmlFilename=$(basename -- "$htmlFile")
ipynbFilename=$(basename -- "$ipynbFile")
before_after=$(python3 before_after.py $ipynbFile)
echo [Updating links]
perl -pi -e s/.ipynb/.html/g $htmlFile
rep="<div class=\"container\" id=\"notebook-container\">
<div class=\"cell border-box-sizing text_cell rendered\">
<div class=\"inner_cell\">
<div class=\"text_cell_render border-box-sizing rendered_html\">
<p> <em>
<a style=\" font-size: 100%; font-family: sans-serif; font-weight: bold\"
data-toggle=\"tooltip\" data-placement=\"top\"
title=\"Download notebook\"
href=\"$ipynbFilename\"> $ipynbFilename </a>
<span style=\"float:right\"> $title </span> </em> </p>
<a class=\"btn\" id=\"toc_button\" data-toggle=\"tooltip\" data-placement=\"top\"
title=\"Toggle table of Contents\" href=\"\#\">
<i class=\"fa fa-list\"></i> </a>
<span style=\"float:right\">
$before_after
</span>
</div>
</div>
</div>"
rep2="<div class=\"cell border-box-sizing text_cell rendered\">
<div class=\"inner_cell\">
<div class=\"text_cell_render border-box-sizing rendered_html\">
<div align=left>
<a style=\"color: blue; font-size: 100%; font-family: sans-serif; font-weight: bold\" href=\"$ipynbFilename\"> [Jupyter notebook]</a>
</div>
</div>
</div>
</div></body>"
origin="<div class=\"container\" id=\"notebook-container\">"
origin2="</body>"
echo [Linking to original notebook]
perl -pi -e "s#$origin#$rep#g" $htmlFile
perl -pi -e "s#$origin2#$rep2#g" $htmlFile
perl -pi -e s#"TeX-AMS_HTML\""#"TeX-AMS_HTML&delayStartupUntil=onload\""#g $htmlFile
perl -pi -e s#"\[Index\]\(([\S]*)\)"#"\<a href=\"\\1\"\>Index\<\/a\>"#g $htmlFile
perl -pi -e s#"\[Back\]\(([\S]*)\)"#"\<a href=\"\\1\"\>Back\<\/a\>"#g $htmlFile
perl -pi -e s#"\[Next\]\(([\S]*)\)"#"\<a href=\"\\1\"\>Next\<\/a\>"#g $htmlFile
done