2021-10-13 11:35:25 +00:00
|
|
|
import merge from "lodash/merge";
|
2021-08-27 12:35:20 +00:00
|
|
|
import { NextSeo, NextSeoProps } from "next-seo";
|
2022-10-18 17:46:22 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
AppImageProps,
|
|
|
|
constructAppImage,
|
|
|
|
constructMeetingImage,
|
|
|
|
MeetingImageProps,
|
|
|
|
} from "@calcom/lib/OgImages";
|
|
|
|
import { truncate, truncateOnWord } from "@calcom/lib/text";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-08-27 12:35:20 +00:00
|
|
|
import { getSeoImage, seoConfig } from "@lib/config/next-seo.config";
|
2021-09-22 19:52:38 +00:00
|
|
|
import { getBrowserInfo } from "@lib/core/browser/browser.utils";
|
2021-08-27 12:35:20 +00:00
|
|
|
|
|
|
|
export type HeadSeoProps = {
|
|
|
|
title: string;
|
|
|
|
description: string;
|
|
|
|
siteName?: string;
|
|
|
|
url?: string;
|
|
|
|
canonical?: string;
|
|
|
|
nextSeoProps?: NextSeoProps;
|
2022-10-18 17:46:22 +00:00
|
|
|
app?: AppImageProps;
|
|
|
|
meeting?: MeetingImageProps;
|
2021-08-27 12:35:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build full seo tags from title, desc, canonical and url
|
|
|
|
*/
|
|
|
|
const buildSeoMeta = (pageProps: {
|
|
|
|
title: string;
|
|
|
|
description: string;
|
|
|
|
image: string;
|
|
|
|
siteName?: string;
|
|
|
|
url?: string;
|
|
|
|
canonical?: string;
|
|
|
|
}): NextSeoProps => {
|
|
|
|
const { title, description, image, canonical, siteName = seoConfig.headSeo.siteName } = pageProps;
|
|
|
|
return {
|
|
|
|
title: title,
|
|
|
|
canonical: canonical,
|
|
|
|
openGraph: {
|
|
|
|
site_name: siteName,
|
|
|
|
type: "website",
|
|
|
|
title: title,
|
|
|
|
description: description,
|
|
|
|
images: [
|
|
|
|
{
|
|
|
|
url: image,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
additionalMetaTags: [
|
|
|
|
{
|
|
|
|
property: "name",
|
|
|
|
content: title,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
property: "description",
|
|
|
|
content: description,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "description",
|
|
|
|
content: description,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
property: "image",
|
|
|
|
content: image,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-04-04 20:26:14 +00:00
|
|
|
export const HeadSeo = (props: HeadSeoProps): JSX.Element => {
|
2021-08-27 12:35:20 +00:00
|
|
|
const defaultUrl = getBrowserInfo()?.url;
|
|
|
|
const image = getSeoImage("default");
|
|
|
|
|
2022-10-18 17:46:22 +00:00
|
|
|
const { title, description, siteName, canonical = defaultUrl, nextSeoProps = {}, app, meeting } = props;
|
|
|
|
|
|
|
|
const truncatedDescription = truncate(description, 24);
|
|
|
|
const longerTruncatedDescriptionOnWords = truncateOnWord(description, 148);
|
2021-08-27 12:35:20 +00:00
|
|
|
|
2021-09-15 18:18:16 +00:00
|
|
|
const pageTitle = title + " | Cal.com";
|
2022-01-11 08:54:02 +00:00
|
|
|
let seoObject = buildSeoMeta({
|
|
|
|
title: pageTitle,
|
|
|
|
image,
|
|
|
|
description: truncatedDescription,
|
|
|
|
canonical,
|
|
|
|
siteName,
|
|
|
|
});
|
2021-08-27 12:35:20 +00:00
|
|
|
|
2022-10-18 17:46:22 +00:00
|
|
|
if (meeting) {
|
|
|
|
const pageImage = getSeoImage("ogImage") + constructMeetingImage(meeting);
|
|
|
|
seoObject = buildSeoMeta({
|
|
|
|
title: pageTitle,
|
|
|
|
description: truncatedDescription,
|
|
|
|
image: pageImage,
|
|
|
|
canonical,
|
|
|
|
siteName,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (app) {
|
|
|
|
const pageImage =
|
|
|
|
getSeoImage("ogImage") + constructAppImage({ ...app, description: longerTruncatedDescriptionOnWords });
|
2022-01-11 08:54:02 +00:00
|
|
|
seoObject = buildSeoMeta({
|
|
|
|
title: pageTitle,
|
|
|
|
description: truncatedDescription,
|
|
|
|
image: pageImage,
|
|
|
|
canonical,
|
|
|
|
siteName,
|
|
|
|
});
|
2021-08-27 12:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const seoProps: NextSeoProps = merge(nextSeoProps, seoObject);
|
|
|
|
|
|
|
|
return <NextSeo {...seoProps} />;
|
|
|
|
};
|
2022-04-04 20:26:14 +00:00
|
|
|
|
|
|
|
export default HeadSeo;
|