diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5e108146..3ef094f9 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -52,8 +52,8 @@ jobs: - run: yarn install --frozen-lockfile - run: npm run build env: + NODE_ENV: "production" NODE_OPTIONS: --max-old-space-size=12288 - - name: Setup Pages uses: actions/configure-pages@v3 - name: Upload artifact diff --git a/README.md b/README.md index f79fa66c..740de2a4 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ PANTSBUILD_ORG_INCLUDE_VERSIONS=$version1,$version2 npm start To build the site, run: ```bash -NODE_OPTIONS="--max-old-space-size=12288" npm run build +NODE_ENV=production NODE_OPTIONS="--max-old-space-size=12288" npm run build ``` (Note: Node needs more than the default amount of RAM because this site is beefy) diff --git a/docusaurus.config.js b/docusaurus.config.js index 2dda7af7..3abf1f8e 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -1,5 +1,5 @@ import versions from "./versions.json"; -import redirects from "./old_site_redirects.js"; +import old_site_redirects from "./old_site_redirects.js"; import captionedCode from "./src/remark/captioned-code.js"; import tabBlocks from "docusaurus-remark-plugin-tab-blocks"; import fs from "fs"; @@ -29,6 +29,8 @@ const onlyIncludeVersions = isDev : ["current"] : undefined; +// In Docusaurus terms, "current" == main == trunk == dev. It is *newer* than +// the newest in versions.json function getCurrentVersion() { const lastReleasedVersion = versions[0]; const version = parseInt(lastReleasedVersion.replace("2.", ""), 10); @@ -71,6 +73,7 @@ const getVersionDetails = () => { const versionDetails = []; let seenStableVersions = 0; + let newestPreReleaseVersion = null; // Construct the configuration for each version. NB. iterating from newest to oldest is important, // to be able to label too-old stable versions as unsupported. @@ -81,6 +84,9 @@ const getVersionDetails = () => { const isMaintained = seenStableVersions < numberOfSupportedStableVersions; const isPrerelease = isPrereleaseVersion(fullVersion); const isCurrent = isCurrentVersion(shortVersion); + if (!isCurrent && isPrerelease && newestPreReleaseVersion === null) { + newestPreReleaseVersion = shortVersion; + } // compute the appropriate configuration this version let config; @@ -88,6 +94,7 @@ const getVersionDetails = () => { // current version => dev config = { label: `${shortVersion} (dev)`, + path: "dev", }; } else if (isPrerelease) { // prerelease => prerelease @@ -95,6 +102,8 @@ const getVersionDetails = () => { label: `${shortVersion} (prerelease)`, banner: "unreleased", noIndex: false, + path: + shortVersion == newestPreReleaseVersion ? "prerelease" : shortVersion, }; } else if (isMaintained) { // a new-enough stable version => so still supported @@ -102,6 +111,7 @@ const getVersionDetails = () => { label: shortVersion, banner: "none", noIndex: false, + path: seenStableVersions == 0 ? "stable" : shortVersion, }; } else { // stable, but too old => deprecated @@ -109,6 +119,7 @@ const getVersionDetails = () => { label: `${shortVersion} (deprecated)`, banner: "unmaintained", noIndex: true, + path: shortVersion, }; } @@ -118,22 +129,22 @@ const getVersionDetails = () => { isMaintained, isPrerelease, isCurrent, - config: { - ...config, - path: shortVersion, - }, + config, }); if (!isPrerelease) { seenStableVersions += 1; } } - return versionDetails; }; const versionDetails = getVersionDetails(); +const mostRecentPreReleaseVersion = versionDetails.find( + ({ isMaintained }) => !isMaintained +); + const mostRecentStableVersion = versionDetails.find( ({ isPrerelease }) => !isPrerelease ); @@ -434,7 +445,27 @@ const config = { [ "@docusaurus/plugin-client-redirects", { - redirects, + redirects: old_site_redirects, + createRedirects(existingPath) { + if (existingPath.includes("/dev/")) { + return [existingPath.replace("/dev/", `/${currentVersion}/`)]; + } else if (existingPath.includes("/prerelease/")) { + return [ + existingPath.replace( + "/prerelease/", + `/${mostRecentPreReleaseVersion.shortVersion}/` + ), + ]; + } else if (existingPath.includes("/stable/")) { + return [ + existingPath.replace( + "/stable/", + `/${mostRecentStableVersion.shortVersion}/` + ), + ]; + } + return undefined; + }, }, ], ],