File tree Expand file tree Collapse file tree 7 files changed +42
-17
lines changed
docusaurus-plugin-content-blog
docusaurus-plugin-content-docs
docusaurus-theme-classic/src/theme/DocBreadcrumbs Expand file tree Collapse file tree 7 files changed +42
-17
lines changed Original file line number Diff line number Diff line change 44
44
"fs-extra" : " ^11.1.1" ,
45
45
"lodash" : " ^4.17.21" ,
46
46
"reading-time" : " ^1.5.0" ,
47
+ "schema-dts" : " ^1.1.2" ,
47
48
"srcset" : " ^4.0.0" ,
48
49
"tslib" : " ^2.6.0" ,
49
50
"unist-util-visit" : " ^5.0.0" ,
Original file line number Diff line number Diff line change 49
49
"fs-extra" : " ^11.1.1" ,
50
50
"js-yaml" : " ^4.1.0" ,
51
51
"lodash" : " ^4.17.21" ,
52
+ "schema-dts" : " ^1.1.2" ,
52
53
"tslib" : " ^2.6.0" ,
53
54
"utility-types" : " ^3.10.0" ,
54
55
"webpack" : " ^5.88.1"
Original file line number Diff line number Diff line change @@ -60,6 +60,8 @@ export {
60
60
getDocsVersionSearchTag ,
61
61
} from './docsSearch' ;
62
62
63
+ export { useBreadcrumbsStructuredData } from './structuredDataUtils' ;
64
+
63
65
export type ActivePlugin = {
64
66
pluginId : string ;
65
67
pluginData : GlobalPluginData ;
Original file line number Diff line number Diff line change
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 useDocusaurusContext from '@docusaurus/useDocusaurusContext' ;
9
+ import type { PropSidebarBreadcrumbsItem } from '@docusaurus/plugin-content-docs' ;
10
+ import type { WithContext , BreadcrumbList } from 'schema-dts' ;
11
+
12
+ export function useBreadcrumbsStructuredData ( {
13
+ breadcrumbs,
14
+ } : {
15
+ breadcrumbs : PropSidebarBreadcrumbsItem [ ] ;
16
+ } ) : WithContext < BreadcrumbList > {
17
+ const { siteConfig} = useDocusaurusContext ( ) ;
18
+ return {
19
+ '@context' : 'https://schema.org' ,
20
+ '@type' : 'BreadcrumbList' ,
21
+ itemListElement : breadcrumbs
22
+ // We filter breadcrumb items without links, they are not allowed
23
+ // See also https://github.com/facebook/docusaurus/issues/9319#issuecomment-2643560845
24
+ . filter ( ( breadcrumb ) => breadcrumb . href )
25
+ . map ( ( breadcrumb , index ) => ( {
26
+ '@type' : 'ListItem' ,
27
+ position : index + 1 ,
28
+ name : breadcrumb . label ,
29
+ item : `${ siteConfig . url } ${ breadcrumb . href } ` ,
30
+ } ) ) ,
31
+ } ;
32
+ }
Original file line number Diff line number Diff line change 7
7
8
8
import React , { type ReactNode } from 'react' ;
9
9
import Head from '@docusaurus/Head' ;
10
- import useDocusaurusContext from '@docusaurus/useDocusaurusContext ' ;
10
+ import { useBreadcrumbsStructuredData } from '@docusaurus/plugin-content-docs/client ' ;
11
11
import type { Props } from '@theme/DocBreadcrumbs/StructuredData' ;
12
12
13
13
export default function DocBreadcrumbsStructuredData ( props : Props ) : ReactNode {
14
- const { siteConfig} = useDocusaurusContext ( ) ;
15
- const structuredData = {
16
- '@context' : 'https://schema.org' ,
17
- '@type' : 'BreadcrumbList' ,
18
- itemListElement : props . breadcrumbs
19
- . filter ( ( breadcrumb ) => breadcrumb . href )
20
- . map ( ( breadcrumb , index ) => ( {
21
- '@type' : 'ListItem' ,
22
- position : index + 1 ,
23
- name : breadcrumb . label ,
24
- item : `${ siteConfig . url } ${ breadcrumb . href } ` ,
25
- } ) ) ,
26
- } ;
14
+ const structuredData = useBreadcrumbsStructuredData ( {
15
+ breadcrumbs : props . breadcrumbs ,
16
+ } ) ;
27
17
return (
28
18
< Head >
29
19
< script type = "application/ld+json" >
Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ export default function DocBreadcrumbs(): ReactNode {
68
68
69
69
return (
70
70
< >
71
+ < DocBreadcrumbsStructuredData breadcrumbs = { breadcrumbs } />
71
72
< nav
72
73
className = { clsx (
73
74
ThemeClassNames . docs . docBreadcrumbs ,
@@ -96,7 +97,6 @@ export default function DocBreadcrumbs(): ReactNode {
96
97
} ) }
97
98
</ ul >
98
99
</ nav >
99
- < DocBreadcrumbsStructuredData breadcrumbs = { breadcrumbs } />
100
100
</ >
101
101
) ;
102
102
}
Original file line number Diff line number Diff line change 47
47
"@docusaurus/core" : " 3.7.0" ,
48
48
"@docusaurus/types" : " 3.7.0" ,
49
49
"fs-extra" : " ^11.1.1" ,
50
- "lodash" : " ^4.17.21" ,
51
- "schema-dts" : " ^1.1.2"
50
+ "lodash" : " ^4.17.21"
52
51
},
53
52
"peerDependencies" : {
54
53
"@docusaurus/plugin-content-docs" : " *" ,
You can’t perform that action at this time.
0 commit comments