feat: different implementation

This commit is contained in:
John Reilly 2021-08-19 17:19:05 +01:00
parent 29afb64445
commit 84bf24c69b
3 changed files with 11 additions and 19 deletions

View file

@ -132,7 +132,7 @@ declare module '@theme/Seo' {
readonly description?: string;
readonly keywords?: readonly string[] | string;
readonly image?: string;
readonly metaTags?: Record<string, string>;
readonly children?: ReactNode;
};
const Seo: (props: Props) => JSX.Element;

View file

@ -127,20 +127,16 @@ function BlogPostItem(props: Props): JSX.Element {
);
};
const metaTags = isBlogPostPage
? {
'og:type': 'article',
'article:published_time': date,
...(authorURL ? {'article:author': authorURL} : {}),
...(frontMatter.tags
? {'article:tag': frontMatter.tags.join(',')}
: {}),
}
: undefined;
return (
<>
<Seo {...{keywords, image, metaTags}} />
<Seo {...{keywords, image}}>
<meta property="og:type" content="article" />
<meta property="article:published_time" content={date} />
{authorURL && <meta property="article:author" content={authorURL} />}
{frontMatter.tags && (
<meta property="article:tag" content={frontMatter.tags.join(',')} />
)}
</Seo>
<article
className={!isBlogPostPage ? 'margin-bottom--xl' : undefined}

View file

@ -17,7 +17,7 @@ export default function Seo({
description,
keywords,
image,
metaTags,
children,
}: Props): JSX.Element {
const {image: defaultImage} = useThemeConfig();
const pageTitle = useTitleFormatter(title);
@ -28,11 +28,6 @@ export default function Seo({
{title && <title>{pageTitle}</title>}
{title && <meta property="og:title" content={pageTitle} />}
{metaTags &&
Object.entries(metaTags).map(([property, content]) => (
<meta key={property} property={property} content={content} />
))}
{description && <meta name="description" content={description} />}
{description && <meta property="og:description" content={description} />}
@ -47,6 +42,7 @@ export default function Seo({
{pageImage && <meta property="og:image" content={pageImage} />}
{pageImage && <meta name="twitter:image" content={pageImage} />}
{children}
</Head>
);
}