diff --git a/netlify.toml b/netlify.toml index 4b9bb164..5b17e189 100644 --- a/netlify.toml +++ b/netlify.toml @@ -15,8 +15,16 @@ HUGO_VERSION = "0.79.0" LOOP = "false" HOST = "/" - +[context.branch-deploy] + command = "./scripts/branchdeploy.sh $DEPLOY_PRIME_URL" [context.branch-deploy.environment] HUGO_VERSION = "0.79.0" LOOP = "false" - HOST = "/" \ No newline at end of file + HOST = "/" +[[plugins]] + package = "@algolia/netlify-plugin-crawler" + [plugins.inputs] + branches = ['main','release/*'] + disabled = false + renderJavaScript = false + template = "hierarchical" diff --git a/scripts/branchdeploy.sh b/scripts/branchdeploy.sh new file mode 100644 index 00000000..62bc3b6e --- /dev/null +++ b/scripts/branchdeploy.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +set -e +# Important for clean builds on Netlify +if ! git remote | grep -q origin ; then + git remote add origin https://github.com/dgraph-io/dgraph-docs.git + git fetch --all +fi + +GREEN='\033[32;1m' +RESET='\033[0m' + +# script used to build a release branch +# expect the branch to be named release/ +# argument is the netlify base url + +releaseVersion=$(git rev-parse --abbrev-ref HEAD | sed 's/release\///') + + +run() { + export DGRAPH_ENDPOINT=${DGRAPH_ENDPOINT:-"https://play.dgraph.io/query?latency=true"} + export HUGO_TITLE="Dgraph Doc - Preview" \ + + pushd "$(dirname "$0")/.." > /dev/null + pushd themes > /dev/null + + if [ ! -d "hugo-docs" ]; then + echo -e "$(date) $GREEN Hugo-docs repository not found. Cloning the repo. $RESET" + git clone https://github.com/dgraph-io/hugo-docs.git + else + echo -e "$(date) $GREEN Hugo-docs repository found. Pulling the latest version from master. $RESET" + pushd hugo-docs > /dev/null + git checkout master + git pull + popd > /dev/null + fi + popd > /dev/null + + echo -e "$(date) $GREEN Generating documentation static pages in the public folder. $RESET" + hugo --destination="public/docs/$releaseVersion" --baseURL="$1/docs/$releaseVersion" 1> /dev/null + cp "public/docs/$releaseVersion/sitemap.xml" public > /dev/null + echo -e "$(date) $GREEN Done building. $RESET" + + popd > /dev/null +} + +run "$1"