From 321dcfef6562ce168b3bb37a9995be72f394c0ec Mon Sep 17 00:00:00 2001 From: Jody Heavener Date: Fri, 4 Feb 2022 16:31:44 -0400 Subject: [PATCH] WIP refactor --- .../src/__tests__/options.test.ts | 1 + .../src/options.ts | 5 +++ .../src/plugin-content-docs.d.ts | 1 + .../src/__tests__/validateThemeConfig.test.ts | 10 ----- .../src/theme/DocBreadcrumbs/index.tsx | 40 +++++++++---------- .../src/validateThemeConfig.ts | 5 --- .../src/utils/docsUtils.tsx | 1 - .../src/utils/useThemeConfig.ts | 3 -- 8 files changed, 26 insertions(+), 40 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/options.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/options.test.ts index a4d94d4c36a54..5ef88f9e26bab 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/options.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/options.test.ts @@ -56,6 +56,7 @@ describe('normalizeDocsPluginOptions', () => { rehypePlugins: [markdownPluginsFunctionStub], beforeDefaultRehypePlugins: [], beforeDefaultRemarkPlugins: [], + breadcrumbs: 'nested', showLastUpdateTime: true, showLastUpdateAuthor: true, admonitions: {}, diff --git a/packages/docusaurus-plugin-content-docs/src/options.ts b/packages/docusaurus-plugin-content-docs/src/options.ts index 7c79e5ac02d5f..520652578c2bb 100644 --- a/packages/docusaurus-plugin-content-docs/src/options.ts +++ b/packages/docusaurus-plugin-content-docs/src/options.ts @@ -55,6 +55,7 @@ export const DEFAULT_OPTIONS: Omit = { editLocalizedFiles: false, sidebarCollapsible: true, sidebarCollapsed: true, + breadcrumbs: 'nested', }; const VersionOptionsSchema = Joi.object({ @@ -139,6 +140,10 @@ export const OptionsSchema = Joi.object({ disableVersioning: Joi.bool().default(DEFAULT_OPTIONS.disableVersioning), lastVersion: Joi.string().optional(), versions: VersionsOptionsSchema, + breadcrumbs: Joi.alternatives( + Joi.bool(), + Joi.string().valid('nested'), + ).default(DEFAULT_OPTIONS.breadcrumbs), }); export function validateOptions({ diff --git a/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts b/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts index 54efdffec5f2f..4ec8ff81f9ffc 100644 --- a/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts +++ b/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts @@ -38,6 +38,7 @@ declare module '@docusaurus/plugin-content-docs' { showLastUpdateTime?: boolean; showLastUpdateAuthor?: boolean; numberPrefixParser: NumberPrefixParser; + breadcrumbs: boolean | 'nested'; }; export type PathOptions = { diff --git a/packages/docusaurus-theme-classic/src/__tests__/validateThemeConfig.test.ts b/packages/docusaurus-theme-classic/src/__tests__/validateThemeConfig.test.ts index d8a7de49b9232..67a2ec87a2851 100644 --- a/packages/docusaurus-theme-classic/src/__tests__/validateThemeConfig.test.ts +++ b/packages/docusaurus-theme-classic/src/__tests__/validateThemeConfig.test.ts @@ -701,14 +701,4 @@ describe('themeConfig tableOfContents', () => { `"\\"tableOfContents.minHeadingLevel\\" must be less than or equal to ref:maxHeadingLevel"`, ); }); - - test('should accept nested breadcrumb config', () => { - const breadcrumbConfig = { - breadcrumbs: 'nested', - }; - expect(testValidateThemeConfig(breadcrumbConfig)).toEqual({ - ...DEFAULT_CONFIG, - ...breadcrumbConfig, - }); - }); }); diff --git a/packages/docusaurus-theme-classic/src/theme/DocBreadcrumbs/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocBreadcrumbs/index.tsx index c707a0a1bb387..e8d182a53b146 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocBreadcrumbs/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocBreadcrumbs/index.tsx @@ -7,37 +7,35 @@ import React from 'react'; import { - isSamePath, + // isSamePath, ThemeClassNames, useSidebarBreadcrumbs, - useThemeConfig, } from '@docusaurus/theme-common'; import styles from './styles.module.css'; import clsx from 'clsx'; -import {useLocation} from '@docusaurus/router'; -import type {PropSidebar} from '@docusaurus/plugin-content-docs'; +// import {useLocation} from '@docusaurus/router'; +// import type {PropSidebar} from '@docusaurus/plugin-content-docs'; export default function DocBreadcrumbs(): JSX.Element | null { - const {pathname} = useLocation(); + // const {pathname} = useLocation(); const breadcrumbs = useSidebarBreadcrumbs(); - const {breadcrumbs: enabled} = useThemeConfig(); - function isExact(items: PropSidebar) { - const singleItem = items[0]; - return ( - items.length === 1 && - singleItem.type === 'link' && - isSamePath(singleItem.href, pathname) - ); - } + // function isExact(items: PropSidebar) { + // const singleItem = items[0]; + // return ( + // items.length === 1 && + // singleItem.type === 'link' && + // isSamePath(singleItem.href, pathname) + // ); + // } - if ( - !breadcrumbs.length || - enabled === false || - (enabled === 'nested' && isExact(breadcrumbs)) - ) { - return null; - } + // if ( + // !breadcrumbs.length || + // enabled === false || + // (enabled === 'nested' && isExact(breadcrumbs)) + // ) { + // return null; + // } return (