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";
|
|
|
|
import React from "react";
|
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;
|
|
|
|
name?: string;
|
|
|
|
url?: string;
|
2022-01-11 08:54:02 +00:00
|
|
|
username?: string;
|
2021-08-27 12:35:20 +00:00
|
|
|
canonical?: string;
|
|
|
|
nextSeoProps?: NextSeoProps;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-01-11 08:54:02 +00:00
|
|
|
const constructImage = (name: string, description: string, username: string): string => {
|
2021-08-27 12:35:20 +00:00
|
|
|
return (
|
|
|
|
encodeURIComponent("Meet **" + name + "** <br>" + description).replace(/'/g, "%27") +
|
2021-09-23 20:05:24 +00:00
|
|
|
".png?md=1&images=https%3A%2F%2Fcal.com%2Flogo-white.svg&images=" +
|
2022-03-26 00:39:38 +00:00
|
|
|
(process.env.NEXT_PUBLIC_WEBSITE_URL || process.env.NEXT_PUBLIC_WEBAPP_URL) +
|
2022-01-11 08:54:02 +00:00
|
|
|
"/" +
|
|
|
|
username +
|
|
|
|
"/avatar.png"
|
2021-08-27 12:35:20 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
const {
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
name = null,
|
2022-01-11 08:54:02 +00:00
|
|
|
username = null,
|
2021-08-27 12:35:20 +00:00
|
|
|
siteName,
|
|
|
|
canonical = defaultUrl,
|
|
|
|
nextSeoProps = {},
|
|
|
|
} = props;
|
|
|
|
|
2022-01-11 16:26:45 +00:00
|
|
|
const truncatedDescription = description.length > 24 ? description.substring(0, 23) + "..." : description;
|
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-01-11 08:54:02 +00:00
|
|
|
if (name && username) {
|
|
|
|
const pageImage = getSeoImage("ogImage") + constructImage(name, truncatedDescription, username);
|
|
|
|
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;
|