44
55set -eo pipefail
66
7- git_repo_root=$( git rev-parse --show-toplevel)
8- site_src=" ${git_repo_root} /_site"
9- gh_pages_root=" ${git_repo_root} /docs"
7+ script_dir=$( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd)
8+ source $script_dir /commons.sh
109
11- # Site built from the main branch will be available at 'https://<domain_name>/'.
12- # Sites built from other branchs will be available at 'https://<domain_name>/branches/<branch_name>'.
13- main_git_branch=" hakyll"
14-
15- # replace "/", "#", etc with "-".
16- slugify () {
17- echo " $1 " | iconv -c -t ascii//TRANSLIT | sed -E ' s/[~^]+/-/g' | sed -E ' s/[^a-zA-Z0-9]+/-/g' | sed -E ' s/^-+|-+$/-/g' | tr A-Z a-z
18- }
10+ git config user.name github-actions
11+ git config user.email github-actions@github.com
1912
2013deploy () {
2114 if [[ ! -z " $GITHUB_REF_NAME " ]]; then
@@ -26,27 +19,25 @@ deploy() {
2619 fi
2720 echo " Current git branch is '${git_branch} '."
2821
29- git config user.name github-actions
30- git config user.email github-actions@github.com
31-
3222 git checkout gh-pages
3323 git pull origin gh-pages
3424
3525 if [ " $git_branch " == " $main_git_branch " ]; then
36- site_dest=" ${gh_pages_root } "
26+ site_dest=" ${gh_pages_dir } "
3727
3828 # Create temporary backup for other branches content.
39- mv " ${gh_pages_root} /branches " .
29+ mv " ${deployments_dir} " .
4030
4131 # Replace site files.
4232 rm -rf " ${site_dest} "
4333 mkdir -p " ${site_dest} "
4434 cp -a -v ${site_src} /* ${site_dest} /
4535
4636 # Restore temporary backup for other branches content.
47- mv ./branches " ${gh_pages_root } /"
37+ mv ./branches " ${gh_pages_dir } /"
4838 else
49- site_dest=" ${gh_pages_root} /branches/$( slugify ${git_branch} ) "
39+ branch_slug=$( slugify $git_branch )
40+ site_dest=" ${gh_pages_dir} /branches/${branch_slug} "
5041
5142 # Replace site files.
5243 rm -rf " ${site_dest} "
@@ -86,10 +77,10 @@ update_deployments_list() {
8677 main_deployment_url=" https://${github_repo_owner} .github.io/${github_repo_name} /"
8778 echo " | [${main_git_branch} ](https://github.com/${github_repo_owner} /${github_repo_name} /tree/${branch} ) | [Open](${main_deployment_url} ) |" >> $deployments_list
8879
89- remote_branches=$( git ls-remote --heads origin | sed ' s?.*refs/heads/??' | grep -v " gh-pages" | grep -v " ${main_git_branch} " )
80+ remote_branches=$( git ls-remote --heads origin | sed ' s?.*refs/heads/??' | grep -v " gh-pages" | grep -v " ${main_git_branch} " )
9081 echo " $remote_branches " | while IFS= read -r branch; do
91- safe_branch =$( slugify $branch )
92- deployment_url=" https://${github_repo_owner} .github.io/${github_repo_name} /branches/${safe_branch } "
82+ branch_slug =$( slugify $branch )
83+ deployment_url=" https://${github_repo_owner} .github.io/${github_repo_name} /branches/${branch_slug } "
9384 echo " | [${branch} ](https://github.com/${github_repo_owner} /${github_repo_name} /tree/${branch} ) | [Open](${deployment_url} ) |" >> $deployments_list
9485 done
9586
0 commit comments