From 103dd5c136323cfba2512c202d3a8941b66a6801 Mon Sep 17 00:00:00 2001 From: ZhgChgLiBot Date: Sun, 27 Oct 2024 21:15:25 +0800 Subject: [PATCH] update deploy.sh --- deploy.sh | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/deploy.sh b/deploy.sh index 420bc62..e705474 100755 --- a/deploy.sh +++ b/deploy.sh @@ -5,6 +5,11 @@ set -eu # Exit on error or unset variable PAGES_BRANCH="gh-pages" +SITE_DIR="_output" + +_backup_dir="$(mktemp -d)" + + init() { # Check if the script is running in a GitHub Actions environment if [[ -z ${GITHUB_ACTION+x} ]]; then @@ -14,6 +19,11 @@ init() { } build() { + # clean + if [[ -d $SITE_DIR ]]; then + rm -rf "$SITE_DIR" + fi + # Run the Ruby script to generate the output bundle exec ruby "./scaffold.rb" } @@ -26,20 +36,22 @@ setup_gh() { fi } +backup() { + mv "$SITE_DIR"/* "$_backup_dir" + mv .git "$_backup_dir" + + if [[ -f CNAME ]]; then + mv CNAME "$_backup_dir" + fi +} + flush() { - shopt -s dotglob nullglob + rm -rf ./* + rm -rf .[^.] .??* - for item in ./* .[^.]*; do - # skip ./_output and CNAME - if [[ "$item" != "./_output" && "$item" != "./.git" && "$item" != "./.github" && "$item" != "./CNAME" ]]; then - rm -rf "$item" - fi - done + shopt -s dotglob nullglob - shopt -u dotglob nullglob - - # Move all generated files to the root directory - mv ./_output/* ./ + mv "$_backup_dir"/* . } deploy() { @@ -57,11 +69,12 @@ deploy() { } main() { - init # Initialize and validate environment - build # Build the site - setup_gh # Set up the gh-pages branch + init + Build + setup_gh + backup flush - deploy # Deploy the site + deploy } # Execute the main function