-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathconvert.sh
43 lines (32 loc) · 889 Bytes
/
convert.sh
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
#!/bin/bash
set -euo pipefail
ARTICLES_DIR="./articles"
IPYNB_TEMPLATE="./articles/ipynb_template.tpl"
checkNbConvertApp() {
if ! command -v jupyter-nbconvert &>/dev/null; then
echo "Error: jupyter-nbconvert is not installed." >&2
return 1
fi
}
getNotebooksInDir() {
local dir=$ARTICLES_DIR
local -n articles_ref=$1
while IFS= read -r -d '' file; do
articles_ref+=("$file")
done < <(find "$dir" -type f -name "*.ipynb" -print0)
}
notebook2Markdown() {
local file=$1
jupyter-nbconvert --to markdown --template "$IPYNB_TEMPLATE" "$file"
}
main() {
checkNbConvertApp || exit 1
local notebooks=()
getNotebooksInDir notebooks
for notebook in "${notebooks[@]}"; do
echo "Converting $notebook to Markdown..."
notebook2Markdown "$notebook"
done
echo "Conversion has completed."
}
main "$@"