4
4
5
5
set -eo pipefail
6
6
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
10
9
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
[email protected]
19
12
20
13
deploy () {
21
14
if [[ ! -z " $GITHUB_REF_NAME " ]]; then
@@ -26,27 +19,25 @@ deploy() {
26
19
fi
27
20
echo " Current git branch is '${git_branch} '."
28
21
29
- git config user.name github-actions
30
- git config user.email
[email protected]
31
-
32
22
git checkout gh-pages
33
23
git pull origin gh-pages
34
24
35
25
if [ " $git_branch " == " $main_git_branch " ]; then
36
- site_dest=" ${gh_pages_root } "
26
+ site_dest=" ${gh_pages_dir } "
37
27
38
28
# Create temporary backup for other branches content.
39
- mv " ${gh_pages_root} /branches " .
29
+ mv " ${deployments_dir} " .
40
30
41
31
# Replace site files.
42
32
rm -rf " ${site_dest} "
43
33
mkdir -p " ${site_dest} "
44
34
cp -a -v ${site_src} /* ${site_dest} /
45
35
46
36
# Restore temporary backup for other branches content.
47
- mv ./branches " ${gh_pages_root } /"
37
+ mv ./branches " ${gh_pages_dir } /"
48
38
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} "
50
41
51
42
# Replace site files.
52
43
rm -rf " ${site_dest} "
@@ -86,10 +77,10 @@ update_deployments_list() {
86
77
main_deployment_url=" https://${github_repo_owner} .github.io/${github_repo_name} /"
87
78
echo " | [${main_git_branch} ](https://github.com/${github_repo_owner} /${github_repo_name} /tree/${branch} ) | [Open](${main_deployment_url} ) |" >> $deployments_list
88
79
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} " )
90
81
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 } "
93
84
echo " | [${branch} ](https://github.com/${github_repo_owner} /${github_repo_name} /tree/${branch} ) | [Open](${deployment_url} ) |" >> $deployments_list
94
85
done
95
86
0 commit comments