Examples or scripts I use
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.4 KiB

#!/bin/sh
# Some code from https://codeberg.org/adam/website/src/branch/main/deploy.sh
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
build_directory="book"
build_branch="pages"
remote_origin_url=$(git config --get remote.origin.url) # get remote origin url, e.g. https://codeberg.org/user/repo.git
domain="your.domain.com"
if [ "$current_branch" = "master" ] || [ "$1" = "force" ]; then
# delete previous site built, if it exists
if [ -d "${build_directory}" ]; then
rm -rf "${build_directory}" || exit 1
fi
# generate mdbook static site to `build` directory
mdbook build || exit 1
# initialize a git repo in build_directory and checkout to build_branch
git -C "${build_directory}" init || echo "can't git init"
git -C "${build_directory}" checkout -b "${build_branch}" || echo "can't git checkout"
# add your domain
echo "${domain}" > "${build_directory}"/.domains
# stage all files
git -C "${build_directory}" add . || echo "can't git add"
# commit static site files and force push to build_branch of the origin
git -C "${build_directory}" commit -m "build: update static site" || echo "can't git commit"
git -C "${build_directory}" remote add origin "${remote_origin_url}" || echo "can't add origin"
git -C "${build_directory}" push --force origin "${build_branch}" || echo "can't git push"
fi
exit 0