-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·47 lines (41 loc) · 2.97 KB
/
build
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
#!/bin/sh
# Generating html version of markdown
PHTML=$(pandoc --standalone --toc --toc-depth=4 --metadata pagetitle="Faust Manual" --mathjax dsp-book.md)
# Detecting line of end of header added by pandoc
LINECUT=$(echo "$PHTML" | awk '/<ul>/{ print NR; exit }')
# Getting rid of pandoc header
PHTML=$(echo "$PHTML" | tail -n +$LINECUT | head -n -2)
# Adding elements for CSS, etc.
PHTML=$(echo "<div class=\"container-fluid\"><div class=\"row faust-doc\"><nav id=\"TOC\" class=\"col-3 faust-doc-content\"><div style=\"height: 100%;overflow-y: scroll;\"><ul class=\"nav flex-column\">$PHTML")
PHTML=$(echo "$PHTML" | awk '/<h1 id=\"chapter-1-introduction\">/{print "<main role=\"main\" class=\"col-9 ml-sm-auto px-4 faust-doc-content\">\n<div data-spy=\"scroll\" data-target=\"#TOC\" data-offset=\"0\" style=\"height: 100%;overflow-y: scroll;\">"}1' | awk '/<\/nav>/{print "</div>"}1')
# Extracting Faust files to be sent to the editor and generating correspind diags
EXFAUSTDIR="img/src/exfaust"
FAUSTCODES=$(echo "$PHTML" | awk '/<!-- faust-run -->/,/<!-- \/faust-run -->/')
CNT=0
while [ ! -z "$FAUSTCODES" ]
do
CURRENT_FAUST_FILE="$EXFAUSTDIR$CNT/exfaust$CNT.dsp"
# Removing existing dir, in case...
rm -rf $EXFAUSTDIR$CNT
# Creating dir for code and SVG
mkdir $EXFAUSTDIR$CNT
# Formating code from file
# TODO: files could be trimed to get rid of empty line at beginning and end
echo "$FAUSTCODES" | awk '1;/<!-- \/faust-run -->/{exit}' | awk '{gsub(/<!-- faust-run -->/,"")}1' | awk '{gsub(/<!-- \/faust-run -->/,"")}1' | awk '{gsub(/<pre><code>/,"")}1' | awk '{gsub(/<\/code><\/pre>/,"")}1' | awk '{gsub(/"/,"\"")}1' | awk '{gsub(/</,"<")}1' | awk '{gsub(/>/,">")}1' | awk '{gsub(/'/,"\x27")}1' > $CURRENT_FAUST_FILE
# Generating SVG
faust2svg $CURRENT_FAUST_FILE
# Cleaning current example
CODE_LENGTH=$(cat $CURRENT_FAUST_FILE | wc -l)
FAUSTCODES=$(echo "$FAUSTCODES" | tail -n +$((CODE_LENGTH+1)))
# Formating Faust runnable examples in html
FAUST_HEADER="<div class=\"faust-run\"><a href=\"$EXFAUSTDIR$CNT/exfaust$CNT-svg/process.svg\" target=\"_blank\"><img src=\"$EXFAUSTDIR$CNT/exfaust$CNT-svg/process.svg\" class=\"mx-auto d-block\"></a>"
PHTML=$(echo "$PHTML" | awk -v var="$FAUST_HEADER" '/<!-- faust-run -->/ && n==0 {sub(/<!-- faust-run -->/,var);++n}{print}')
FAUST_FOOTER="<a href=\"http://faust.grame.fr/editor?code=https://ccrma.stanford.edu/~rmichon/dsp-book/$CURRENT_FAUST_FILE\"><button type=\"button\" class=\"btn btn-primary\">Try it Yourself >></button></a></div>"
PHTML=$(echo "$PHTML" | awk -v var="$FAUST_FOOTER" '/<!-- \/faust-run -->/ && n==0 {sub(/<!-- \/faust-run -->/,var);++n}{print}')
# Going to next code...
((CNT++))
done
# Add the header and the footer of the future Faust website
#echo "$PHTML</div></div></div></main>" | cat lib/header-faust.html - lib/footer.html > index.html
# Add the header and the footer to make a standalone HTML page
echo "$PHTML</div></div></div></main>" | cat lib/header-doc.html - lib/footer.html > index.html