Connect, collaborate, and grow with a community of TypeScript developers
Refactor meta (#730)
Sean Boultaeac7102f189
diff --git a/apps/web/src/app/[locale]/(email)/waitlist/page.tsx b/apps/web/src/app/[locale]/(email)/waitlist/page.tsxindex 0324300b..3777eeff 100644--- a/apps/web/src/app/[locale]/(email)/waitlist/page.tsx+++ b/apps/web/src/app/[locale]/(email)/waitlist/page.tsx@@ -1,8 +1,10 @@import type { Metadata } from 'next';+import { buildMetaForDefault } from '~/app/metadata';-export const metadata: Metadata = {- title: 'Waitlist | TypeHero',- description: 'Join the waitlist for TypeHero and be the first to know when we launch!',-};-+export async function generateMetadata(): Promise<Metadata> {+ return buildMetaForDefault({+ title: 'Waitlist | TypeHero',+ description: 'Join the waitlist for TypeHero and be the first to know when we launch!',+ });+}export { Waitlist as default } from './_components';diff --git a/apps/web/src/app/[locale]/(legal)/privacy/page.tsx b/apps/web/src/app/[locale]/(legal)/privacy/page.tsxindex b174ba8c..8944ef99 100644--- a/apps/web/src/app/[locale]/(legal)/privacy/page.tsx+++ b/apps/web/src/app/[locale]/(legal)/privacy/page.tsx@@ -1,10 +1,13 @@import type { Metadata } from 'next';+import { buildMetaForDefault } from '~/app/metadata';import { Footsies } from '~/components/footsies';-export const metadata: Metadata = {- title: 'Privacy | TypeHero',- description: 'Read the TypeHero Privacy Policy.',-};+export async function generateMetadata(): Promise<Metadata> {+ return buildMetaForDefault({+ title: 'Privacy | TypeHero',+ description: 'Read the TypeHero Privacy Policy.',+ });+}export default function Page() {return (diff --git a/apps/web/src/app/[locale]/(legal)/tos/page.tsx b/apps/web/src/app/[locale]/(legal)/tos/page.tsxindex 66314510..5e76c1a7 100644--- a/apps/web/src/app/[locale]/(legal)/tos/page.tsx+++ b/apps/web/src/app/[locale]/(legal)/tos/page.tsx@@ -1,10 +1,13 @@import type { Metadata } from 'next';+import { buildMetaForDefault } from '~/app/metadata';import { Footsies } from '~/components/footsies';-export const metadata: Metadata = {- title: 'ToS | TypeHero',- description: 'Read the TypeHero Terms of Service.',-};+export async function generateMetadata(): Promise<Metadata> {+ return buildMetaForDefault({+ title: 'ToS | TypeHero',+ description: 'Read the TypeHero Terms of Service.',+ });+}export default function Page() {return (diff --git a/apps/web/src/app/[locale]/[username]/page.tsx b/apps/web/src/app/[locale]/[username]/page.tsxindex c0e7a2d3..2183dff9 100644--- a/apps/web/src/app/[locale]/[username]/page.tsx+++ b/apps/web/src/app/[locale]/[username]/page.tsx@@ -1,3 +1,4 @@+import { buildMetaForUser } from '~/app/metadata';import { Profile } from './_components/profile';interface Props {@@ -13,8 +14,9 @@ export default function Page({ params }: Props) {export async function generateMetadata({ params: { username } }: Props) {const name = decodeURIComponent(username).substring(1);- return {+ return buildMetaForUser({+ username: name,title: `${name}'s profile | TypeHero`,description: `View the profile of ${name} on TypeHero.`,- };+ });}diff --git a/apps/web/src/app/[locale]/explore/page.tsx b/apps/web/src/app/[locale]/explore/page.tsxindex db1f3a08..a3548d17 100644--- a/apps/web/src/app/[locale]/explore/page.tsx+++ b/apps/web/src/app/[locale]/explore/page.tsx@@ -1,11 +1,14 @@import type { Metadata } from 'next';+import { buildMetaForDefault } from '~/app/metadata';// CI fails without thisexport const dynamic = 'force-dynamic';-export const metadata: Metadata = {- title: 'Explore Challenges | TypeHero',- description: 'Explore all challenges by difficulty or tags on TypeHero.',-};+export async function generateMetadata(): Promise<Metadata> {+ return buildMetaForDefault({+ title: 'Explore Challenges | TypeHero',+ description: 'Explore all challenges by difficulty or tags on TypeHero.',+ });+}export { Explore as default } from './_components';diff --git a/apps/web/src/app/[locale]/page.tsx b/apps/web/src/app/[locale]/page.tsxindex f3f89e8d..67cde80e 100644--- a/apps/web/src/app/[locale]/page.tsx+++ b/apps/web/src/app/[locale]/page.tsx@@ -6,12 +6,11 @@ import { Hero } from './_components/hero';import { WaitlistBanner } from './_components/waitlist-banner';import { getStaticParams } from '~/locales/server';import { setStaticParamsLocale } from 'next-international/server';+import { buildMetaForDefault } from '../metadata';-export const metadata: Metadata = {- title: 'TypeHero',- description:- 'Connect, collaborate, and grow with a community of TypeScript developers. Elevate your skills through interactive coding challenges, discussions, and knowledge sharing',-};+export async function generateMetadata(): Promise<Metadata> {+ return buildMetaForDefault({});+}export function generateStaticParams() {return getStaticParams();diff --git a/apps/web/src/app/[locale]/settings/page.tsx b/apps/web/src/app/[locale]/settings/page.tsxindex ca9c9540..77175bac 100644--- a/apps/web/src/app/[locale]/settings/page.tsx+++ b/apps/web/src/app/[locale]/settings/page.tsx@@ -2,11 +2,14 @@ import { getServerAuthSession } from '@repo/auth/server';import { prisma } from '@repo/db';import type { Metadata } from 'next';import { NewSettings } from './_components/new-settings';+import { buildMetaForDefault } from '~/app/metadata';-export const metadata: Metadata = {- title: 'Settings | TypeHero',- description: 'Change your settings on TypeHero.',-};+export async function generateMetadata(): Promise<Metadata> {+ return buildMetaForDefault({+ title: 'Settings | TypeHero',+ description: 'Change your settings on TypeHero.',+ });+}export default async function SettingsPage() {const session = await getServerAuthSession();diff --git a/apps/web/src/app/[locale]/tracks/page.tsx b/apps/web/src/app/[locale]/tracks/page.tsxindex 0f4cad40..f9093b48 100644--- a/apps/web/src/app/[locale]/tracks/page.tsx+++ b/apps/web/src/app/[locale]/tracks/page.tsx@@ -1,9 +1,10 @@import type { Metadata } from 'next';+import { buildMetaForDefault } from '~/app/metadata';-export { Tracks as default } from './_components';+export async function generateMetadata(): Promise<Metadata> {+ return buildMetaForDefault({+ title: 'Explore Tracks | TypeHero',+ });+}-export const metadata: Metadata = {- title: 'Explore Tracks | TypeHero',- description:- 'Explore the learning tracks that TypeHero has to offer, find one you like, and get started on learning!',-};+export { Tracks as default } from './_components';diff --git a/apps/web/src/app/[locale]/wizard/page.tsx b/apps/web/src/app/[locale]/wizard/page.tsxindex 92bd5e45..c3f0069c 100644--- a/apps/web/src/app/[locale]/wizard/page.tsx+++ b/apps/web/src/app/[locale]/wizard/page.tsx@@ -2,6 +2,14 @@ import { getServerAuthSession } from '@repo/auth/server';import { TypographyH2 } from '@repo/ui/components/typography/h2';import type { Metadata } from 'next';import { Wizard } from './_components';+import { buildMetaForDefault } from '~/app/metadata';++export async function generateMetadata(): Promise<Metadata> {+ return buildMetaForDefault({+ title: 'Create a Challenge | TypeHero',+ description: 'Create a challenge on TypeHero and share it with the world!',+ });+}export default async function Page() {const session = await getServerAuthSession();@@ -16,8 +24,3 @@ export default async function Page() {return <Wizard />;}--export const metadata: Metadata = {- title: 'Create a Challenge | TypeHero',- description: 'Create a challenge on TypeHero and share it with the world!',-};diff --git a/apps/web/src/app/layout.tsx b/apps/web/src/app/layout.tsxindex 4aff9bf2..dd89a5e9 100644--- a/apps/web/src/app/layout.tsx+++ b/apps/web/src/app/layout.tsx@@ -12,7 +12,7 @@ import { Navigation } from '~/components/navigation';const inter = Inter({ subsets: ['latin'] });export async function generateMetadata(): Promise<Metadata> {- return buildMetaForDefault();+ return buildMetaForDefault({});}export default function RootLayout({ children }: { children: React.ReactNode }) {diff --git a/apps/web/src/app/metadata.ts b/apps/web/src/app/metadata.tsindex 0d957676..0eccf1b4 100644--- a/apps/web/src/app/metadata.ts+++ b/apps/web/src/app/metadata.ts@@ -1,5 +1,5 @@import type { Metadata } from 'next';-import { challengeParam } from '@repo/og-image';+import { challengeParam, userParam } from '@repo/og-image';const OG_URL =process.env.NODE_ENV !== 'production' ? 'http://localhost:4200' : 'https://og.typehero.dev';@@ -52,6 +52,25 @@ interface MetaParamsForChallenge {username: string;}+/** Helper to build opengraph metadata for a user, you should call this in generateMetadata() next function */+export const buildMetaForUser = async ({+ title,+ description,+ username,+}: MetaParamsForChallenge): Promise<Metadata> => {+ const params = `${userParam.toSearchString({+ username,+ })}`;++ const ogImageUrl = `${OG_URL}/api/user?${params}`;++ return buildMeta({+ ogImageUrl,+ title,+ description,+ });+};+/** Helper to build opengraph metadata for a challenge, you should call this in generateMetadata() next function */export const buildMetaForChallenge = async ({title,@@ -74,9 +93,17 @@ export const buildMetaForChallenge = async ({};/** Helper to build opengraph metadata with defaults, you should call this in generateMetadata() next function */-export const buildMetaForDefault = async (): Promise<Metadata> => {+export const buildMetaForDefault = async ({+ title,+ description,+}: {+ title?: string;+ description?: string;+}): Promise<Metadata> => {return buildMeta({ogImageUrl: `${OG_URL}/api/default?cache-bust=${new Date().getDate()}`,+ title,+ description,});};