-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
refactor(theme): use JSON-LD instead of microdata for blog structured data #9669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
e0da5cf
feat: JSON-LD structured data implementation for blog
johnnyreilly 6521052
Merge branch 'main' of https://github.com/johnnyreilly/docusaurus int…
johnnyreilly 2bc8ca6
fix: tests
johnnyreilly 25afce0
Update packages/docusaurus-theme-classic/src/theme/BlogPostPage/Struc…
johnnyreilly 1df8ce4
Update packages/docusaurus-theme-classic/src/theme/BlogListPage/Struc…
johnnyreilly 7c88ae0
feat: migrate to blogMetadata bundle/prop as suggested by @slorber
johnnyreilly 79224e1
feat: dedicated StructuredData component
johnnyreilly c21d57a
feat: add structuredDataUtils
johnnyreilly c5961ea
feat: add schema-dts
johnnyreilly 4cc7a50
fix: single blogMetadata
johnnyreilly 885dbaf
fix: split out getImage
johnnyreilly 6663726
fix: getAuthor / getImage move
johnnyreilly 8ffcb58
fix: getBlogPost
johnnyreilly ce1b664
fix: baseBlogPermalink -> blogBasePath
johnnyreilly 3ce60a1
fix: migrate structuredData logic to theme-common
johnnyreilly 356d8f2
fix: move StructuredData to theme-common
johnnyreilly 55433eb
fix: remove unnecessary prop
johnnyreilly e59c882
fix: less prop drilling
johnnyreilly 0be47bd
fix: address review feedback
johnnyreilly 6d26f5c
Add blog plugin useBlogMetadata() client hook + refactor to use it
slorber 84a13d1
fix blog tests???
slorber 20256fa
revert usage of StructuredData comp in docs
slorber 96073e8
remove StructuredData component
slorber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.