docs: upgrade to docusaurus v3 (#26803)

This commit is contained in:
Erick Friis
2024-09-24 11:28:13 -07:00
committed by GitHub
parent b1da532522
commit f9ef688b3a
20 changed files with 11196 additions and 14430 deletions

View File

@@ -1,17 +0,0 @@
import React from "react";
export function ColumnContainer({children}) {
return (
<div style={{ display: "flex", flexWrap: "wrap" }}>
{children}
</div>
)
}
export function Column({children}) {
return (
<div style={{ flex: "1 0 300px", padding: "10px", overflowX: "scroll", zoom: '80%' }}>
{children}
</div>
)
}

View File

@@ -1,6 +1,6 @@
import React from 'react';
import Paginator from '@theme-original/DocItem/Paginator';
import Feedback from "../../Feedback";
import Feedback from "@theme/Feedback";
export default function PaginatorWrapper(props) {
return (

View File

@@ -1,201 +0,0 @@
// Swizzled class to show custom text for canary version.
// Should be removed in favor of the stock implementation.
import React from 'react';
import clsx from 'clsx';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import Link from '@docusaurus/Link';
import Translate from '@docusaurus/Translate';
import {
useActivePlugin,
useDocVersionSuggestions,
} from '@docusaurus/plugin-content-docs/client';
import {ThemeClassNames} from '@docusaurus/theme-common';
import {
useDocsPreferredVersion,
useDocsVersion,
} from '@docusaurus/theme-common/internal';
function UnreleasedVersionLabel({siteTitle, versionMetadata}) {
return (
<Translate
id="theme.docs.versions.unreleasedVersionLabel"
description="The label used to tell the user that he's browsing an unreleased doc version"
values={{
siteTitle,
versionLabel: <b>{versionMetadata.label}</b>,
}}>
{
'This is unreleased documentation for {siteTitle}\'s {versionLabel} version.'
}
</Translate>
);
}
function UnmaintainedVersionLabel({siteTitle, versionMetadata}) {
return (
<Translate
id="theme.docs.versions.unmaintainedVersionLabel"
description="The label used to tell the user that he's browsing an unmaintained doc version"
values={{
siteTitle,
versionLabel: <b>{versionMetadata.label}</b>,
}}>
{
'This is documentation for {siteTitle} {versionLabel}, which is no longer actively maintained.'
}
</Translate>
);
}
const BannerLabelComponents = {
unreleased: UnreleasedVersionLabel,
unmaintained: UnmaintainedVersionLabel,
};
function BannerLabel(props) {
const BannerLabelComponent =
BannerLabelComponents[props.versionMetadata.banner];
return <BannerLabelComponent {...props} />;
}
function LatestVersionSuggestionLabel({versionLabel, to, onClick}) {
return (
<Translate
id="theme.docs.versions.latestVersionSuggestionLabel"
description="The label used to tell the user to check the latest version"
values={{
versionLabel,
latestVersionLink: (
<b>
<Link to={to} onClick={onClick}>
<Translate
id="theme.docs.versions.latestVersionLinkLabel"
description="The label used for the latest version suggestion link label">
this version
</Translate>
</Link>
</b>
),
}}>
{
'For the current stable version, see {latestVersionLink} ({versionLabel}).'
}
</Translate>
);
}
function DocVersionBannerEnabled({className, versionMetadata}) {
const {
siteConfig: {title: siteTitle},
} = useDocusaurusContext();
const {pluginId} = useActivePlugin({failfast: true});
const getVersionMainDoc = (version) =>
version.docs.find((doc) => doc.id === version.mainDocId);
const {savePreferredVersionName} = useDocsPreferredVersion(pluginId);
const {latestDocSuggestion, latestVersionSuggestion} =
useDocVersionSuggestions(pluginId);
// Try to link to same doc in latest version (not always possible), falling
// back to main doc of latest version
const latestVersionSuggestedDoc =
latestDocSuggestion ?? getVersionMainDoc(latestVersionSuggestion);
return (
<div
className={clsx(
className,
ThemeClassNames.docs.docVersionBanner,
'alert alert--warning margin-bottom--md',
)}
role="alert">
<div>
<BannerLabel siteTitle={siteTitle} versionMetadata={versionMetadata} />
</div>
<div className="margin-top--md">
<LatestVersionSuggestionLabel
versionLabel={latestVersionSuggestion.label}
to={latestVersionSuggestedDoc.path}
onClick={() => savePreferredVersionName(latestVersionSuggestion.name)}
/>
</div>
</div>
);
}
function LatestDocVersionBanner({className, versionMetadata}) {
const {
siteConfig: {title: siteTitle},
} = useDocusaurusContext();
const {pluginId} = useActivePlugin({failfast: true});
const getVersionMainDoc = (version) =>
version.docs.find((doc) => doc.id === version.mainDocId);
const {savePreferredVersionName} = useDocsPreferredVersion(pluginId);
const {latestDocSuggestion, latestVersionSuggestion} =
useDocVersionSuggestions(pluginId);
// Try to link to same doc in latest version (not always possible), falling
// back to main doc of latest version
const latestVersionSuggestedDoc =
latestDocSuggestion ?? getVersionMainDoc(latestVersionSuggestion);
const canaryPath = `/docs/0.2.x/${latestVersionSuggestedDoc.path.slice("/docs/".length)}`;
return (
<div
className={clsx(
className,
ThemeClassNames.docs.docVersionBanner,
'alert alert--info margin-bottom--md',
)}
role="alert">
<div>
<Translate
id="theme.docs.versions.unmaintainedVersionLabel"
description="The label used to encourage the user to view the experimental 0.2.x version"
values={{
siteTitle,
versionLabel: <b>{versionMetadata.label}</b>,
}}>
{
'This is a stable version of documentation for {siteTitle}\'s version {versionLabel}.'
}
</Translate>
</div>
<div className="margin-top--md">
<Translate
id="theme.docs.versions.latestVersionSuggestionLabel"
description="The label used to tell the user to check the experimental version"
values={{
versionLabel: <b>{versionMetadata.label}</b>,
latestVersionLink: (
<b>
<Link to={canaryPath} onClick={() => savePreferredVersionName("0.2.x")}>
<Translate
id="theme.docs.versions.latestVersionLinkLabel"
description="The label used for the latest version suggestion link label">
this experimental version
</Translate>
</Link>
</b>
),
}}>
{
'You can also check out {latestVersionLink} for an updated experience.'
}
</Translate>
</div>
</div>
);
}
export default function DocVersionBanner({className}) {
const versionMetadata = useDocsVersion();
if (versionMetadata.banner) {
return (
<DocVersionBannerEnabled
className={className}
versionMetadata={versionMetadata}
/>
);
} else if (versionMetadata.isLast) {
// Uncomment when we are ready to direct people to new build
// return (
// <LatestDocVersionBanner
// className={className}
// versionMetadata={versionMetadata}
// />
// );
return null;
}
return null;
}

View File

@@ -2,7 +2,7 @@ import React from "react";
import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
import {
useDocById,
} from '@docusaurus/theme-common/internal';
} from '@docusaurus/plugin-content-docs/client';
const FEATURE_TABLES = {
chat: {

View File

@@ -1,8 +1,5 @@
import React from 'react';
import Translate, {translate} from '@docusaurus/Translate';
import {PageMetadata} from '@docusaurus/theme-common';
import Layout from '@theme/Layout';
import clsx from 'clsx';
import {useLocation} from 'react-router-dom';
function LegacyBadge() {
@@ -11,58 +8,48 @@ function LegacyBadge() {
);
}
export default function NotFound() {
export default function NotFoundContent({className}) {
const location = useLocation();
const pathname = location.pathname.endsWith('/') ? location.pathname : location.pathname + '/'; // Ensure the path matches the keys in suggestedLinks
const {canonical, alternative} = suggestedLinks[pathname] || {};
return (
<>
<PageMetadata
title={translate({
id: 'theme.NotFound.title',
message: 'Page Not Found',
})}
/>
<Layout>
<main className="container margin-vert--xl">
<div className="row">
<div className="col col--6 col--offset-3">
<h1 className="hero__title">
{canonical ? 'Page Moved' : alternative ? 'Page Removed' : 'Page Not Found'}
</h1>
{
canonical ? (
<h3>You can find the new location <a href={canonical}>here</a>.</h3>
) : alternative ? (
<p>The page you were looking for has been removed.</p>
) : (
<p>We could not find what you were looking for.</p>
)
}
{alternative && (
<p>
<details>
<summary>Alternative pages</summary>
<ul>
{alternative.map((alt, index) => (
<li key={index}>
<a href={alt}>{alt}</a>{alt.startsWith('/v0.1/') && <>{' '}<LegacyBadge/></>}
</li>
))}
</ul>
</details>
</p>
)}
<p>
Please contact the owner of the site that linked you to the
original URL and let them know their link {canonical ? 'has moved.' : alternative ? 'has been removed.' : 'is broken.'}
</p>
</div>
</div>
</main>
</Layout>
</>
<main className={clsx('container margin-vert--xl', className)}>
<div className="row">
<div className="col col--6 col--offset-3">
<h1 className="hero__title">
{canonical ? 'Page Moved' : alternative ? 'Page Removed' : 'Page Not Found'}
</h1>
{
canonical ? (
<h3>You can find the new location <a href={canonical}>here</a>.</h3>
) : alternative ? (
<p>The page you were looking for has been removed.</p>
) : (
<p>We could not find what you were looking for.</p>
)
}
{alternative && (
<p>
<details>
<summary>Alternative pages</summary>
<ul>
{alternative.map((alt, index) => (
<li key={index}>
<a href={alt}>{alt}</a>{alt.startsWith('/v0.1/') && <>{' '}<LegacyBadge/></>}
</li>
))}
</ul>
</details>
</p>
)}
<p>
Please contact the owner of the site that linked you to the
original URL and let them know their link {canonical ? 'has moved.' : alternative ? 'has been removed.' : 'is broken.'}
</p>
</div>
</div>
</main>
);
}