diff --git a/.github/workflows/docs_build_and_deploy.yml b/.github/workflows/docs_build_and_deploy.yml index 103980b..d440fc9 100644 --- a/.github/workflows/docs_build_and_deploy.yml +++ b/.github/workflows/docs_build_and_deploy.yml @@ -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'." diff --git a/docs/source/_static/switcher.json b/docs/source/_static/switcher.json index cad800f..2f9d2ea 100644 --- a/docs/source/_static/switcher.json +++ b/docs/source/_static/switcher.json @@ -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/" } ]