Skip to content

Instantly share code, notes, and snippets.

@kevinrue
Created June 27, 2019 03:36
Show Gist options
  • Save kevinrue/d417a5bfc6a6ba214e00ef59db3474e9 to your computer and use it in GitHub Desktop.
Save kevinrue/d417a5bfc6a6ba214e00ef59db3474e9 to your computer and use it in GitHub Desktop.
Script to automatically build and deploy my Blogdown website
#!/bin/bash
original_path=$(pwd)
source_path="/Users/kevin/git/kevinrue.github.io-academic"
site_path="/Users/kevin/git/kevinrue.github.io"
echo_eval () {
echo "> $1"
eval "$1"
}
echo "Building $source_path"
# Compile blogdown from the source folder
cmd="cd $source_path"
echo_eval "$cmd"
cmd='Rscript -e "blogdown::build_site()"'
echo_eval "$cmd"
cmd="cd $site_path"
echo_eval "$cmd"
# Make sure the repo is up to date before 'editing' files
cmd="git pull"
echo_eval "$cmd"
# Remove previous files (excepted '.*' like '.git')
cmd="git rm -rf ./*"
echo_eval "$cmd"
# Place the new website files
cmd="cp -r $source_path/public/* $site_path/"
echo_eval "$cmd"
# Stage new files
cmd="git add ."
echo_eval "$cmd"
# Commit with message
cmd="git commit -m 'Update'"
echo_eval "$cmd"
# Push commit
cmd="git push origin master"
echo_eval "$cmd"
cd "$original_path"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment