-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
feat(v2): add a banner that links to latest version of documentation #2916
Conversation
Deploy preview for docusaurus-2 ready! Built with commit 12ef010 |
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.
Hi and thanks for your PR.
isOld
and link to /docs
is likely not reliable enough. It will work on basic D2 sites but will not work on sites that configure routeBasePath or have no homePageId
@@ -115,6 +117,11 @@ function DocItem(props) { | |||
<span className="badge badge--secondary"> | |||
Version: {version} | |||
</span> | |||
{isOld ? ( | |||
<span className="badge badge--secondary margin-horiz--xs"> | |||
<Link to="/docs"> Go to latest version </Link> |
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.
The /docs url is configurable, so it's not a good idea to hardcode the link to /docs here, + there's no guarantee that the user used the docs "homePageId" feature.
See https://v2.docusaurus.io/docs/docs-introduction/#docs-only-mode
@@ -145,6 +150,7 @@ export default async function processMetadata({ | |||
lastUpdatedBy, | |||
lastUpdatedAt, | |||
sidebar_label, | |||
isOld, |
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 we should rather try to compute, for each doc, what's the permalink to the latest version of the same doc.
maybe we need a property like latestPermalink
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.
some docs may get deleted in newer version of doc
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.
In such case latestPermalink would be undefined, and you wouldn't add the link?
Ah that's right, you want to link to the docs root, not necessarily the same doc in another version, so this is probably overkill.
Docs plugin: createDocsBaseMetadata(version) allows to pass data to the DocPage component, which is the layout component for a whole doc version. I think we should add data here with a permalink to the latest docs homepage (not necessarily But this is likely to conflict with my existing PR. You can make a POC, but can you wait before merging 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.
Honestly, this current solution does not bear any benefit. As I understand it, we need to clearly inform the docs user that they is looking at outdated information, and also encourage they to use the latest version.
The link in "breadcrumbs" is almost invisible (and especially in dark mode looks ugly, IMO).
I think we should add something like that alert:
This way we inform the user clearly enough:
- that they is viewing docs for an outdated version
- we "urge" they to switch to the latest version of docs, thus prompting they to upgrade their website to the newest version of Docusaurus
Source code of snippet
<div class="alert alert--danger margin-bottom--md" role="alert">
This is archived documentation for Docusaurus <strong>v2.0.0-alpha.50</strong>, which is no longer actively maintained.
<br><br>For up-to-date documentation, see the <a href="#">latest version</a>.
</div>
Summary of Changes
Considerations |
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.
That almost looks good to me, but the /docs
path does not always exist on all sites.
If there's no "docs home", maybe we should link to the first doc of the sidebar instead?
Subjective: I'd personally prefer a warning/orange than an error/red for the banner color.
const latestPermalink = | ||
version && version !== versioning.latestVersion | ||
? normalizeUrl([baseUrl, routeBasePath]) | ||
: 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.
This is almost what we want :)
on D2 website, we have a docs homePageId
, so the root is /docs
docs: {
homePageId: 'introduction',
path: 'docs',
But there are sites that do not have any docs home, it's the case for Watchman:
- https://facebook.github.io/watchman/docs => 404
- https://facebook.github.io/watchman/docs/install => this is the watchman home
For sites like Watchman without a doc at the root, we'd rather make sure that we don't link to a path that does not exist
Summary of changes:
|
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.
The algo should be more:
- if there's a home doc id, the link should target that home doc id
- else, link to the first document of the sidebar
@@ -461,6 +472,16 @@ Available document ids= | |||
Object.values(content.docsMetadata), | |||
'version', | |||
); | |||
const rootUrl = getHrefFromSideBar( | |||
content.docsSidebars[`version-${versioning.latestVersion}/docs`], | |||
); |
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.
Unfortunately the root url is not necessarily the first doc of the sidebar. If the user used a homeDocumentId, we must use it in priority, even if it's not the first doc in the sidebar (even if users usually use the first doc of the sidebar as home documentId).
Hey, I'd be fine if you fix the homeDocId problem to merge this PR. Note, in the future it's probably needed we'll actually need to link to the same doc of the latest version, with a fallback to homeDocId, then firstDoc (of latest version) This kind of behavior keeps being asked (yesterday here: #2923) I think we'd need to provide some algo like function getAllLinks(sidebarItems: DocsSidebarItem[]): SidebarItemLink[] {
return flatten(sidebarItems.map(item => {
if (sidebarItem.type === 'category') {
return getAllLinks(sidebarItem.items);
} else {
return [sidebarItem.href];
}
}));
}
function getLatestDocsPermalink(links: SidebarItemLink[],preferedPaths: string[]): string | undefined {
const existingPreferedPath = preferedPaths.find(preferedPath => {
return links.some(link => link.href === preferedPath);
})
if ( existingPreferedPath ) {
return existingPreferedPath;
}
else {
return links[0]?.href;
}
}
const docsLatestPermalink = getLatestDocsPermalink(latestSidebarData, [
currentDocPath,
homeDocIdPath
]); This is really pseudo code, maybe you'll find it useful |
Didn't try, but this could work fine: const latestHomeDoc = options.homePageId ? content.docsMetadata[options.homePageId] : undefined;
let latestDocPermalink: string
if ( latestHomeDoc ) {
latestDocPermalink = latestHomeDoc.permalink;
}
else {
latestDocPermalink = getHrefFromSideBar(
content.docsSidebars[`version-${versioning.latestVersion}/docs`],
);
} try to test with |
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.
That looks good to me
Just, what about renaming rootUrl/latestPermalink to something more explicit? like latestVersionMainDocPermalink
Also not fan of getHrefFromSideBar
what about getFirstDocLinkOfSidebar
?
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.
Actually, there's a case where this fails, if the homeDocId
selected does not exist in latest docs version.
As the "home" concept is currently not versioned, it is possible that the user selects a home that exists in next (ie /docs/next path will be created), but does not exist in current docs version (ie /docs will not be created)
Test with:
homePageId: 'doesNotExist',
I have a fix, I will push changes |
2fe191b
to
17c7e3a
Compare
LGTM, merging as #2905 is not reviewed yet |
Motivation
Add a badge that links older versions of documentation to the latest version of the documentation. This PR closes #2432.
Have you read the Contributing Guidelines on pull requests?
Yes.
Test Plan
After visiting the netlify preview site, go to any older version of the documentation . Check that there is a badge that links to the latest version
Click on the link to the latest version. There should be no badge next to the version number, since we are now at the latest version
The automated tests has been updated accordingly.