@@ -20,29 +20,42 @@ git fetch origin '+refs/heads/docs/*:refs/remotes/origin/docs/*' || true
2020BRANCHES=$( git branch -r | grep ' origin/docs/' | sed ' s/^[[:space:]]*origin\///' || true)
2121
2222for branch in $BRANCHES ; do
23+ # Only treat docs/X.Y.Z branches as version snapshots.
24+ if ! [[ " $branch " =~ ^docs/[0-9]+\. [0-9]+\. [0-9]+$ ]]; then
25+ echo " Skipping non-version docs branch: $branch "
26+ continue
27+ fi
28+
2329 # Extract version number (e.g., docs/0.7.0 -> 0.7.0)
2430 VERSION=${branch# docs/ }
2531 echo " Processing version: $VERSION from branch: $branch "
26-
27- VERSIONS+=(" $VERSION " )
2832
2933 # Create the target directory for this version's docs
3034 TARGET_DIR=" versioned_docs/version-$VERSION "
3135 mkdir -p " $TARGET_DIR "
3236
3337 # Extract the 'docs/' folder from that specific branch
3438 # using git archive so we don't have to switch branches
35- (cd .. && git archive " $branch " docs/) | tar -x -C " $TARGET_DIR " || echo " Warning: Could not extract docs/ from $branch "
39+ if ! (cd .. && git archive " $branch " docs/) | tar -x -C " $TARGET_DIR " ; then
40+ echo " Warning: Could not extract docs/ from $branch . Skipping version $VERSION ."
41+ rm -rf " $TARGET_DIR "
42+ continue
43+ fi
44+
45+ # Extract the sidebars file for this version.
46+ # Docusaurus expects this in versioned_sidebars/version-{version}-sidebars.js
47+ if ! git show " $branch :docs-website/sidebars.js" > " versioned_sidebars/version-${VERSION} -sidebars.js" 2> /dev/null; then
48+ echo " Warning: Could not extract sidebars.js from $branch . Skipping version $VERSION ."
49+ rm -rf " $TARGET_DIR "
50+ rm -f " versioned_sidebars/version-${VERSION} -sidebars.js"
51+ continue
52+ fi
53+
54+ VERSIONS+=(" $VERSION " )
3655
3756 # Extract README.md and CONTRIBUTING.md if they are included in the docs config
3857 git show " $branch :README.md" > " $TARGET_DIR /README.md" || true
3958 git show " $branch :CONTRIBUTING.md" > " $TARGET_DIR /CONTRIBUTING.md" || true
40-
41- # Extract the sidebars file for this version
42- # Docusaurus expects this in versioned_sidebars/version-{version}-sidebars.js
43- if git show " $branch :docs-website/sidebars.js" > /dev/null 2>&1 ; then
44- git show " $branch :docs-website/sidebars.js" > " versioned_sidebars/version-${VERSION} -sidebars.js" || true
45- fi
4659done
4760
4861# Generate versions.json for Docusaurus to read
0 commit comments