fix(plugin-docs,theme): refactor docs plugin routes and component tree (#7966)

This commit is contained in:
Sébastien Lorber 2022-08-18 17:55:05 +02:00 committed by GitHub
parent c29218ea1d
commit 3b9b497d13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 1189 additions and 857 deletions

View file

@ -73,7 +73,7 @@ export {
useDocsVersionCandidates,
useLayoutDoc,
useLayoutDocsSidebar,
useDocRouteMetadata,
useDocRootMetadata,
} from './utils/docsUtils';
export {useTitleFormatter} from './utils/generalUtils';

View file

@ -27,6 +27,9 @@ export const ThemeClassNames = {
},
wrapper: {
main: 'main-wrapper',
// TODO these wrapper class names are now quite useless
// TODO do breaking change later in 3.0
// we already add plugin name/id class on <html>: that's enough
blogPages: 'blog-wrapper',
docsPages: 'docs-wrapper',
mdxPages: 'mdx-wrapper',

View file

@ -17,7 +17,7 @@ import {
type GlobalSidebar,
type GlobalDoc,
} from '@docusaurus/plugin-content-docs/client';
import type {Props as DocPageProps} from '@theme/DocPage';
import type {Props as DocRootProps} from '@theme/DocRoot';
import {useDocsPreferredVersion} from '../contexts/docsPreferredVersion';
import {useDocsVersion} from '../contexts/docsVersion';
import {useDocsSidebar} from '../contexts/docsSidebar';
@ -290,14 +290,11 @@ Available doc ids are:
* version metadata, and the subroutes creating individual doc pages. This hook
* will match the current location against all known sub-routes.
*
* @param props The props received by `@theme/DocPage`
* @param props The props received by `@theme/DocRoot`
* @returns The data of the relevant document at the current location, or `null`
* if no document associated with the current location can be found.
*/
export function useDocRouteMetadata({
route,
versionMetadata,
}: DocPageProps): null | {
export function useDocRootMetadata({route}: DocRootProps): null | {
/** The element that should be rendered at the current location. */
docElement: JSX.Element;
/**
@ -309,6 +306,7 @@ export function useDocRouteMetadata({
sidebarItems: PropSidebar | undefined;
} {
const location = useLocation();
const versionMetadata = useDocsVersion();
const docRoutes = route.routes!;
const currentDocRoute = docRoutes.find((docRoute) =>
matchPath(location.pathname, docRoute),