diff --git a/site/components/JSONLD.tsx b/site/components/JSONLD.tsx new file mode 100644 index 00000000..b6726597 --- /dev/null +++ b/site/components/JSONLD.tsx @@ -0,0 +1,65 @@ +import { ArticleJsonLd } from 'next-seo'; +import { useRouter } from 'next/router'; + +export default function JSONLD({ + meta, + source, +}: { + meta: any; + source: string; +}): JSX.Element { + if (!source) { + return <>; + } + + const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || 'https://portaljs.org'; + const pageUrl = `${baseUrl}/${meta.urlPath}`; + + const imageMatches = source.match( + /(?<=src: ")(.*)\.((png)|(jpg)|(jpeg))(?=")/g + ); + let images = []; + if (imageMatches) { + images = [...imageMatches]; + images = images.map((img) => + img.startsWith('http') + ? img + : `${baseUrl}${img.startsWith('/') ? '' : '/'}${img}` + ); + } + + let Component: JSX.Element; + + const isBlog: boolean = + /^blog\/.*/.test(meta.urlPath) || meta.filetype === 'blog'; + const isDoc: boolean = /^((docs)|(howtos\/)|(guide\/)).*/.test(meta.urlPath); + + if (isBlog) { + Component = ( + + ); + } else if (isDoc) { + Component = ( + + ); + } + + return Component; +} diff --git a/site/components/Layout.tsx b/site/components/Layout.tsx index 66496d90..f3fc0b0a 100644 --- a/site/components/Layout.tsx +++ b/site/components/Layout.tsx @@ -54,12 +54,14 @@ function useTableOfContents(tableOfContents) { export default function Layout({ children, title, + description, tableOfContents = [], isHomePage = false, sidebarTree = [], }: { children; title?: string; + description?: string; tableOfContents?; urlPath?: string; sidebarTree?: []; @@ -82,7 +84,7 @@ export default function Layout({ return ( <> - {title && } + {title && }