Skip to content

Commit

Permalink
Fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelWei committed Nov 18, 2024
1 parent 46131fb commit 2818c1e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
50 changes: 39 additions & 11 deletions docs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,38 @@ BRANCHES=(
3.x
4.x
)

LAST_VERSION=4.x

REMOTE="origin"

git fetch --all
git fetch --tags
current_branch=$(git rev-parse --abbrev-ref HEAD)
origin=$(git config --get remote.origin.url)
current_path=$(pwd)

rm -rf temp_versioned_docs
mkdir -p temp_versioned_docs
git clone "$origin" temp_versioned_docs

for tag in "${TAGS[@]}"; do

if [ "$tag" != "$current_branch" ]; then
git fetch "$REMOTE" "$tag"
fi
cd "$current_path"
cd temp_versioned_docs

git checkout "$tag"
if [ -f docusaurus.config.js ]; then
if [ -f docs/docusaurus.config.js ]; then
majorVersion=$(echo "$tag" | cut -d. -f1)
version=v${majorVersion}

echo "Adding documentation for $version"

cd "$current_path"

rm -rf docs sidebars.json
cp -r temp_versioned_docs/docs/docs .
cp -r temp_versioned_docs/docs/sidebars.js .

npm run docusaurus docs:version "${version}"
else
echo "Warning: branch/tag ${version} does not contain a docusaurus.config.js!"
Expand All @@ -38,23 +53,36 @@ for tag in "${TAGS[@]}"; do
done

for branch in "${BRANCHES[@]}"; do

if [ "$branch" != "$current_branch" ]; then
git fetch "$REMOTE" "$branch":"$branch"
fi
cd "$current_path"
cd temp_versioned_docs

git checkout "$branch"
if [ -f docusaurus.config.js ]; then
if [ -f docs/docusaurus.config.js ]; then
# Name version as the branch name
majorVersion=$(echo "$branch" | cut -d. -f1)
version=v${majorVersion}

echo "Adding documentation for $version"

cd "$current_path"

rm -rf docs sidebars.json
cp -r temp_versioned_docs/docs/docs .
cp -r temp_versioned_docs/docs/sidebars.js .

npm run docusaurus docs:version "${version}"
else
echo "Warning: branch ${branch} does not contain a docusaurus.config.js!"
fi

done
cd "$current_path"

# Cleanup
rm -rf temp_versioned_docs

# Return to the original branch
git reset --hard HEAD

git checkout "$current_branch"
# Edit docusaurus.config.js lastVersion to the last version
sed -i 's/lastVersion: "current"/lastVersion: "'"${LAST_VERSION}"'"/g' docusaurus.config.js
9 changes: 4 additions & 5 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ const config = {
({
docs: {
sidebarPath: "./sidebars.js",
//lastVersion: 'current',
lastVersion: "v4",
lastVersion: "current",
includeCurrentVersion: true,
versions: {
current: {
label: 'DEV',
banner: 'unreleased'
}
label: "DEV",
banner: "unreleased",
},
},
// Please change this to your repo.
// Remove this to remove the "edit this page" links.
Expand Down

0 comments on commit 2818c1e

Please sign in to comment.