Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use friendly "semi-stable" urls for key versions #256

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ jobs:
- run: yarn install --frozen-lockfile
- run: npm run build
env:
NODE_ENV: "production"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not doubting this, but what was the reason to add this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the various nested ?: operators happen to work either way right now, but being explicit about building everything for the public site.

https://github.com/pantsbuild/pantsbuild.org/blob/main/docusaurus.config.js#L20

NODE_OPTIONS: --max-old-space-size=12288

- name: Setup Pages
uses: actions/configure-pages@v3
- name: Upload artifact
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
45 changes: 38 additions & 7 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand All @@ -81,34 +84,42 @@ 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;
if (isCurrent) {
// current version => dev
config = {
label: `${shortVersion} (dev)`,
path: "dev",
};
} else if (isPrerelease) {
// prerelease => prerelease
config = {
label: `${shortVersion} (prerelease)`,
banner: "unreleased",
noIndex: false,
path:
shortVersion == newestPreReleaseVersion ? "prerelease" : shortVersion,
};
} else if (isMaintained) {
// a new-enough stable version => so still supported
config = {
label: shortVersion,
banner: "none",
noIndex: false,
path: seenStableVersions == 0 ? "stable" : shortVersion,
};
} else {
// stable, but too old => deprecated
config = {
label: `${shortVersion} (deprecated)`,
banner: "unmaintained",
noIndex: true,
path: shortVersion,
};
}

Expand All @@ -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
);
Expand Down Expand Up @@ -434,7 +445,27 @@ const config = {
[
"@docusaurus/plugin-client-redirects",
{
redirects,
redirects: old_site_redirects,
createRedirects(existingPath) {
if (existingPath.startsWith("/dev/")) {
return [existingPath.replace("/dev/", `/${currentVersion}/`)];
} else if (existingPath.startsWith("/prerelease/")) {
return [
existingPath.replace(
"/prerelease/",
`/${mostRecentPreReleaseVersion.shortVersion}/`
),
];
} else if (existingPath.startsWith("/stable/")) {
return [
existingPath.replace(
"/stable/",
`/${mostRecentStableVersion.shortVersion}/`
),
];
}
return undefined;
},
},
],
],
Expand Down
Loading