Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

feat: make challenge OG description renderable and deterministic (#823)

Anthony Morris7d615c452b6b
diff --git a/apps/og-image/app/api/challenge/route.tsx b/apps/og-image/app/api/challenge/route.tsx
index 19e47175..da0164a2 100644
--- a/apps/og-image/app/api/challenge/route.tsx
+++ b/apps/og-image/app/api/challenge/route.tsx
@@ -81,7 +81,7 @@ export async function GET(req: Request) {
tw="text-7xl font-bold truncate pr-48 -mt-2 overflow-ellipsis"
style={{ fontWeight: '800 !important' }}
>
- {props.title === null ? null : props.title.split(" | ")[0]}
+ {props.title === null ? null : props.title.split(' | ')[0]}
</h1>
<p tw="flex items-center -mt-3">
<p
diff --git a/apps/og-image/utils/zodParams.ts b/apps/og-image/utils/zodParams.ts
index ca6d9e69..2bb7784e 100644
--- a/apps/og-image/utils/zodParams.ts
+++ b/apps/og-image/utils/zodParams.ts
@@ -1,7 +1,7 @@
import { z } from 'zod';
-type Primitives = string | number | boolean | null;
-type JsonValue = Primitives | JsonValue[] | { [key: string]: JsonValue };
+type Primitives = boolean | number | string | null;
+type JsonValue = JsonValue[] | Primitives | { [key: string]: JsonValue };
const jsonStr = z.string().transform((str, ctx) => {
try {
@@ -36,7 +36,7 @@ function truncateWordsFn(str: string, maxCharacters: number) {
// break at closest word
const truncated = str.slice(0, maxCharacters);
const lastSpace = truncated.lastIndexOf(' ');
- return truncated.slice(0, lastSpace) + ' …';
+ return `${truncated.slice(0, lastSpace)} …`;
}
function truncatedWordSchema(opts: { maxCharacters: number }) {
return z.string().transform((str) => truncateWordsFn(str, opts.maxCharacters));
diff --git a/apps/web/src/app/[locale]/challenge/[id]/page.tsx b/apps/web/src/app/[locale]/challenge/[id]/page.tsx
index b5f39b06..3a8fa593 100644
--- a/apps/web/src/app/[locale]/challenge/[id]/page.tsx
+++ b/apps/web/src/app/[locale]/challenge/[id]/page.tsx
@@ -13,9 +13,11 @@ interface Props {
export async function generateMetadata({ params: { id } }: Props) {
const challenge = await getChallengeRouteData(id, null);
+ const description = `Unlock your TypeScript potential by solving the ${challenge.name} challenge on TypeHero.`;
+
return buildMetaForChallenge({
title: `${challenge.name} | TypeHero`,
- description: `${challenge.shortDescription}`,
+ description,
username: challenge.user.name,
difficulty: challenge.difficulty,
date: getRelativeTime(challenge.createdAt),