Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update isCalcom for canonicals to handle https://cal.com #6802

Merged
merged 9 commits into from Jan 31, 2023
17 changes: 12 additions & 5 deletions packages/ui/components/head-seo/HeadSeo.tsx
Expand Up @@ -11,7 +11,6 @@ import {
} from "@calcom/lib/OgImages";
import { getBrowserInfo } from "@calcom/lib/browser/browser.utils";
import { APP_NAME } from "@calcom/lib/constants";
import isCalcom from "@calcom/lib/isCalcom";
import { seoConfig, getSeoImage } from "@calcom/lib/next-seo.config";
import { truncateOnWord } from "@calcom/lib/text";

Expand Down Expand Up @@ -74,10 +73,18 @@ const buildSeoMeta = (pageProps: {
};

export const HeadSeo = (props: HeadSeoProps): JSX.Element => {
// build the canonical url to ensure it's always cal.com (not app.cal.com)
const router = useRouter();
const calcomUrl = (`https://cal.com` + (router.asPath === "/" ? "" : router.asPath)).split("?")[0]; // cut off search params
const defaultUrl = isCalcom ? calcomUrl : getBrowserInfo()?.url;
// The below code sets the defaultUrl for our canonical tags

// Get the current URL from the window object
const url = getBrowserInfo()?.url;
// Check if the URL is from cal.com
const isCalcom = url && new URL(url).hostname.endsWith("cal.com");
// Get the router's path
const path = useRouter().asPath;
// Build the canonical URL using the router's path, without query parameters. Note: on homepage it omits the trailing slash
const calcomCanonical = `https://cal.com${path === "/" ? "" : path}`.split("?")[0];
// Set the default URL to either the current URL (if self-hosted) or https://cal.com canonical URL
const defaultUrl = isCalcom ? calcomCanonical : url;

const { title, description, siteName, canonical = defaultUrl, nextSeoProps = {}, app, meeting } = props;

Expand Down