fix(content-docs): properly display collocated social card image (#6744)

* fix(content-docs): properly display collocated social card image

* oops
This commit is contained in:
Joshua Chen 2022-02-23 18:21:22 +08:00 committed by GitHub
parent ddad9713e6
commit 051380aa4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 2 deletions

View file

@ -8,6 +8,10 @@
declare module '@docusaurus/plugin-content-docs' {
import type {RemarkAndRehypePluginOptions} from '@docusaurus/mdx-loader';
export interface Assets {
image?: string;
}
export type NumberPrefixParser = (filename: string) => {
filename: string;
numberPrefix?: number;
@ -159,6 +163,7 @@ declare module '@theme/DocItem' {
import type {
PropNavigationLink,
PropVersionMetadata,
Assets,
} from '@docusaurus/plugin-content-docs';
export type DocumentRoute = {
@ -204,6 +209,7 @@ declare module '@theme/DocItem' {
readonly metadata: Metadata;
readonly toc: readonly TOCItem[];
readonly contentTitle: string | undefined;
readonly assets: Assets;
(): JSX.Element;
};
}

View file

@ -22,9 +22,8 @@ import DocBreadcrumbs from '@theme/DocBreadcrumbs';
export default function DocItem(props: Props): JSX.Element {
const {content: DocContent} = props;
const {metadata, frontMatter} = DocContent;
const {metadata, frontMatter, assets} = DocContent;
const {
image,
keywords,
hide_title: hideTitle,
hide_table_of_contents: hideTableOfContents,
@ -32,6 +31,7 @@ export default function DocItem(props: Props): JSX.Element {
toc_max_heading_level: tocMaxHeadingLevel,
} = frontMatter;
const {description, title} = metadata;
const image = assets.image ?? frontMatter.image;
// We only add a title if:
// - user asks to hide it with front matter

View file

@ -1,3 +1,7 @@
---
image: ./img/oss_logo.png
---
# Image tests
import Image from '@theme/IdealImage';

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB