A deploy_notes/build.sh => deploy_notes/build.sh +50 -0
@@ 0,0 1,50 @@
+#!/bin/sh -e
+
+if [[ "$1" == 'pdf' ]]; then
+ outdir="$HOME/docs/notes/deploy_notes/public_pdf"
+elif [[ "$1" == 'html' ]]; then
+ outdir="$HOME/docs/notes/deploy_notes/public_html"
+fi
+
+if [[ "$1" == 'pdf' ]]; then
+ mkdir -p $outdir/tmp
+ outfiles=()
+ for file in "${@:2}"; do
+ echo "Converting $file"
+ pandoc -f markdown+hard_line_breaks "$file" -o $outdir/tmp/$(basename $file | cut -f 1 -d '.').pdf
+ outfiles+=($(basename $file | cut -f 1 -d '.').pdf)
+ done
+ cd $outdir/tmp
+ echo "Uniting pdf"
+ pdfunite ${outfiles[*]} $outdir/notes.pdf
+ cd $outdir
+ rm -rf $outdir/tmp
+ echo DONE
+fi
+
+if [[ "$1" == 'html' ]]; then
+ mkdir -p "$outdir/tmp"
+ for file in "${@:2}"; do
+ echo "Converting $file"
+ file=$(echo $file | cut -c 3-)
+ path=$(dirname $file)
+ name=$(basename $file | cut -f 1 -d '.')
+ path_to_root=$(realpath --relative-to="$outdir/$path" "$outdir")
+ escaped_path_to_root=$(printf '%s\n' "$path_to_root" | sed -e 's/[\/&]/\\&/g')
+ cp $outdir/../../$file $outdir/tmp
+ grep -Po '\[.+\]\((?!https?:\/\/).*(?<!\.html|\.png|\.svg|\.jpg)\)' "$outdir/../../$file" | while read match; do
+ clean_match=$(echo $match | awk -F '(' ' {{print $2}} ' | cut -f 1 -d ')')
+ link=$clean_match.html
+ escaped_match=$(printf '%s\n' "$clean_match" | sed -e 's/[\/&]/\\&/g')
+ escaped_link=$(printf '%s\n' "$link" | sed -e 's/[\/&]/\\&/g')
+ sed -ie "s/$escaped_match/$escaped_link/" "$outdir/tmp/$name.md"
+ done
+ mkdir -p $outdir/$path
+ pandoc -s --template="$outdir/assets/template.html" -V home="$path_to_root/index.html" --css=$path_to_root/style.css --highlight-style breezedark -f markdown+hard_line_breaks --katex $outdir/tmp/"$name".md -o $outdir/$path/$name.html
+ sed -i "s/https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/KaTeX\/0.11.1\/katex.min.css/$escaped_path_to_root\/assets\/css\/katex.min.css/g" "$outdir/$path/$name.html"
+ sed -i "s/https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/KaTeX\/0.11.1\/katex.min.js/$escaped_path_to_root\/assets\/js\/katex.min.js/g" "$outdir/$path/$name.html"
+ cd ..
+ done
+ rm -rf $outdir/tmp
+ echo DONE
+fi
A deploy_notes/run => deploy_notes/run +9 -0
@@ 0,0 1,9 @@
+#!/bin/sh
+
+cd $HOME/docs/notes
+if [ "$1" == "html" ]; then
+ find . -name "*.md" -exec deploy_notes/build.sh html '{}' +;
+elif [ "$1" == "pdf" ]; then
+ find . -name "*.md" -exec deploy_notes/build.sh pdf '{}' +;
+fi
+rm -rf ~/docs/notes_html