aboutsummaryrefslogtreecommitdiff
path: root/md/md2html.sh
blob: d45f38d25ba6d3abcc0ef25a157c448866cb2885 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/bash
# converts md to .tmpl.html with pandoc

readonly POSTS_DIR="../../html/posts"
readonly POST_TEMP="POST_TEMPLATE.tmpl.html"

post=$(basename "$1" .md) 
echo "converting $post to HTML"

# pandoc for md to html
pandoc -f markdown-auto_identifiers -t html --template=$POST_TEMP --wrap=none -o "$POSTS_DIR/$post.tmpl.html" "$post".md

# # adds in filename to path no longer needed
# sed -i "s/posts\//posts\/$post/" "$POSTS_DIR/$post.tmpl.html"

# makes http & https links have target _blank and rel noopener noreferrer
perl -i -0pe 's/(<\W*a\W*[^>]*href=)(["'"'"']http[s]?:\/\/[^"'"'"'>]*["'"'"'])([^>]*>)/$1$2 target="_blank" rel="noopener noreferrer"$3/g' "$POSTS_DIR/$post.tmpl.html"