Skip to content

Commit

Permalink
V1 of dynamic switcher.json
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorTatarnikov committed Nov 22, 2024
1 parent f43b2b1 commit a27113d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/docs_build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,34 @@ jobs:
rm -rvf ${version}
echo -e "\nCopying HTML files to ${version}:"
cp -Rvf ../docs/build ${version}/
if [[ "${version}" != "dev" ]]; then
# Updated switcher.json file
SWITCHER_FILE="${version}/_static/switcher.json"
SWITCHER_CONTENT=$(cat "${SWITCHER_FILE}")
BASE_URL="$(jq -r '.[1].url|split("/")[0:-2]|join("/")' $SWITCHER_FILE)"
NEW_URL="${BASE_URL}/${version}/"
# Extract the current latest version entry
CURRENT_LATEST_ENTRY=$(jq '.[1]' <<< "${SWITCHER_CONTENT}")
# Remove the "name" field from the current latest entry
UPDATED_CURRENT_LATEST_ENTRY=$(jq '.[1] | del(.name)' <<< "$SWITCHER_CONTENT")
# Create the new version entry with the "latest" tag
NEW_ENTRY=$(jq -n --arg version "${version}" --arg url "$NEW_URL" \
'{version: $version, url: $url, name: "v\($version) (latest)"}')
UPDATED_SWITCHER_CONTENT=$(jq --argjson new_entry "$NEW_ENTRY" \
--argjson updated_current_latest_entry "$UPDATED_CURRENT_LATEST_ENTRY" \
'.[1] = $updated_current_latest_entry | . += [$new_entry]' <<< "$SWITCHER_CONTENT")
# Write the updated content back to switcher.json
echo "$UPDATED_SWITCHER_CONTENT" > "$SWITCHER_FILE"
echo "switcher.json has been updated successfully."
fi
# If this is a new release, update the link from /latest to it
if [[ "${version}" != "dev" ]]; then
echo -e "\nSetup link from ${version} to 'latest'."
Expand Down
8 changes: 6 additions & 2 deletions docs/source/_static/switcher.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
[
{
"name": "v0.3.1 (stable)",
"version": "0.3.1",
"version": "dev",
"url": "https://neuroblueprint.neuroinformatics.dev/latest/"
},
{
"name": "v0.3.0 (stable)",
"version": "0.3.0",
"url": "https://neuroblueprint.neuroinformatics.dev/"
}
]

0 comments on commit a27113d

Please sign in to comment.