Skip to content

Instantly share code, notes, and snippets.

@timoast
Created April 1, 2017 14:18
Show Gist options
  • Save timoast/c894ab9c9650c89e9d2a950e2848fecb to your computer and use it in GitHub Desktop.
Save timoast/c894ab9c9650c89e9d2a950e2848fecb to your computer and use it in GitHub Desktop.
#! /bin/sh
usage="$(basename "$0") -- build bookdown book
-h show help and exit
-a upload book to aws"
amazon=false # check options
while getopts "ah" opt; do
case $opt in
h) printf "$usage\n"
exit
;;
a) amazon=true
;;
esac
done
# get most recent Rmd file
RMDFILE="$(ls -Art *.Rmd | tail -n 1)"
BASENAME=(${RMDFILE//.Rmd/})
# generate/update the markdown
Rscript -e "bookdown::preview_chapter('${RMDFILE}')"
# copy the markdown file and associated files over to other dir
cp _book/${BASENAME}.md ~/Dropbox/notebook_render/${BASENAME}.Rmd
cp -r _bookdown_files/${BASENAME}_files ~/Dropbox/notebook_render/_bookdown_files
# build book
cd ~/Dropbox/notebook_render
Rscript -e "bookdown::render_book('index.Rmd')"
open -a "Safari" _book/index.html
# upload to aws
if [ $amazon == true ]; then
source ~/.virtualenvs/env/bin/activate
aws s3 sync _book/ s3://aws-website-[website name]
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment