Connect, collaborate, and grow with a community of TypeScript developers
feat(aot): adds og image (#1632)
bautistaaa5c57589e1d59
diff --git a/apps/aot/src/app/events/[year]/[day]/solutions/page.tsx b/apps/aot/src/app/events/[year]/[day]/solutions/page.tsxindex 616967ca..a3ea152e 100644--- a/apps/aot/src/app/events/[year]/[day]/solutions/page.tsx+++ b/apps/aot/src/app/events/[year]/[day]/solutions/page.tsx@@ -1,9 +1,8 @@-import { buildMetaForDefault } from '~/utils/metadata';-import { getChallengeRouteData } from '../getChallengeRouteData';-import { Solutions } from './_components';-import { getAotSlug } from '~/utils/getAotSlug';import { notFound } from 'next/navigation';import { isAfterJanuaryFirst } from '~/utils/aot';+import { getAotSlug } from '~/utils/getAotSlug';+import { buildMetaForEventPage } from '~/utils/metadata';+import { Solutions } from './_components';interface Props {params: {@@ -12,11 +11,10 @@ interface Props {};}-export async function generateMetadata({ params: { year, day } }: Props) {- const { challenge } = await getChallengeRouteData(getAotSlug({ year, day }), null);- return buildMetaForDefault({- title: `Solutions to ${challenge.name} | TypeHero`,- description: challenge.shortDescription,+export async function generateMetadata() {+ return buildMetaForEventPage({+ title: 'Advent of Typescript',+ description: 'Advent of Typescript',});}diff --git a/apps/aot/src/app/events/[year]/page.tsx b/apps/aot/src/app/events/[year]/page.tsxindex 5c3f39ae..dbcb4d75 100644--- a/apps/aot/src/app/events/[year]/page.tsx+++ b/apps/aot/src/app/events/[year]/page.tsx@@ -1,5 +1,6 @@import Link from 'next/link';import { api } from '~/trpc/server';+import { buildMetaForEventPage } from '~/utils/metadata';interface Props {params: {@@ -7,6 +8,12 @@ interface Props {};}+export async function generateMetadata() {+ return buildMetaForEventPage({+ title: 'Advent of Typescript',+ description: 'Advent of Typescript',+ });+}export default async function EventByYearLandingPage({ params: { year } }: Props) {const event = await api.event.getEventChallengesByYear({ year });const daysCompleted = event.trackChallenges.length;diff --git a/apps/aot/src/app/leaderboard/page.tsx b/apps/aot/src/app/leaderboard/page.tsxindex 2366a10d..0593b710 100644--- a/apps/aot/src/app/leaderboard/page.tsx+++ b/apps/aot/src/app/leaderboard/page.tsx@@ -2,7 +2,14 @@ import { getAllFlags } from '~/utils/feature-flag';import AdventDaysRow from './_components/advent-days-row';import OverallLeaderboard from './_components/overall-leaderboard';import { notFound } from 'next/navigation';+import { buildMetaForEventPage } from '~/utils/metadata';+export async function generateMetadata() {+ return buildMetaForEventPage({+ title: 'Advent of Typescript',+ description: 'Advent of Typescript',+ });+}export default async function LeaderboardPage() {const { enableAotPlatform } = await getAllFlags();if (!enableAotPlatform) {diff --git a/apps/aot/src/app/login/page.tsx b/apps/aot/src/app/login/page.tsxindex 6ed75d23..3bb3b725 100644--- a/apps/aot/src/app/login/page.tsx+++ b/apps/aot/src/app/login/page.tsx@@ -1,6 +1,13 @@import Link from 'next/link';import { LoginButton } from './_components/LoginButton';+import { buildMetaForEventPage } from '~/utils/metadata';+export async function generateMetadata() {+ return buildMetaForEventPage({+ title: 'Advent of Typescript',+ description: 'Advent of Typescript',+ });+}export default async function Index({searchParams,}: {diff --git a/apps/aot/src/app/page.tsx b/apps/aot/src/app/page.tsxindex 7791e444..b6f996a4 100644--- a/apps/aot/src/app/page.tsx+++ b/apps/aot/src/app/page.tsx@@ -2,7 +2,14 @@ import Hero from '~/components/landing/Hero';import Partners from '~/components/landing/Partners';import { CountdownTimer } from '~/components/landing/useCountdown';import Snowfall from '../components/landing/Snowfall';+import { buildMetaForEventPage } from '~/utils/metadata';+export async function generateMetadata() {+ return buildMetaForEventPage({+ title: 'Advent of Typescript',+ description: 'Advent of Typescript',+ });+}export default function Home() {return (<div className="-mt-14 grid min-h-screen grid-rows-3 place-content-center place-items-center overflow-hidden bg-gradient-to-b from-transparent to-transparent to-50% dark:from-emerald-400/40">diff --git a/apps/aot/src/utils/metadata.ts b/apps/aot/src/utils/metadata.tsindex b19b315d..fdbe2920 100644--- a/apps/aot/src/utils/metadata.ts+++ b/apps/aot/src/utils/metadata.ts@@ -1,14 +1,13 @@import type { Metadata } from 'next';-import { challengeParam, userParam } from '@repo/og-utils';export const OG_URL =process.env.NODE_ENV !== 'production' ? 'http://localhost:4200' : 'https://og.typehero.dev';-export const tagline = 'Level up and learn TypeScript with interactive exercises';+export const tagline = 'Advent of TypeScript';export const baseMetadata: Metadata = {metadataBase: new URL(OG_URL),title: {- default: 'TypeHero',+ default: 'Advend of TypeScript',template: '%s',},robots: {@@ -17,9 +16,9 @@ export const baseMetadata: Metadata = {},description: tagline,openGraph: {- title: 'TypeHero',+ title: 'Advent of TypeScript',description: tagline,- siteName: 'TypeHero',+ siteName: 'Advent of TypeScript',images: [{url: `${OG_URL}/api/default`,@@ -31,11 +30,11 @@ export const baseMetadata: Metadata = {type: 'website',},twitter: {- title: 'TypeHero',+ title: 'Advent of TypeScript',card: 'summary_large_image',images: [{- url: `${OG_URL}/api/default`,+ url: `${OG_URL}/api/aot-2024`,width: 1920,height: 1080,},@@ -46,85 +45,6 @@ export const baseMetadata: Metadata = {},};-// TODO: infer from ZOD-interface MetaParamsForChallenge {- title: string;- description: string;- username: string;- difficulty: 'BEGINNER' | 'EASY' | 'EVENT' | 'EXTREME' | 'HARD' | 'MEDIUM';- date: string;-}--interface MetaParamsForUser {- title: string;- description: string;- username: string;- avatar: string;- dateSince: string;-}-/** Helper to build opengraph metadata for a user, you should call this in generateMetadata() next function */-export const buildMetaForUser = async ({- title,- description,- username,- dateSince,- avatar,-}: MetaParamsForUser): Promise<Metadata> => {- const params = `${userParam.toSearchString({- username,- avatar,- dateSince,- })}`;-- 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,- description,- username,- difficulty,- date,-}: MetaParamsForChallenge): Promise<Metadata> => {- const params = `${challengeParam.toSearchString({- description,- title,- username,- difficulty,- date,- })}`;-- const ogImageUrl = `${OG_URL}/api/challenge?${params}`;-- return buildMeta({- ogImageUrl,- title,- description,- });-};--/** Helper to build opengraph metadata with defaults, you should call this in generateMetadata() next function */-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,- });-};-export const buildMetaForEventPage = async ({title,description,@@ -133,7 +53,7 @@ export const buildMetaForEventPage = async ({description?: string;}): Promise<Metadata> => {return buildMeta({- ogImageUrl: `${OG_URL}/api/aot-2023`,+ ogImageUrl: `${OG_URL}/api/aot-2024`,title,description,});diff --git a/apps/og-image/app/api/aot-2024/route.tsx b/apps/og-image/app/api/aot-2024/route.tsxnew file mode 100644index 00000000..8f3bfe0b--- /dev/null+++ b/apps/og-image/app/api/aot-2024/route.tsx@@ -0,0 +1,22 @@+import { ImageResponse } from '@vercel/og';++export const runtime = 'edge';++export async function GET() {+ return new ImageResponse(+ (+ <div tw="relative flex flex-col">+ <img+ src="https://utfs.io/f/8G81upehgowlBVbY7JPrNSbxC8KMGVhPpRDmrdWQ7L53ai6s"+ tw="w-full"+ alt="gg"+ />+ <div tw="absolute font-semibold flex-grow h-full text-5xl text-red-600 flex w-full justify-end" />+ </div>+ ),+ {+ width: 1200,+ height: 630,+ },+ );+}diff --git a/apps/og-image/app/page.tsx b/apps/og-image/app/page.tsxindex f34ce890..65b92647 100644--- a/apps/og-image/app/page.tsx+++ b/apps/og-image/app/page.tsx@@ -67,6 +67,10 @@ export default function Page() {<h2>Aot 2023</h2><img alt="aot-2023 metadata" src="/api/aot-2023" /></div>+ <div>+ <h2>Aot 2024</h2>+ <img alt="aot-2024 metadata" src="/api/aot-2024" />+ </div></main></div>);