cal/packages/lib/next-seo.config.ts
Richard Poelderl 174c730f1f
chore: add canonical to the document via `PageWrapper` (#8639)
* add canonical to the document via `PageWrapper`

* use WEBSITE_URL constant to create the canonical url value

---------

Co-authored-by: Keith Williams <keithwillcode@gmail.com>
Co-authored-by: Efraín Rochín <roae.85@gmail.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
2023-06-02 18:28:03 +00:00

53 lines
1.4 KiB
TypeScript

import type { DefaultSeoProps, NextSeoProps } from "next-seo";
import type { Router } from "next/router";
import { APP_NAME, SEO_IMG_DEFAULT, SEO_IMG_OGIMG } from "@calcom/lib/constants";
import type { AppImageProps, MeetingImageProps } from "./OgImages";
export type HeadSeoProps = {
title: string;
description: string;
siteName?: string;
url?: string;
canonical?: string;
nextSeoProps?: NextSeoProps;
app?: AppImageProps;
meeting?: MeetingImageProps;
};
const seoImages = {
default: SEO_IMG_DEFAULT,
ogImage: SEO_IMG_OGIMG,
};
export const getSeoImage = (key: keyof typeof seoImages): string => {
return seoImages[key];
};
export const seoConfig: {
headSeo: Required<Pick<HeadSeoProps, "siteName">>;
defaultNextSeo: DefaultSeoProps;
} = {
headSeo: {
siteName: APP_NAME,
},
defaultNextSeo: {
twitter: {
handle: "@calcom",
site: "@calcom",
cardType: "summary_large_image",
},
},
} as const;
/**
* This function builds a canonical URL from a given host and path omitting the query params. Note: on homepage it omits the trailing slash
* @param origin The protocol + host, e.g. `https://cal.com` or `https://cal.dev`
* @param path NextJS' useRouter().asPath
* @returns
*/
export const buildCanonical = ({ origin, path }: { origin: Location["origin"]; path: Router["asPath"] }) => {
return `${origin}${path === "/" ? "" : path}`.split("?")[0];
};