Skip to content

Commit

Permalink
WIP refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jodyheavener committed Feb 4, 2022
1 parent a5db12b commit 321dcfe
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('normalizeDocsPluginOptions', () => {
rehypePlugins: [markdownPluginsFunctionStub],
beforeDefaultRehypePlugins: [],
beforeDefaultRemarkPlugins: [],
breadcrumbs: 'nested',
showLastUpdateTime: true,
showLastUpdateAuthor: true,
admonitions: {},
Expand Down
5 changes: 5 additions & 0 deletions packages/docusaurus-plugin-content-docs/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const DEFAULT_OPTIONS: Omit<PluginOptions, 'id' | 'sidebarPath'> = {
editLocalizedFiles: false,
sidebarCollapsible: true,
sidebarCollapsed: true,
breadcrumbs: 'nested',
};

const VersionOptionsSchema = Joi.object({
Expand Down Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ declare module '@docusaurus/plugin-content-docs' {
showLastUpdateTime?: boolean;
showLastUpdateAuthor?: boolean;
numberPrefixParser: NumberPrefixParser;
breadcrumbs: boolean | 'nested';
};

export type PathOptions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<nav
Expand Down
5 changes: 0 additions & 5 deletions packages/docusaurus-theme-classic/src/validateThemeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const DEFAULT_CONFIG = {
minHeadingLevel: 2,
maxHeadingLevel: 3,
},
breadcrumbs: 'nested',
};

const NavbarItemPosition = Joi.string().equal('left', 'right').default('left');
Expand Down Expand Up @@ -381,10 +380,6 @@ const ThemeConfigSchema = Joi.object({
.max(6)
.default(DEFAULT_CONFIG.tableOfContents.maxHeadingLevel),
}).default(DEFAULT_CONFIG.tableOfContents),
breadcrumbs: Joi.alternatives(
Joi.bool(),
Joi.string().valid('nested'),
).default(DEFAULT_CONFIG.breadcrumbs),
});

export {DEFAULT_CONFIG, ThemeConfigSchema};
Expand Down
1 change: 0 additions & 1 deletion packages/docusaurus-theme-common/src/utils/docsUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ export function useSidebarBreadcrumbs(): PropSidebar {
const breadcrumbs: PropSidebar = [];

function extract(items: PropSidebar) {
// eslint-disable-next-line no-restricted-syntax
for (const item of items) {
if (item.type === 'category' && extract(item.items)) {
breadcrumbs.push(item);
Expand Down
3 changes: 0 additions & 3 deletions packages/docusaurus-theme-common/src/utils/useThemeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ export type TableOfContents = {
maxHeadingLevel: number;
};

export type Breadcrumbs = boolean | 'nested';

// Theme config after validation/normalization
export type ThemeConfig = {
docs: {
Expand All @@ -129,7 +127,6 @@ export type ThemeConfig = {
metadata: Array<Record<string, string>>;
sidebarCollapsible: boolean;
tableOfContents: TableOfContents;
breadcrumbs: Breadcrumbs;
};

// User-provided theme config, unnormalized
Expand Down

0 comments on commit 321dcfe

Please sign in to comment.