Skip to content

Commit 8e6415c

Browse files
committed
simplify nb2md script and verify new post
1 parent c3a009e commit 8e6415c

9 files changed

+1339
-50
lines changed

_posts/2024-05-28-time-series-varying-intercepts.md

Lines changed: 1271 additions & 0 deletions
Large diffs are not rendered by default.

_posts_drafts/nb2md_script.sh

Lines changed: 14 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,87 +15,51 @@
1515

1616

1717
# Create variables, using the notebook name from the argument of the call---------
18-
1918
NB=$1
2019
NB_base=$(echo ${NB} | sed s'|.ipynb||')
2120
NB_md="$NB_base.md"
2221

2322
echo ' '
24-
echo 'File base name: ' ${NB_base}
2523
echo 'Notebook: ' ${NB}
24+
echo 'File base name: ' ${NB_base}
2625
echo 'Markdown file: ' ${NB_md}
2726
echo ' '
2827

2928
# Convert to markdown format ------------------------------------------------------
30-
3129
jupyter nbconvert --to markdown ${NB}
3230

33-
3431
# Move the associated figures files, in the NB_files folder, to _assets--------------------
35-
3632
mv ${NB_base}_files/ ../assets/${NB_base}_files/
37-
3833
echo 'Moving associated figures ' ${NB_base}_files/ ../_assets/${NB_base}_files/
3934
echo ' '
4035

41-
# Edit path of .png files ----------------------------------
4236

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.
4439
# Better to edit first, create a new file in _posts folder, then delete in current folder
4540

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
4842
# OLD ![png](test_files/test_5_0.png)
4943
# NEW ![png](/assets/test_files/test_5_0.png)
5044

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"
6647
echo ' '
6748

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}
7151

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"
7454
echo ' '
7555

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>`
8157
echo 'Remove random Javascript object text'
82-
# sed '/<IPython.core.display.Javascript object>/d' ./${NB_md} > ./${NB_md}
8358
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}
9359
echo ' '
9460

9561
rm ${NB_md}
9662
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 " "
Loading

0 commit comments

Comments
 (0)