@docusaurus/theme-classic 0.0.0-4356 → 0.0.0-4364

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -477,10 +477,23 @@ declare module '@theme/NavbarItem/DocNavbarItem' {
477
477
  export default DocsSidebarNavbarItem;
478
478
  }
479
479
 
480
+ declare module '@theme/NavbarItem/DocSidebarNavbarItem' {
481
+ import type {Props as DefaultNavbarItemProps} from '@theme/NavbarItem/DefaultNavbarItem';
482
+
483
+ export interface Props extends DefaultNavbarItemProps {
484
+ readonly sidebarId: string;
485
+ readonly docsPluginId?: string;
486
+ }
487
+
488
+ const DocSidebarNavbarItem: (props: Props) => JSX.Element;
489
+ export default DocSidebarNavbarItem;
490
+ }
491
+
480
492
  declare module '@theme/NavbarItem' {
481
493
  import type {ComponentProps} from 'react';
482
494
  import type {Props as DefaultNavbarItemProps} from '@theme/NavbarItem/DefaultNavbarItem';
483
495
  import type {Props as DocNavbarItemProps} from '@theme/NavbarItem/DocNavbarItem';
496
+ import type {Props as DocSidebarNavbarItemProps} from '@theme/NavbarItem/DocSidebarNavbarItem';
484
497
  import type {Props as DocsVersionNavbarItemProps} from '@theme/NavbarItem/DocsVersionNavbarItem';
485
498
  import type {Props as DropdownNavbarItemProps} from '@theme/NavbarItem/DropdownNavbarItem';
486
499
  import type {Props as DocsVersionDropdownNavbarItemProps} from '@theme/NavbarItem/DocsVersionDropdownNavbarItem';
@@ -490,7 +503,8 @@ declare module '@theme/NavbarItem' {
490
503
  export type LinkLikeNavbarItemProps =
491
504
  | ({readonly type?: 'default'} & DefaultNavbarItemProps)
492
505
  | ({readonly type: 'doc'} & DocNavbarItemProps)
493
- | ({readonly type: 'docsVersion'} & DocsVersionNavbarItemProps);
506
+ | ({readonly type: 'docsVersion'} & DocsVersionNavbarItemProps)
507
+ | ({readonly type: 'docSidebar'} & DocSidebarNavbarItemProps);
494
508
 
495
509
  export type Props = ComponentProps<'a'> & {
496
510
  readonly position?: 'left' | 'right';
@@ -84,6 +84,11 @@ const DocItemSchema = NavbarItemBaseSchema.append({
84
84
  docId: _utilsValidation.Joi.string().required(),
85
85
  docsPluginId: _utilsValidation.Joi.string()
86
86
  });
87
+ const DocSidebarItemSchema = NavbarItemBaseSchema.append({
88
+ type: _utilsValidation.Joi.string().equal('docSidebar').required(),
89
+ sidebarId: _utilsValidation.Joi.string().required(),
90
+ docsPluginId: _utilsValidation.Joi.string()
91
+ });
87
92
 
88
93
  const itemWithType = type => {
89
94
  // because equal(undefined) is not supported :/
@@ -151,6 +156,9 @@ const NavbarItemSchema = _utilsValidation.Joi.object({
151
156
  }, {
152
157
  is: itemWithType('doc'),
153
158
  then: DocItemSchema
159
+ }, {
160
+ is: itemWithType('docSidebar'),
161
+ then: DocSidebarItemSchema
154
162
  }, {
155
163
  is: itemWithType('localeDropdown'),
156
164
  then: LocaleDropdownNavbarItemSchema
@@ -14,14 +14,17 @@ import TOC from '@theme/TOC';
14
14
 
15
15
  function BlogPostPage(props) {
16
16
  const {content: BlogPostContents, sidebar} = props;
17
+ const {assets, metadata} = BlogPostContents;
17
18
  const {
18
- // TODO this frontmatter is not validated/normalized, it's the raw user-provided one. We should expose normalized one too!
19
+ title,
20
+ description,
21
+ nextItem,
22
+ prevItem,
23
+ date,
24
+ tags,
25
+ authors,
19
26
  frontMatter,
20
- assets,
21
- metadata,
22
- } = BlogPostContents;
23
- const {title, description, nextItem, prevItem, date, tags, authors} =
24
- metadata;
27
+ } = metadata;
25
28
  const {
26
29
  hide_table_of_contents: hideTableOfContents,
27
30
  keywords,
@@ -12,6 +12,7 @@ import Seo from '@theme/Seo';
12
12
  import DocVersionBanner from '@theme/DocVersionBanner';
13
13
  import DocVersionBadge from '@theme/DocVersionBadge';
14
14
  import {MainHeading} from '@theme/Heading';
15
+ import useBaseUrl from '@docusaurus/useBaseUrl';
15
16
  import styles from './styles.module.css';
16
17
  export default function DocCategoryGeneratedIndexPage({
17
18
  categoryGeneratedIndex,
@@ -22,6 +23,8 @@ export default function DocCategoryGeneratedIndexPage({
22
23
  <Seo
23
24
  title={categoryGeneratedIndex.title}
24
25
  description={categoryGeneratedIndex.description}
26
+ keywords={categoryGeneratedIndex.keywords} // TODO `require` this?
27
+ image={useBaseUrl(categoryGeneratedIndex.image)}
25
28
  />
26
29
  <div className={styles.generatedIndexPage}>
27
30
  <DocVersionBanner />
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import React from 'react';
8
+ import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
9
+ import {useLatestVersion, useActiveDocContext} from '@theme/hooks/useDocs';
10
+ import clsx from 'clsx';
11
+ import {getInfimaActiveClassName} from './index';
12
+ import {useDocsPreferredVersion, uniq} from '@docusaurus/theme-common';
13
+
14
+ function getSidebarLink(versions, sidebarId) {
15
+ const allSidebars = versions
16
+ .flatMap((version) => {
17
+ if (version.sidebars) {
18
+ return Object.entries(version.sidebars);
19
+ }
20
+
21
+ return undefined;
22
+ })
23
+ .filter((sidebarItem) => !!sidebarItem);
24
+ const sidebarEntry = allSidebars.find((sidebar) => sidebar[0] === sidebarId);
25
+
26
+ if (!sidebarEntry) {
27
+ throw new Error(`DocSidebarNavbarItem: couldn't find any sidebar with id "${sidebarId}" in version${
28
+ versions.length ? 's' : ''
29
+ } ${versions.map((version) => version.name).join(', ')}".
30
+ Available sidebar ids are:
31
+ - ${Object.keys(allSidebars).join('\n- ')}`);
32
+ }
33
+
34
+ if (!sidebarEntry[1].link) {
35
+ throw new Error(
36
+ `DocSidebarNavbarItem: couldn't find any document for sidebar with id "${sidebarId}"`,
37
+ );
38
+ }
39
+
40
+ return sidebarEntry[1].link;
41
+ }
42
+
43
+ export default function DocSidebarNavbarItem({
44
+ sidebarId,
45
+ label,
46
+ docsPluginId,
47
+ ...props
48
+ }) {
49
+ const {activeVersion, activeDoc} = useActiveDocContext(docsPluginId);
50
+ const {preferredVersion} = useDocsPreferredVersion(docsPluginId);
51
+ const latestVersion = useLatestVersion(docsPluginId); // Versions used to look for the doc to link to, ordered + no duplicate
52
+
53
+ const versions = uniq(
54
+ [activeVersion, preferredVersion, latestVersion].filter(Boolean),
55
+ );
56
+ const sidebarLink = getSidebarLink(versions, sidebarId);
57
+ const activeDocInfimaClassName = getInfimaActiveClassName(props.mobile);
58
+ return (
59
+ <DefaultNavbarItem
60
+ exact
61
+ {...props}
62
+ className={clsx(props.className, {
63
+ [activeDocInfimaClassName]: activeDoc?.sidebar === sidebarId,
64
+ })}
65
+ activeClassName={activeDocInfimaClassName}
66
+ label={label ?? sidebarLink.label}
67
+ to={sidebarLink.path}
68
+ />
69
+ );
70
+ }
@@ -22,6 +22,7 @@ const NavbarItemComponents = {
22
22
  docsVersionDropdown: () =>
23
23
  require('@theme/NavbarItem/DocsVersionDropdownNavbarItem').default,
24
24
  doc: () => require('@theme/NavbarItem/DocNavbarItem').default,
25
+ docSidebar: () => require('@theme/NavbarItem/DocSidebarNavbarItem').default,
25
26
  /* eslint-enable @typescript-eslint/no-var-requires, global-require */
26
27
  };
27
28
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/theme-classic",
3
- "version": "0.0.0-4356",
3
+ "version": "0.0.0-4364",
4
4
  "description": "Classic theme for Docusaurus",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/theme-classic.d.ts",
@@ -23,14 +23,14 @@
23
23
  "update-code-translations": "node -e 'require(\"./update-code-translations.js\").run()'"
24
24
  },
25
25
  "dependencies": {
26
- "@docusaurus/core": "0.0.0-4356",
27
- "@docusaurus/plugin-content-blog": "0.0.0-4356",
28
- "@docusaurus/plugin-content-docs": "0.0.0-4356",
29
- "@docusaurus/plugin-content-pages": "0.0.0-4356",
30
- "@docusaurus/theme-common": "0.0.0-4356",
31
- "@docusaurus/theme-translations": "0.0.0-4356",
32
- "@docusaurus/utils": "0.0.0-4356",
33
- "@docusaurus/utils-validation": "0.0.0-4356",
26
+ "@docusaurus/core": "0.0.0-4364",
27
+ "@docusaurus/plugin-content-blog": "0.0.0-4364",
28
+ "@docusaurus/plugin-content-docs": "0.0.0-4364",
29
+ "@docusaurus/plugin-content-pages": "0.0.0-4364",
30
+ "@docusaurus/theme-common": "0.0.0-4364",
31
+ "@docusaurus/theme-translations": "0.0.0-4364",
32
+ "@docusaurus/utils": "0.0.0-4364",
33
+ "@docusaurus/utils-validation": "0.0.0-4364",
34
34
  "@mdx-js/mdx": "^1.6.21",
35
35
  "@mdx-js/react": "^1.6.21",
36
36
  "clsx": "^1.1.1",
@@ -45,8 +45,8 @@
45
45
  "rtlcss": "^3.3.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@docusaurus/module-type-aliases": "0.0.0-4356",
49
- "@docusaurus/types": "0.0.0-4356",
48
+ "@docusaurus/module-type-aliases": "0.0.0-4364",
49
+ "@docusaurus/types": "0.0.0-4364",
50
50
  "@types/mdx-js__react": "^1.5.4",
51
51
  "@types/parse-numeric-range": "^0.0.1",
52
52
  "@types/rtlcss": "^3.1.1",
@@ -61,5 +61,5 @@
61
61
  "engines": {
62
62
  "node": ">=14"
63
63
  },
64
- "gitHead": "689533485d30a832b6a1d4108c491c90bb6165e7"
64
+ "gitHead": "db9cb5ab444107d56734f4e8405721484197d0a9"
65
65
  }
@@ -16,14 +16,17 @@ import TOC from '@theme/TOC';
16
16
 
17
17
  function BlogPostPage(props: Props): JSX.Element {
18
18
  const {content: BlogPostContents, sidebar} = props;
19
+ const {assets, metadata} = BlogPostContents;
19
20
  const {
20
- // TODO this frontmatter is not validated/normalized, it's the raw user-provided one. We should expose normalized one too!
21
+ title,
22
+ description,
23
+ nextItem,
24
+ prevItem,
25
+ date,
26
+ tags,
27
+ authors,
21
28
  frontMatter,
22
- assets,
23
- metadata,
24
- } = BlogPostContents;
25
- const {title, description, nextItem, prevItem, date, tags, authors} =
26
- metadata;
29
+ } = metadata;
27
30
  const {
28
31
  hide_table_of_contents: hideTableOfContents,
29
32
  keywords,
@@ -14,6 +14,7 @@ import Seo from '@theme/Seo';
14
14
  import DocVersionBanner from '@theme/DocVersionBanner';
15
15
  import DocVersionBadge from '@theme/DocVersionBadge';
16
16
  import {MainHeading} from '@theme/Heading';
17
+ import useBaseUrl from '@docusaurus/useBaseUrl';
17
18
 
18
19
  import styles from './styles.module.css';
19
20
 
@@ -26,6 +27,9 @@ export default function DocCategoryGeneratedIndexPage({
26
27
  <Seo
27
28
  title={categoryGeneratedIndex.title}
28
29
  description={categoryGeneratedIndex.description}
30
+ keywords={categoryGeneratedIndex.keywords}
31
+ // TODO `require` this?
32
+ image={useBaseUrl(categoryGeneratedIndex.image)}
29
33
  />
30
34
  <div className={styles.generatedIndexPage}>
31
35
  <DocVersionBanner />
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import React from 'react';
9
+ import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
10
+ import {useLatestVersion, useActiveDocContext} from '@theme/hooks/useDocs';
11
+ import clsx from 'clsx';
12
+ import {getInfimaActiveClassName} from './index';
13
+ import type {Props} from '@theme/NavbarItem/DocSidebarNavbarItem';
14
+ import {useDocsPreferredVersion, uniq} from '@docusaurus/theme-common';
15
+ import type {
16
+ GlobalDataVersion,
17
+ GlobalDataSidebar,
18
+ } from '@docusaurus/plugin-content-docs';
19
+
20
+ function getSidebarLink(versions: GlobalDataVersion[], sidebarId: string) {
21
+ const allSidebars = versions
22
+ .flatMap((version) => {
23
+ if (version.sidebars) {
24
+ return Object.entries(version.sidebars);
25
+ }
26
+ return undefined;
27
+ })
28
+ .filter(
29
+ (sidebarItem): sidebarItem is [string, GlobalDataSidebar] =>
30
+ !!sidebarItem,
31
+ );
32
+ const sidebarEntry = allSidebars.find((sidebar) => sidebar[0] === sidebarId);
33
+ if (!sidebarEntry) {
34
+ throw new Error(
35
+ `DocSidebarNavbarItem: couldn't find any sidebar with id "${sidebarId}" in version${
36
+ versions.length ? 's' : ''
37
+ } ${versions.map((version) => version.name).join(', ')}".
38
+ Available sidebar ids are:
39
+ - ${Object.keys(allSidebars).join('\n- ')}`,
40
+ );
41
+ }
42
+ if (!sidebarEntry[1].link) {
43
+ throw new Error(
44
+ `DocSidebarNavbarItem: couldn't find any document for sidebar with id "${sidebarId}"`,
45
+ );
46
+ }
47
+ return sidebarEntry[1].link;
48
+ }
49
+
50
+ export default function DocSidebarNavbarItem({
51
+ sidebarId,
52
+ label,
53
+ docsPluginId,
54
+ ...props
55
+ }: Props): JSX.Element {
56
+ const {activeVersion, activeDoc} = useActiveDocContext(docsPluginId);
57
+ const {preferredVersion} = useDocsPreferredVersion(docsPluginId);
58
+ const latestVersion = useLatestVersion(docsPluginId);
59
+
60
+ // Versions used to look for the doc to link to, ordered + no duplicate
61
+ const versions = uniq(
62
+ [activeVersion, preferredVersion, latestVersion].filter(
63
+ Boolean,
64
+ ) as GlobalDataVersion[],
65
+ );
66
+ const sidebarLink = getSidebarLink(versions, sidebarId);
67
+ const activeDocInfimaClassName = getInfimaActiveClassName(props.mobile);
68
+
69
+ return (
70
+ <DefaultNavbarItem
71
+ exact
72
+ {...props}
73
+ className={clsx(props.className, {
74
+ [activeDocInfimaClassName]: activeDoc?.sidebar === sidebarId,
75
+ })}
76
+ activeClassName={activeDocInfimaClassName}
77
+ label={label ?? sidebarLink.label}
78
+ to={sidebarLink.path}
79
+ />
80
+ );
81
+ }
@@ -32,6 +32,7 @@ const NavbarItemComponents: Record<
32
32
  docsVersionDropdown: () =>
33
33
  require('@theme/NavbarItem/DocsVersionDropdownNavbarItem').default,
34
34
  doc: () => require('@theme/NavbarItem/DocNavbarItem').default,
35
+ docSidebar: () => require('@theme/NavbarItem/DocSidebarNavbarItem').default,
35
36
  /* eslint-enable @typescript-eslint/no-var-requires, global-require */
36
37
  } as const;
37
38
 
@@ -477,10 +477,23 @@ declare module '@theme/NavbarItem/DocNavbarItem' {
477
477
  export default DocsSidebarNavbarItem;
478
478
  }
479
479
 
480
+ declare module '@theme/NavbarItem/DocSidebarNavbarItem' {
481
+ import type {Props as DefaultNavbarItemProps} from '@theme/NavbarItem/DefaultNavbarItem';
482
+
483
+ export interface Props extends DefaultNavbarItemProps {
484
+ readonly sidebarId: string;
485
+ readonly docsPluginId?: string;
486
+ }
487
+
488
+ const DocSidebarNavbarItem: (props: Props) => JSX.Element;
489
+ export default DocSidebarNavbarItem;
490
+ }
491
+
480
492
  declare module '@theme/NavbarItem' {
481
493
  import type {ComponentProps} from 'react';
482
494
  import type {Props as DefaultNavbarItemProps} from '@theme/NavbarItem/DefaultNavbarItem';
483
495
  import type {Props as DocNavbarItemProps} from '@theme/NavbarItem/DocNavbarItem';
496
+ import type {Props as DocSidebarNavbarItemProps} from '@theme/NavbarItem/DocSidebarNavbarItem';
484
497
  import type {Props as DocsVersionNavbarItemProps} from '@theme/NavbarItem/DocsVersionNavbarItem';
485
498
  import type {Props as DropdownNavbarItemProps} from '@theme/NavbarItem/DropdownNavbarItem';
486
499
  import type {Props as DocsVersionDropdownNavbarItemProps} from '@theme/NavbarItem/DocsVersionDropdownNavbarItem';
@@ -490,7 +503,8 @@ declare module '@theme/NavbarItem' {
490
503
  export type LinkLikeNavbarItemProps =
491
504
  | ({readonly type?: 'default'} & DefaultNavbarItemProps)
492
505
  | ({readonly type: 'doc'} & DocNavbarItemProps)
493
- | ({readonly type: 'docsVersion'} & DocsVersionNavbarItemProps);
506
+ | ({readonly type: 'docsVersion'} & DocsVersionNavbarItemProps)
507
+ | ({readonly type: 'docSidebar'} & DocSidebarNavbarItemProps);
494
508
 
495
509
  export type Props = ComponentProps<'a'> & {
496
510
  readonly position?: 'left' | 'right';
@@ -85,6 +85,12 @@ const DocItemSchema = NavbarItemBaseSchema.append({
85
85
  docsPluginId: Joi.string(),
86
86
  });
87
87
 
88
+ const DocSidebarItemSchema = NavbarItemBaseSchema.append({
89
+ type: Joi.string().equal('docSidebar').required(),
90
+ sidebarId: Joi.string().required(),
91
+ docsPluginId: Joi.string(),
92
+ });
93
+
88
94
  const itemWithType = (type: string | undefined) => {
89
95
  // because equal(undefined) is not supported :/
90
96
  const typeSchema = type
@@ -172,6 +178,10 @@ const NavbarItemSchema = Joi.object({
172
178
  is: itemWithType('doc'),
173
179
  then: DocItemSchema,
174
180
  },
181
+ {
182
+ is: itemWithType('docSidebar'),
183
+ then: DocSidebarItemSchema,
184
+ },
175
185
  {
176
186
  is: itemWithType('localeDropdown'),
177
187
  then: LocaleDropdownNavbarItemSchema,