15
15
16
16
17
17
# Create variables, using the notebook name from the argument of the call---------
18
-
19
18
NB=$1
20
19
NB_base=$( echo ${NB} | sed s' |.ipynb||' )
21
20
NB_md=" $NB_base .md"
22
21
23
22
echo ' '
24
- echo ' File base name: ' ${NB_base}
25
23
echo ' Notebook: ' ${NB}
24
+ echo ' File base name: ' ${NB_base}
26
25
echo ' Markdown file: ' ${NB_md}
27
26
echo ' '
28
27
29
28
# Convert to markdown format ------------------------------------------------------
30
-
31
29
jupyter nbconvert --to markdown ${NB}
32
30
33
-
34
31
# Move the associated figures files, in the NB_files folder, to _assets--------------------
35
-
36
32
mv ${NB_base} _files/ ../assets/${NB_base} _files/
37
-
38
33
echo ' Moving associated figures ' ${NB_base} _files/ ../_assets/${NB_base} _files/
39
34
echo ' '
40
35
41
- # Edit path of .png files ----------------------------------
42
36
43
- # I can't move the file first and edit in place with sed
37
+ # Edit path of .png and .svg files ----------------------------------
38
+ # I can't edit the file paths in place with sed or over-write the markdown.
44
39
# Better to edit first, create a new file in _posts folder, then delete in current folder
45
40
46
- # Find all of the references to .png files in the newly moved markdown script and edit with new path---
47
-
41
+ # Find all of the references to .png and svg files in the newly moved markdown script and edit with new path
48
42
# OLD 
49
43
# NEW 
50
44
51
- echo ' Before renaming png files'
52
- cat ../_posts/${NB_md} | grep " \[png\](${NB_base} _files"
53
- echo ' '
54
-
55
- # sed command was a bit hard to write
56
- # need to use single and double quotes (using comma as separator in sed command
57
- sed ' s,' \\ [png\]\( " $NB_base " _files' ,' \\ [png\]\( /assets/" $NB_base " _files' ,g' ${NB_md} > ../_posts/${NB_md}
58
-
59
- echo ' After renaming png files'
60
- cat ../_posts/${NB_md} | grep " \[png\](${NB_base} _files"
61
- echo ' '
62
-
63
- # Edit path of .svg files ---------------------------------------
64
- echo ' Before renaming svg files'
65
- cat ../_posts/${NB_md} | grep " \[svg\](${NB_base} _files"
45
+ echo ' Before renaming png files, markdown in _post_drafts'
46
+ cat ${NB_md} | egrep " svg|png"
66
47
echo ' '
67
48
68
- # sed command was a bit hard to write
69
- # need to use single and double quotes (using comma as separator in sed command
70
- sed ' s,' \\ [svg\]\( " $NB_base " _files' ,' \\ [svg\]\( /assets/" $NB_base " _files' ,g' ${NB_md} > ../_posts/${NB_md}
49
+ # sed -E: Enables extended regular expressions
50
+ sed -E ' s/!\[(png|svg)\]\(([^)]+)\)/![\1]\(\/assets\/\2)/g' ${NB_md} > ../_posts/${NB_md}
71
51
72
- echo ' After renaming svg files'
73
- cat ../_posts/${NB_md} | grep " \[ svg\]( ${NB_base} _files "
52
+ echo ' After renaming png files, markdown in _post '
53
+ cat ../_posts/${NB_md} | egrep " svg|png "
74
54
echo ' '
75
55
76
-
77
- # Move the markdown file to _posts ----------------------------------
78
- echo ' Moved markdown file ' ${NB_md} ../_posts/${NB_md}
79
-
80
- # Remove the lines that say `<IPython.core.display.Javascript object>` (not working)
56
+ # Remove the lines that say `<IPython.core.display.Javascript object>`
81
57
echo ' Remove random Javascript object text'
82
- # sed '/<IPython.core.display.Javascript object>/d' ./${NB_md} > ./${NB_md}
83
58
sed -i ' ' ' /\<IPython.core.display.Javascript object\>/d' ../_posts/${NB_md}
84
- # sed -i '' '/\<IPython.core.display.Javascript object\>/d' ${NB_md}
85
- echo ' '
86
-
87
-
88
- # Cut out the first line
89
- echo ' Cut out the first line'
90
- # Need to assign to a diff file first. Redirection (>) happens before tail is invoked by the shell.
91
- # https://stackoverflow.com/questions/339483/how-can-i-remove-the-first-line-of-a-text-file-using-bash-sed-script
92
- tail -n +2 ../_posts/${NB_md} > ../_posts/${NB_md} .tmp && mv ../_posts/${NB_md} .tmp ../_posts/${NB_md}
93
59
echo ' '
94
60
95
61
rm ${NB_md}
96
62
echo ' Removed markdown file in _posts_drafts folder '
97
- echo ' '
98
-
99
- echo " Markdown produced and updated."
100
- echo " cd to parent folder and make sure first line of markdown file is not blank (starts with --- indicating start of YAML)"
101
- echo " Run bundle exec jekyll serve to test page build locally."
63
+ echo " Updated markdown produced in _posts folder."
64
+ echo " cd to parent folder and run bundle exec jekyll serve to test page build locally."
65
+ echo " "
0 commit comments