Diff of /docs/render_ipynb.bash [000000] .. [d45a3a]

Switch to unified view

a b/docs/render_ipynb.bash
1
#!/bin/bash
2
#
3
# Compile .md from .ipynb files for mkdocs
4
5
# Names of ipynb files to convert (from /notebooks) are specified in ipynb_pages.txt
6
set -e
7
8
function sed_replace {
9
  # https://stackoverflow.com/a/10467453/7529152
10
  # sed_replace <from> <to> <file>"
11
  sed -i "s/$(echo $1 | sed -e 's/\([[\/.*]\|\]\)/\\&/g')/$(echo $2 | sed -e 's/[\/&]/\\&/g')/g" $3
12
}
13
14
15
DIR=tutorials
16
for file in $(cat ipynb_pages.txt); do
17
18
    echo "converting: ${file}.ipynb"
19
    # .ipynb -> .md
20
    jupyter nbconvert --to markdown ../notebooks/${file}.ipynb --output-dir sources/${DIR}/
21
22
    file_out=sources/${DIR}/${file}.md
23
    dir_out=sources/${DIR}/${file}_files
24
25
    # fix the paths for the original images
26
    sed_replace '![img](../docs/theme_dir/img/' '![img](/bpnet/img/' $file_out
27
    # prepend the original ipython notebook link
28
    echo -e "Generated from [notebooks/${file}.ipynb](https://github.com/kundajelab/bpnet/blob/master/notebooks/${file}.ipynb)\n$(cat ${file_out})" > ${file_out}
29
30
    if [ -d "${dir_out}" ]; then
31
32
    # move the additional files <file>_files to theme_dir/img/ipynb/ (inline plots in ipynb)
33
    if [ -d "theme_dir/img/ipynb/${file}_files" ]; then
34
        rm -r theme_dir/img/ipynb/${file}_files
35
    fi
36
    mv -f ${dir_out} theme_dir/img/ipynb/
37
38
    # fix the path in the .md file
39
    sed_replace '![png]('${file}'_files' '![png](/bpnet/img/ipynb/'${file}'_files' $file_out
40
    sed_replace '![svg]('${file}'_files' '![svg](/bpnet/img/ipynb/'${file}'_files' $file_out
41
    fi
42
done
43
44
if [ -d "theme_dir/bpnet" ]; then
45
    rm -r theme_dir/bpnet
46
fi
47
mkdir -p theme_dir/bpnet
48
ln -sr theme_dir/img theme_dir/bpnet/img