Connect, collaborate, and grow with a community of TypeScript developers
feat: new design for OG user image (#1068)
Dunsinfd70d6c88a83
diff --git a/apps/og-image/app/api/user/route.tsx b/apps/og-image/app/api/user/route.tsxindex e70a64d9..a63e778b 100644--- a/apps/og-image/app/api/user/route.tsx+++ b/apps/og-image/app/api/user/route.tsx@@ -3,7 +3,6 @@ import { userParam } from 'utils/zodParams';import { fetchFont } from 'utils/fetchFont';import { Grid } from 'app/components/grid';import { Logo } from 'app/components/logo';-import Image from 'next/image';export const runtime = 'edge';@@ -21,21 +20,24 @@ export async function GET(req: Request) {}const props = parsed.data.input;+ console.log({props})return new ImageResponse((<div tw="bg-black h-full w-full text-white bg-cover flex flex-col px-14 py-10"><Grid />- <div tw="flex flex-col text-center h-full w-full gap-4 justify-between">- <div tw="flex justify-between">+ <div tw="flex flex text-center h-full w-full gap-4 justify-between">+ <div tw="flex items-center">{props.avatar ? (- <img src={props.avatar} tw="object-cover h-36 w-36 rounded-full" />+ <img src={props.avatar} tw="object-cover h-68 w-68 rounded-full" />) : null}- <Logo />+ <div tw='flex flex-col ml-10'>+ <h1 tw="text-8xl font-bold">{props.username}</h1>+ <p tw='text-4xl -mt-6 font-medium'>Member Since: {props.dateSince}</p>+ </div></div>- <div tw="flex flex-col text-left">- <h1 tw="text-6xl font-bold">{props.username}</h1>- {props.bio ? <p tw="text-4xl text-zinc-300">{props.bio}</p> : null}+ <div tw="flex relative right-0">+ <Logo /></div></div></div>diff --git a/apps/og-image/app/page.tsx b/apps/og-image/app/page.tsxindex d30c599e..9b741c09 100644--- a/apps/og-image/app/page.tsx+++ b/apps/og-image/app/page.tsx@@ -52,8 +52,8 @@ export default function Page() {alt="ayo"src={`/api/user?${userParam.toSearchString({username: 'Hacksore',- bio: 'This is a test card that has a has a nice description lorem40 ipsum dolor sit amet, consectetur adipiscing elit. lorem more text here s aothesntohks anatoh esn uthsanotedhusn hwanoejt hsaont hesnathdoneitsdhsas asnoehusnatohesunthaoenst',avatar: 'https://avatars.githubusercontent.com/u/32938743?v=4',+ dateSince: '2 days ago'})}&random=${nonce}`}/></div>diff --git a/apps/og-image/utils/zodParams.ts b/apps/og-image/utils/zodParams.tsindex 792d1dd3..ece0e964 100644--- a/apps/og-image/utils/zodParams.ts+++ b/apps/og-image/utils/zodParams.ts@@ -63,7 +63,7 @@ export const challengeParam = zodParams(export const userParam = zodParams(z.object({username: truncatedWordSchema({ maxCharacters: 70 }),- bio: truncatedWordSchema({ maxCharacters: 145 }).optional(),avatar: z.string().optional(),+ dateSince: z.string()}),);diff --git a/apps/web/src/app/[locale]/[username]/page.tsx b/apps/web/src/app/[locale]/[username]/page.tsxindex b9d0f890..550dbaf6 100644--- a/apps/web/src/app/[locale]/[username]/page.tsx+++ b/apps/web/src/app/[locale]/[username]/page.tsx@@ -2,6 +2,7 @@ import { buildMetaForDefault, buildMetaForUser } from '~/app/metadata';import { prisma } from '@repo/db';import { OverviewTab } from './_components/dashboard/overview-tab';import { notFound } from 'next/navigation';+import { getRelativeTime } from '~/utils/relativeTime';interface Props {params: {@@ -54,16 +55,17 @@ export async function generateMetadata({ params: { username: usernameFromQuery }},});- const bio = user ? user.bio : '';const avatar = user && user.image ? user.image : '';+ const date = user?.createdAt!;+ const dateSince = getRelativeTime(date);if (username)return buildMetaForUser({username,title: `${username}'s profile | TypeHero`,description: `View the profile of ${username} on TypeHero.`,- bio,avatar,+ dateSince,});return buildMetaForDefault({title: 'Profile | TypeHero',diff --git a/apps/web/src/app/metadata.ts b/apps/web/src/app/metadata.tsindex ff04a610..fcdca39b 100644--- a/apps/web/src/app/metadata.ts+++ b/apps/web/src/app/metadata.ts@@ -59,21 +59,21 @@ interface MetaParamsForUser {title: string;description: string;username: string;- bio: 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,- bio,+ dateSince,avatar,}: MetaParamsForUser): Promise<Metadata> => {const params = `${userParam.toSearchString({username,- bio,avatar,+ dateSince,})}`;const ogImageUrl = `${OG_URL}/api/user?${params}`;