-
Notifications
You must be signed in to change notification settings - Fork 18
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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"; | ||
|
@@ -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,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, | ||
}; | ||
} | ||
|
||
|
@@ -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/")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there ever a chance of |
||
return [existingPath.replace("/dev/", `/${currentVersion}/`)]; | ||
} else if (existingPath.includes("/prerelease/")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment re string matching |
||
return [ | ||
existingPath.replace( | ||
"/prerelease/", | ||
`/${mostRecentPreReleaseVersion.shortVersion}/` | ||
), | ||
]; | ||
} else if (existingPath.includes("/stable/")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment re string matching |
||
return [ | ||
existingPath.replace( | ||
"/stable/", | ||
`/${mostRecentStableVersion.shortVersion}/` | ||
), | ||
]; | ||
} | ||
return undefined; | ||
}, | ||
}, | ||
], | ||
], | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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