Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | 9x 9x 9x 9x 9x 9x 29x 29x 29x 29x 29x | import { useRouter } from 'next/router';
import React from 'react';
import { author as auth } from '@/constants/site';
import Head from 'next/head';
import {
alternateLinks,
articleTags,
blogTags,
imageTags,
jsonLdScript,
ogLocaleTags,
resolveSeoUrls,
robotsTags,
staticHreflangTags,
type SeoMeta,
} from './tags';
export type JsonLdContext = {
url: string;
domain?: string;
locale?: string;
author: string;
/** '' for English, '/es' or '/gl' otherwise — a builder needs it to link the locale's own home. */
langPrefix: string;
};
type Props = {
isBlog?: boolean;
noimage?: boolean;
meta?: SeoMeta;
/**
* Structured data for a page that is not a blog post, which otherwise emits none. A builder rather
* than a value, so it is fed the same canonical URL the head tags use instead of recomputing it.
*/
jsonLd?: (context: JsonLdContext) => unknown;
};
/**
* @example
* <SEO meta={meta} isBlog={true} />;
*
* @param {object} meta - The object containing the meta data for SEO
* @param {boolean} isBlog - Whether the page is a blog post the SEO changes
* @param {boolean} noimage - Whether to show the image in the SEO
* @returns {JSX.Element}
*/
const SEO = ({ meta, isBlog, noimage = true, jsonLd }: Props) => {
const { locale, pathname } = useRouter();
const urls = resolveSeoUrls({ meta, isBlog, locale, pathname });
const author = meta?.author || auth;
const description = meta?.description;
return (
<Head>
{isBlog ? blogTags({ meta, locale, author, urls }) : staticHreflangTags(urls.domain, urls.pagePath)}
<title>{meta?.title}</title>
{robotsTags(meta?.noindex)}
<meta name="author" content={author} />
<meta name="description" content={description} />
<meta property="og:description" content={description} />
<meta name="twitter:description" content={description} />
<meta property="og:title" content={meta?.title} />
<meta name="twitter:title" content={meta?.title} />
<meta property="og:type" content={isBlog ? 'article' : 'website'} />
{articleTags(isBlog, meta)}
{imageTags(noimage, urls.imageUrl, meta?.title)}
<meta property="og:url" content={urls.url} />
{ogLocaleTags(locale)}
<link rel="canonical" href={urls.url} title="Canonical url" />
{alternateLinks(meta, urls.domain, urls.category)}
{jsonLd &&
jsonLdScript(
'page-jsonld',
'page-jsonld',
jsonLd({
url: urls.url,
domain: urls.domain,
locale,
author,
langPrefix: urls.langPrefix,
}),
)}
</Head>
);
};
export default SEO;
|