Skip to content

Commit 4f77d1f

Browse files
committed
Serve schema files through static
Add a script that prepares static content before the site build. The script handles static images (which used to be done directly in the makefile) and it also copies schema files to the right location in static for each version declared in the script. Fixes #11 Signed-off-by: Andrea Frittoli <[email protected]>
1 parent 528f7de commit 4f77d1f

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
resources/
33
node_modules/
44
package-lock.json
5-
.hugo_build.lock
5+
.hugo_build.lock
6+
# Local Netlify folder
7+
.netlify

Makefile

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
.PHONY: serve
22
serve:
33
echo "Local development"
4-
cd themes/docsy && git submodule update -f --init
5-
cp content/en/docs/images/* static/images/
6-
sed -i -e 's/\(images\/[a-zA-Z\-]*\.svg\)/\/\1/g' content/en/docs/*.md
4+
./scripts/build-static.sh
75
hugo server \
86
--baseURL $(URL) \
97
--buildDrafts \
@@ -14,14 +12,10 @@ serve:
1412

1513
.PHONY: production-build
1614
production-build:
17-
cd themes/docsy && git submodule update -f --init
18-
cp content/en/docs/images/* static/images/
19-
sed -i -e 's/\(images\/[a-zA-Z\-]*\.svg\)/\/\1/g' content/en/docs/*.md
15+
./scripts/build-static.sh
2016
hugo --baseURL $(URL)
2117

2218
.PHONY: preview-build
2319
preview-build:
24-
cd themes/docsy && git submodule update -f --init
25-
cp content/en/docs/images/* static/images/
26-
sed -i -e 's/\(images\/[a-zA-Z\-]*\.svg\)/\/\1/g' content/en/docs/*.md
20+
./scripts/build-static.sh
2721
hugo --baseURL $(DEPLOY_PRIME_URL)

scripts/build-static.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Build static content from the spec repo
4+
set -exo pipefail
5+
6+
BASE_DIR="$( cd "$( dirname "$0" )/.." >/dev/null 2>&1 && pwd )"
7+
STATIC_DIR="${BASE_DIR}/static"
8+
DOCS_DIR="${BASE_DIR}/content/en/docs"
9+
10+
# Serve static images
11+
cp ${DOCS_DIR}/images/* ${STATIC_DIR}/images/
12+
sed -i -e 's/\(images\/[a-zA-Z\-]*\.svg\)/\/\1/g' ${DOCS_DIR}/*.md
13+
14+
# Serve versioned schemas
15+
cd ${DOCS_DIR}
16+
ORIGINAL_REVISION=$(git rev-parse HEAD)
17+
for tag in $(git tag); do
18+
# Get the version by trimming the "v"
19+
version=$(printf $tag | sed 's/^v//g')
20+
TARGET_SCHEMA_FOLDER="${STATIC_DIR}/${version}/schema"
21+
# Create the folder if it doesn't exists yet
22+
mkdir -p ${TARGET_SCHEMA_FOLDER} || true
23+
24+
git checkout "${tag}"
25+
for schema in $(ls schemas/*json); do
26+
# Extract the schema name from the schema id itself
27+
TARGET_SCHEMA=$(awk -F'/' '/"\$id"/{ print $6 }' $schema | sed -e 's/",//g')
28+
# Copy the file to static with the new name
29+
cp ${schema} ${TARGET_SCHEMA_FOLDER}/${TARGET_SCHEMA}
30+
done
31+
done
32+
git checkout ${ORIGINAL_REVISION}

0 commit comments

Comments
 (0)