import NextHead from 'next/head'; import { useRouter } from 'next/router'; import { capitalizeString } from '@/utils/capitalizeString'; import metaData from '@/data/pages.preval'; import { PREVIEW_HEIGHT, PREVIEW_WIDTH } from '@/data/preview'; import { SITE_NAME, TWITTER_HANDLE } from '@/data/general'; import { getImagePath } from '@/utils/previews'; export const Head = () => { const { asPath, pathname, query: { platform = 'react' }, } = useRouter(); const asPathname = pathname.replace('[platform]', String(platform)); const filepath = `/${pathname .split('/') .filter((n) => n && n !== '[platform]') .join('/')}`; const { title, metaTitle, description, metaDescription } = metaData[pathname]?.frontmatter ?? {}; if ((!description && !metaDescription) || (!title && !metaTitle)) { throw new Error(`Meta Info missing on ${filepath}`); } const homepagePaths = ['/', '/[platform]']; const pageTitle = homepagePaths.includes(pathname) ? `${metaTitle} on ${capitalizeString(platform as string)}` : `${metaTitle ?? title} | Amplify UI for ${capitalizeString( platform as string )}`; const _description = metaDescription || description; return ( {homepagePaths.includes(pathname) ? ( ) : null} {pageTitle} {/* Open Graph */} {/* Twitter */} ); };