-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(theme): use JSON-LD instead of microdata for blog structured…
… data (#9669) Co-authored-by: Joshua Chen <[email protected]> Co-authored-by: sebastien <[email protected]>
- Loading branch information
1 parent
8abd189
commit 60d9346
Showing
23 changed files
with
348 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/docusaurus-plugin-content-blog/src/client/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import useRouteContext from '@docusaurus/useRouteContext'; | ||
import type {BlogMetadata} from '@docusaurus/plugin-content-blog'; | ||
|
||
export function useBlogMetadata(): BlogMetadata { | ||
const routeContext = useRouteContext(); | ||
const blogMetadata = routeContext?.data?.blogMetadata; | ||
if (!blogMetadata) { | ||
throw new Error( | ||
"useBlogMetadata() can't be called on the current route because the blog metadata could not be found in route context", | ||
); | ||
} | ||
return blogMetadata as BlogMetadata; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/docusaurus-plugin-content-blog/tsconfig.client.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"noEmit": false, | ||
"composite": true, | ||
"incremental": true, | ||
"tsBuildInfoFile": "./lib/.tsbuildinfo-client", | ||
"moduleResolution": "bundler", | ||
"module": "esnext", | ||
"target": "esnext", | ||
"rootDir": "src", | ||
"outDir": "lib" | ||
}, | ||
"include": ["src/client", "src/*.d.ts"], | ||
"exclude": ["**/__tests__/**"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/docusaurus-theme-classic/src/theme/BlogListPage/StructuredData/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import Head from '@docusaurus/Head'; | ||
import {useBlogListPageStructuredData} from '@docusaurus/theme-common'; | ||
import type {Props} from '@theme/BlogListPage/StructuredData'; | ||
|
||
export default function BlogListPageStructuredData(props: Props): JSX.Element { | ||
const structuredData = useBlogListPageStructuredData(props); | ||
return ( | ||
<Head> | ||
<script type="application/ld+json"> | ||
{JSON.stringify(structuredData)} | ||
</script> | ||
</Head> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/docusaurus-theme-classic/src/theme/BlogPostPage/StructuredData/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import Head from '@docusaurus/Head'; | ||
import {useBlogPostStructuredData} from '@docusaurus/theme-common'; | ||
|
||
export default function BlogPostStructuredData(): JSX.Element { | ||
const structuredData = useBlogPostStructuredData(); | ||
return ( | ||
<Head> | ||
<script type="application/ld+json"> | ||
{JSON.stringify(structuredData)} | ||
</script> | ||
</Head> | ||
); | ||
} |
Oops, something went wrong.