-
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
Add VersionedDocsLink and use for evergreen links to "latest" docs page #177
Merged
huonw
merged 6 commits into
pantsbuild:main
from
huonw:huonw/174-dynamic-versioned-link
Mar 12, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
699c3d6
Define VersionedDocsLink component
huonw 1fdd30a
Switch members.mdx over to new things (including switching to 'curren…
huonw 1f5e4c2
Use on front page "Learn more" link
huonw 694a872
REVERT ME: break a link
huonw f97a640
Revert "REVERT ME: break a link"
huonw 6c5c794
Fix "learn more" link for https://github.com/prettier/prettier/issues…
huonw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import Link from "@docusaurus/Link"; | ||
import useDocusaurusContext from "@docusaurus/useDocusaurusContext"; | ||
|
||
const docsPluginPath = "./src/js/docsPluginWithTopLevel404.js"; | ||
|
||
// extract the plugin configuration from docusaurus and use this to deduce the "version" references | ||
// for the link component | ||
const useVersionConfigs = () => { | ||
const { siteConfig } = useDocusaurusContext(); | ||
|
||
const [_, docsPluginConfig] = siteConfig.plugins.find( | ||
(pair) => pair[0] == docsPluginPath | ||
); | ||
if (!docsPluginConfig) { | ||
throw new Error( | ||
`failed to find docs plugin at ${docsPluginPath} in docusaurus.config.js; has something been renamed?` | ||
); | ||
} | ||
|
||
const current = docsPluginConfig.versions.current; | ||
return { | ||
"current-dev": current, | ||
// When running the dev server, we might be only showing the "current" docs (unless | ||
// PANTSBUILD_ORG_INCLUDE_VERSIONS is set), in which lastVersion may not be set, so we just | ||
// fallback to the current version to keep things working | ||
"last-stable": docsPluginConfig.lastVersion | ||
? docsPluginConfig.versions[docsPluginConfig.lastVersion] | ||
: current, | ||
}; | ||
}; | ||
|
||
/** | ||
* Link to a particular path within auto-generated docs & reference, "live" for the appropriate version. | ||
* | ||
* For instance, to link to /2.19/docs/introduction/welcome-to-pants | ||
* for whatever the current stable version is, use: | ||
* | ||
* <VersionedDocsLink version="latest-stable" unversionedPath="docs/introduction/welcome-to-pants">Welcome!</VersionedDocsLink> | ||
* | ||
* @param unversionedPath - the URL path without the leading /2.x/ version bit | ||
* @param version - the description of the version to link to: `current-dev` (Pants' main branch), `last-stable` (most recent stable) | ||
* @param linkProps - any other parameters to pass to @docusaurus/Link (including `children`) | ||
*/ | ||
export default function VersionedDocsLink({ | ||
unversionedPath, | ||
version, | ||
...linkProps | ||
}) { | ||
const versionConfigs = useVersionConfigs(); | ||
|
||
const versionConfig = versionConfigs[version]; | ||
if (!versionConfig) { | ||
const supported = Object.keys(versionConfigs).join(", "); | ||
throw new Error( | ||
`failed to find configuration for version="${version}" with unversionedPath="${unversionedPath}"; supported version values are: ${supported}` | ||
); | ||
} | ||
|
||
const to = `/${versionConfig.path}/${unversionedPath}`; | ||
return <Link to={to} {...linkProps} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
As noted in the PR description this is changing from the first entry of
versions.json
to the "current". This means switching from the most recentversioned_docs/...
entry (which corresponds to some2.*.x
branch in https://github.com/pantsbuild/pants) to the contents ofdocs/
(which corresponds tomain
).I think this is reasonable: people are generally contributing to the
main
branch, so the docs there are what's relevant.(For this particular one, arguably the "process" parts of the docs like https://www.pantsbuild.org/2.20/docs/contributions are "evergreen" pages and could be moved to this repo, while some pages like https://www.pantsbuild.org/2.20/docs/contributions/development/developing-rust are more strongly tied to a particular version and so aren't evergreen.)