diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 841f141485..0fd0d68187 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,19 +1,40 @@ -name: Deploy docs from master commit to gh pages +name: Deploy docs to gh-pages on: push: branches: - master + - v8_maintenance + - v9_maintenance + workflow_dispatch: jobs: deploy-docs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - run: npm ci && npm run bootstrap + # Conditional build depending on branch + - name: Set build directory based on branch + id: set-build-dir + run: | + if [ "${{ github.ref }}" == "refs/heads/master" ]; then + echo "::set-output name=build_dir::./packages/__docs__/__build__" + echo "::set-output name=deploy_dir::./" + elif [ "${{ github.ref }}" == "refs/heads/v8_maintenance" ]; then + echo "::set-output name=build_dir::./packages/__docs__/__build__" + echo "::set-output name=deploy_dir::v8" + elif [ "${{ github.ref }}" == "refs/heads/v9_maintenance" ]; then + echo "::set-output name=build_dir::./packages/__docs__/__build__" + echo "::set-output name=deploy_dir::v9" + fi - name: Build docs-app run: npm run build:docs - - uses: JamesIves/github-pages-deploy-action@v4 + - name: Copy redirects config file to the __build__ directory. + run: cp ./packages/__docs__/_redirects_gh_pages ./packages/__docs__/__build__ + - name: Deploy to GitHub Pages + uses: JamesIves/github-pages-deploy-action@v4 with: - folder: ./packages/__docs__/__build__ + folder: ${{ steps.set-build-dir.outputs.build_dir }} branch: gh-pages + target-folder: ${{ steps.set-build-dir.outputs.deploy_dir }} clean-exclude: pr-preview force: false diff --git a/packages/__docs__/_redirects_gh_pages b/packages/__docs__/_redirects_gh_pages new file mode 100644 index 0000000000..a8d6a0795b --- /dev/null +++ b/packages/__docs__/_redirects_gh_pages @@ -0,0 +1,4 @@ +/v6/* https://instructure.github.io/instructure-ui/v6:splat 200 +/v7/* https://instructure.github.io/instructure-ui/v7:splat 200 +/v8/* https://instructure.github.io/instructure-ui/v8:splat 200 +/v9/* https://instructure.github.io/instructure-ui/v9:splat 200 diff --git a/packages/__docs__/src/Header/index.tsx b/packages/__docs__/src/Header/index.tsx index 37413d55fe..e839fe34dc 100644 --- a/packages/__docs__/src/Header/index.tsx +++ b/packages/__docs__/src/Header/index.tsx @@ -69,9 +69,12 @@ class Header extends Component { // If we select the latest version from the dropdown, // then navigate to the index (instructure.design/#currentHash). // In every other case eg.: v6,v7 navigate to --> instructure.design/v6/#currentHash + const rootToAdd = window.location.origin.includes('github.io') + ? '/instructure-ui' + : '' const versionToNavigate = isSelectedLatestVersion - ? `/${window.location.hash}` - : `/${selectedVersion}/${window.location.hash}` + ? `${rootToAdd}/${window.location.hash}` + : `${rootToAdd}/${selectedVersion}/${window.location.hash}` return window.location.replace(versionToNavigate) } diff --git a/packages/__docs__/src/versionData.js b/packages/__docs__/src/versionData.js index cc0032aa4e..61d0029c97 100644 --- a/packages/__docs__/src/versionData.js +++ b/packages/__docs__/src/versionData.js @@ -36,12 +36,11 @@ const fetchVersionData = async (signal) => { const isLocalHost = window.location.hostname === 'localhost' if (!isLocalHost) { - const result = await fetch(`${window.location.origin}/versions.json`, { - signal - }) - const versionsData = await result.json() - - return versionsData + let input = window.location.hostname.includes('github.io') + ? `${window.location.origin}/instructure-ui/versions.json` + : `${window.location.origin}/versions.json` + const result = await fetch(input, { signal }) + return await result.json() } return null @@ -51,7 +50,9 @@ const fetchVersionData = async (signal) => { * if we are on the docs page of a legacy version, * the path includes the version number, e.g. `/v7` or `/v8` */ -const [versionInPath] = window.location.pathname.split('/').filter(Boolean) +const lastSegment = + window.location.pathname.split('/').filter(Boolean).pop() || '' +const versionInPath = /v\d$/.test(lastSegment) ? lastSegment : undefined export default fetchVersionData export { fetchVersionData, versionInPath }