diff --git a/.gitignore b/.gitignore index 40b67f4..65e9a64 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ resources/ node_modules/ package-lock.json -.hugo_build.lock \ No newline at end of file +.hugo_build.lock +# Local Netlify folder +.netlify diff --git a/Makefile b/Makefile index 64c0d35..a7085e1 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,7 @@ .PHONY: serve serve: echo "Local development" - cd themes/docsy && git submodule update -f --init - cp content/en/docs/images/* static/images/ - sed -i -e 's/\(images\/[a-zA-Z\-]*\.svg\)/\/\1/g' content/en/docs/*.md + ./scripts/build-static.sh hugo server \ --baseURL $(URL) \ --buildDrafts \ @@ -14,14 +12,10 @@ serve: .PHONY: production-build production-build: - cd themes/docsy && git submodule update -f --init - cp content/en/docs/images/* static/images/ - sed -i -e 's/\(images\/[a-zA-Z\-]*\.svg\)/\/\1/g' content/en/docs/*.md + ./scripts/build-static.sh hugo --baseURL $(URL) .PHONY: preview-build preview-build: - cd themes/docsy && git submodule update -f --init - cp content/en/docs/images/* static/images/ - sed -i -e 's/\(images\/[a-zA-Z\-]*\.svg\)/\/\1/g' content/en/docs/*.md + ./scripts/build-static.sh hugo --baseURL $(DEPLOY_PRIME_URL) diff --git a/scripts/build-static.sh b/scripts/build-static.sh new file mode 100755 index 0000000..62b0bde --- /dev/null +++ b/scripts/build-static.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# +# Build static content from the spec repo +set -exo pipefail + +BASE_DIR="$( cd "$( dirname "$0" )/.." >/dev/null 2>&1 && pwd )" +STATIC_DIR="${BASE_DIR}/static" +DOCS_DIR="${BASE_DIR}/content/en/docs" + +# Serve static images +cp ${DOCS_DIR}/images/* ${STATIC_DIR}/images/ +sed -i -e 's/\(images\/[a-zA-Z\-]*\.svg\)/\/\1/g' ${DOCS_DIR}/*.md + +# Serve versioned schemas +cd ${DOCS_DIR} +ORIGINAL_REVISION=$(git rev-parse HEAD) +for tag in $(git tag); do + # Get the version by trimming the "v" + version=$(printf $tag | sed 's/^v//g') + TARGET_SCHEMA_FOLDER="${STATIC_DIR}/${version}/schema" + # Create the folder if it doesn't exists yet + mkdir -p ${TARGET_SCHEMA_FOLDER} || true + + git checkout "${tag}" + for schema in $(ls schemas/*json); do + # Extract the schema name from the schema id itself + TARGET_SCHEMA=$(awk -F'/' '/"\$id"/{ print $6 }' $schema | sed -e 's/",//g') + # Copy the file to static with the new name + cp ${schema} ${TARGET_SCHEMA_FOLDER}/${TARGET_SCHEMA} + done +done +git checkout ${ORIGINAL_REVISION} \ No newline at end of file