From 41d1071efd16ea33c2b6067c717c53ebfed62d34 Mon Sep 17 00:00:00 2001 From: TheCatLady <52870424+TheCatLady@users.noreply.github.com> Date: Fri, 1 Mar 2024 09:12:49 -0800 Subject: [PATCH] fix: custom blog plugin metadata --- src/theme/BlogPostPage/Metadata.tsx | 58 +++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/theme/BlogPostPage/Metadata.tsx diff --git a/src/theme/BlogPostPage/Metadata.tsx b/src/theme/BlogPostPage/Metadata.tsx new file mode 100644 index 00000000..9c2a0f73 --- /dev/null +++ b/src/theme/BlogPostPage/Metadata.tsx @@ -0,0 +1,58 @@ +import { PageMetadata } from '@docusaurus/theme-common'; +import { useBlogPost } from '@docusaurus/theme-common/internal'; +import { openGraph } from '@site/src/utils/og'; + +export default function BlogPostPageMetadata(): JSX.Element { + const { frontMatter, assets, metadata } = useBlogPost(); + const { + title, + description, + date, + tags, + authors, + formattedDate, + readingTime, + } = metadata; + + const { keywords } = frontMatter; + + const image = + assets.image ?? + frontMatter.image ?? + openGraph({ + title, + metadata: formattedDate + ? `${formattedDate}${ + readingTime ? ` ยท ${Math.ceil(readingTime)} min read` : '' + }` + : null, + authors, + }); + return ( + + + + {/* TODO double check those article meta array syntaxes, see https://ogp.me/#array */} + {authors.some((author) => author.url) && ( + author.url) + .filter(Boolean) + .join(',')} + /> + )} + {tags.length > 0 && ( + tag.label).join(',')} + /> + )} + + ); +}