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

Create _generateMetadata util and replace duplicates with this #74

Merged
merged 4 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions apps/web/app/_utils.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { headers } from "next/headers";

import { constructGenericImage } from "@calcom/lib/OgImages";
import { IS_CALCOM, WEBAPP_URL, APP_NAME, SEO_IMG_OGIMG } from "@calcom/lib/constants";
import { getFixedT } from "@calcom/lib/server/getFixedT";

import { preparePageMetadata } from "@lib/metadata";

export const _generateMetadata = async (
titleKey: string,
hbjORbj marked this conversation as resolved.
Show resolved Hide resolved
descriptionKey: string,
usePlainTitleKey?: boolean,
usePlainDescriptionKey?: boolean
) => {
const h = headers();
const canonical = h.get("x-pathname") ?? "";
const locale = h.get("x-locale") ?? "en";

const t = await getFixedT(locale, "common");

const title = usePlainTitleKey ? titleKey : t(titleKey);
const description = usePlainDescriptionKey ? descriptionKey : t(descriptionKey);

const metadataBase = new URL(IS_CALCOM ? "https://cal.com" : WEBAPP_URL);

const image =
SEO_IMG_OGIMG +
constructGenericImage({
title,
description,
});

return preparePageMetadata({
title,
canonical,
image,
description,
siteName: APP_NAME,
metadataBase,
});
};
37 changes: 2 additions & 35 deletions apps/web/app/future/(layout)/availability/page.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,6 @@
import AvailabilityPage from "@pages/availability";
import { headers } from "next/headers";
import { _generateMetadata } from "app/_utils";

import { constructGenericImage } from "@calcom/lib/OgImages";
import { IS_CALCOM, WEBAPP_URL, APP_NAME, SEO_IMG_OGIMG } from "@calcom/lib/constants";
import { getFixedT } from "@calcom/lib/server/getFixedT";

import { preparePageMetadata } from "@lib/metadata";

export const generateMetadata = async () => {
const h = headers();
const canonical = h.get("x-pathname") ?? "";
const locale = h.get("x-locale") ?? "en";

const t = await getFixedT(locale, "common");

const title = t("availability");
const description = t("configure_availability");

const metadataBase = new URL(IS_CALCOM ? "https://cal.com" : WEBAPP_URL);

const image =
SEO_IMG_OGIMG +
constructGenericImage({
title,
description,
});

return preparePageMetadata({
title,
canonical,
image,
description,
siteName: APP_NAME,
metadataBase,
});
};
export const generateMetadata = async () => await _generateMetadata("availability", "configure_availability");

export default AvailabilityPage;
38 changes: 3 additions & 35 deletions apps/web/app/future/(layout)/event-types/page.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,7 @@
import EventTypes from "@pages/event-types";
import { headers } from "next/headers";
import { _generateMetadata } from "app/_utils";

import { constructGenericImage } from "@calcom/lib/OgImages";
import { IS_CALCOM, WEBAPP_URL, APP_NAME, SEO_IMG_OGIMG } from "@calcom/lib/constants";
import { getFixedT } from "@calcom/lib/server/getFixedT";

import { preparePageMetadata } from "@lib/metadata";

export const generateMetadata = async () => {
const h = headers();
const canonical = h.get("x-pathname") ?? "";
const locale = h.get("x-locale") ?? "en";

const t = await getFixedT(locale, "common");

const title = t("event_types_page_title");
const description = t("event_types_page_subtitle");

const metadataBase = new URL(IS_CALCOM ? "https://cal.com" : WEBAPP_URL);

const image =
SEO_IMG_OGIMG +
constructGenericImage({
title,
description,
});

return preparePageMetadata({
title,
canonical,
image,
description,
siteName: APP_NAME,
metadataBase,
});
};
export const generateMetadata = async () =>
await _generateMetadata("event_types_page_title", "event_types_page_subtitle");

export default EventTypes;
37 changes: 2 additions & 35 deletions apps/web/app/future/(layout)/insights/page.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,6 @@
import InsightsPage from "@pages/insights";
import { headers } from "next/headers";
import { _generateMetadata } from "app/_utils";

import { constructGenericImage } from "@calcom/lib/OgImages";
import { IS_CALCOM, WEBAPP_URL, APP_NAME, SEO_IMG_OGIMG } from "@calcom/lib/constants";
import { getFixedT } from "@calcom/lib/server/getFixedT";

import { preparePageMetadata } from "@lib/metadata";

export const generateMetadata = async () => {
const h = headers();
const canonical = h.get("x-pathname") ?? "";
const locale = h.get("x-locale") ?? "en";

const t = await getFixedT(locale, "common");

const title = "Insights";
const description = t("insights_subtitle");

const metadataBase = new URL(IS_CALCOM ? "https://cal.com" : WEBAPP_URL);

const image =
SEO_IMG_OGIMG +
constructGenericImage({
title,
description,
});

return preparePageMetadata({
title,
canonical,
image,
description,
siteName: APP_NAME,
metadataBase,
});
};
export const generateMetadata = async () => await _generateMetadata("Insights", "insights_subtitle", true);

export default InsightsPage;
37 changes: 2 additions & 35 deletions apps/web/app/future/(layout)/settings/billing/page.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,6 @@
import BillingPage from "@pages/settings/billing";
import { headers } from "next/headers";
import { _generateMetadata } from "app/_utils";

import { constructGenericImage } from "@calcom/lib/OgImages";
import { IS_CALCOM, WEBAPP_URL, APP_NAME, SEO_IMG_OGIMG } from "@calcom/lib/constants";
import { getFixedT } from "@calcom/lib/server/getFixedT";

import { preparePageMetadata } from "@lib/metadata";

export const generateMetadata = async () => {
const h = headers();
const canonical = h.get("x-pathname") ?? "";
const locale = h.get("x-locale") ?? "en";

const t = await getFixedT(locale, "common");

const title = t("billing");
const description = t("manage_billing_description");

const metadataBase = new URL(IS_CALCOM ? "https://cal.com" : WEBAPP_URL);

const image =
SEO_IMG_OGIMG +
constructGenericImage({
title,
description,
});

return preparePageMetadata({
title,
canonical,
image,
description,
siteName: APP_NAME,
metadataBase,
});
};
export const generateMetadata = async () => await _generateMetadata("billing", "manage_billing_description");

export default BillingPage;
37 changes: 2 additions & 35 deletions apps/web/app/future/(layout)/settings/developer/webhooks/page.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,6 @@
import WebhooksPage from "@pages/settings/developer/webhooks";
import { headers } from "next/headers";
import { _generateMetadata } from "app/_utils";

import { constructGenericImage } from "@calcom/lib/OgImages";
import { IS_CALCOM, WEBAPP_URL, APP_NAME, SEO_IMG_OGIMG } from "@calcom/lib/constants";
import { getFixedT } from "@calcom/lib/server/getFixedT";

import { preparePageMetadata } from "@lib/metadata";

export const generateMetadata = async () => {
const h = headers();
const canonical = h.get("x-pathname") ?? "";
const locale = h.get("x-locale") ?? "en";

const t = await getFixedT(locale, "common");

const title = t("webhooks");
const description = t("add_webhook_description");

const metadataBase = new URL(IS_CALCOM ? "https://cal.com" : WEBAPP_URL);

const image =
SEO_IMG_OGIMG +
constructGenericImage({
title,
description,
});

return preparePageMetadata({
title,
canonical,
image,
description,
siteName: APP_NAME,
metadataBase,
});
};
export const generateMetadata = async () => await _generateMetadata("webhooks", "add_webhook_description");

export default WebhooksPage;
Original file line number Diff line number Diff line change
@@ -1,39 +1,6 @@
import AppearancePage from "@pages/settings/my-account/appearance";
import { headers } from "next/headers";
import { _generateMetadata } from "app/_utils";

import { constructGenericImage } from "@calcom/lib/OgImages";
import { IS_CALCOM, WEBAPP_URL, APP_NAME, SEO_IMG_OGIMG } from "@calcom/lib/constants";
import { getFixedT } from "@calcom/lib/server/getFixedT";

import { preparePageMetadata } from "@lib/metadata";

export const generateMetadata = async () => {
const h = headers();
const canonical = h.get("x-pathname") ?? "";
const locale = h.get("x-locale") ?? "en";

const t = await getFixedT(locale, "common");

const title = t("appearance");
const description = t("appearance_description");

const metadataBase = new URL(IS_CALCOM ? "https://cal.com" : WEBAPP_URL);

const image =
SEO_IMG_OGIMG +
constructGenericImage({
title,
description,
});

return preparePageMetadata({
title,
canonical,
image,
description,
siteName: APP_NAME,
metadataBase,
});
};
export const generateMetadata = async () => await _generateMetadata("appearance", "appearance_description");

export default AppearancePage;
Original file line number Diff line number Diff line change
@@ -1,39 +1,6 @@
import CalendarsPage from "@pages/settings/my-account/calendars";
import { headers } from "next/headers";
import { _generateMetadata } from "app/_utils";

import { constructGenericImage } from "@calcom/lib/OgImages";
import { IS_CALCOM, WEBAPP_URL, APP_NAME, SEO_IMG_OGIMG } from "@calcom/lib/constants";
import { getFixedT } from "@calcom/lib/server/getFixedT";

import { preparePageMetadata } from "@lib/metadata";

export const generateMetadata = async () => {
const h = headers();
const canonical = h.get("x-pathname") ?? "";
const locale = h.get("x-locale") ?? "en";

const t = await getFixedT(locale, "common");

const title = t("calendars");
const description = t("calendars_description");

const metadataBase = new URL(IS_CALCOM ? "https://cal.com" : WEBAPP_URL);

const image =
SEO_IMG_OGIMG +
constructGenericImage({
title,
description,
});

return preparePageMetadata({
title,
canonical,
image,
description,
siteName: APP_NAME,
metadataBase,
});
};
export const generateMetadata = async () => await _generateMetadata("calendars", "calendars_description");

export default CalendarsPage;
Original file line number Diff line number Diff line change
@@ -1,39 +1,7 @@
import ConferencingPage from "@pages/settings/my-account/conferencing";
import { headers } from "next/headers";
import { _generateMetadata } from "app/_utils";

import { constructGenericImage } from "@calcom/lib/OgImages";
import { IS_CALCOM, WEBAPP_URL, APP_NAME, SEO_IMG_OGIMG } from "@calcom/lib/constants";
import { getFixedT } from "@calcom/lib/server/getFixedT";

import { preparePageMetadata } from "@lib/metadata";

export const generateMetadata = async () => {
const h = headers();
const canonical = h.get("x-pathname") ?? "";
const locale = h.get("x-locale") ?? "en";

const t = await getFixedT(locale, "common");

const title = t("conferencing");
const description = t("conferencing_description");

const metadataBase = new URL(IS_CALCOM ? "https://cal.com" : WEBAPP_URL);

const image =
SEO_IMG_OGIMG +
constructGenericImage({
title,
description,
});

return preparePageMetadata({
title,
canonical,
image,
description,
siteName: APP_NAME,
metadataBase,
});
};
export const generateMetadata = async () =>
await _generateMetadata("conferencing", "conferencing_description");

export default ConferencingPage;
Loading
Loading