-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish.sh
More file actions
33 lines (25 loc) · 813 Bytes
/
publish.sh
File metadata and controls
33 lines (25 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env sh
# add PUBLISH_FOLDER to your .gitignore
REMOTE="origin"
BRANCH="gh-pages"
PUBLISH_FOLDER="public"
if ! git diff-files --quiet --ignore-submodules --
then
echo "The working directory is dirty. Please commit any pending changes."
exit 1;
fi
echo "Switching to master branch"
git checkout master
echo "Preparing publish folder"
rm -rf ${PUBLISH_FOLDER} && mkdir ${PUBLISH_FOLDER}
git worktree prune
echo "Checking out ${BRANCH} branch into the publish folder"
git worktree add -B ${BRANCH} ${PUBLISH_FOLDER} --no-checkout
echo "Generating site"
hugo
echo "Updating ${BRANCH} branch"
cd ${PUBLISH_FOLDER} && git add --all && git commit -m "Updating gh-pages (publish.sh)" && cd ..
echo "Pushing to ${REMOTE}"
git push ${REMOTE} +${BRANCH}
echo "Cleaning up"
rm -rf ${PUBLISH_FOLDER}