commit 780baaa0e6badfa4dea4986391cc31b2c84a1d67 parent 0bc0f46627ce6a1045e30f709889dea055ff9573 Author: pyratebeard <root@pyratebeard.net> Date: Fri, 23 Sep 2022 21:38:48 +0100 preview script Diffstat:
M | scripts/preview | | | 41 | +++++++++++++++++++++++++++++++++++++++-- |
1 file changed, 39 insertions(+), 2 deletions(-)
diff --git a/scripts/preview b/scripts/preview @@ -1,3 +1,40 @@ -#!/bin/sh +#!/bin/bash -echo preview +# use arg as title and set post file path +TITLE=$1 +POST="entry/${TITLE}.md" + +# create a tmp dir +mkdir demo + +# copy post file, post_template and css +# to temp dir +cp ${POST} demo/index.md +cp post_template.html style.css demo/ + +# small change to post_template for stylesheet +sed -i 's%\.\./%%' demo/post_template.html + +# generate html file +pandoc -s \ + --template=demo/post_template.html \ + --metadata title="demolog" \ + -f markdown \ + -t html \ + -o demo/index.html \ + demo/index.md + +# start web server and capture pid for later +busybox httpd -f -h ./demo -p 8080 & +busypid=$! + +# open demo post file in browser +xdg-open http://localhost:8080 + +# wait until ready to stop web server +echo press any key to cancel +read -n 1 + +# kill the web server and remove temp dir +kill -9 ${busypid} +rm -rf demo/