Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions apps/web/app/api/og/fonts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { readFile } from "fs/promises"
import { join } from "path"

/**
* Loads Geist Mono font files for OG image generation.
*
* Font files are vendored into `public/fonts/` so they can be read via
* `process.cwd()` on Vercel (same pattern used by `public/icon.svg`).
*
* We can't read from `node_modules/geist/...` because in a monorepo
* dependencies are hoisted to the workspace root while `process.cwd()`
* points to the app directory (e.g. `apps/web`).
*/
const fontsDir = join(process.cwd(), "public", "fonts")

export const geistMonoRegular = readFile(
join(fontsDir, "GeistMono-Regular.ttf")
)
export const geistMonoBold = readFile(join(fontsDir, "GeistMono-Bold.ttf"))
13 changes: 1 addition & 12 deletions apps/web/app/api/og/home/route.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
import { readFile } from "fs/promises"
import { ImageResponse } from "next/og"
import { join } from "path"
import { geistMonoBold, geistMonoRegular } from "@/app/api/og/fonts"

const size = {
width: 1200,
height: 630,
}

const geistMonoRegular = readFile(
join(
process.cwd(),
"node_modules/geist/dist/fonts/geist-mono/GeistMono-Regular.ttf"
)
)
const geistMonoBold = readFile(
join(
process.cwd(),
"node_modules/geist/dist/fonts/geist-mono/GeistMono-Bold.ttf"
)
)
const iconSvg = readFile(join(process.cwd(), "public/icon.svg"), "utf-8")

export async function GET() {
Expand Down
16 changes: 1 addition & 15 deletions apps/web/app/api/og/post/route.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { and, eq } from "drizzle-orm"
import { readFile } from "fs/promises"
import { ImageResponse } from "next/og"
import type { NextRequest } from "next/server"
import { join } from "path"
import { geistMonoBold, geistMonoRegular } from "@/app/api/og/fonts"
import { getRootCommentText } from "@/lib/data/posts"
import { db } from "@/lib/db/client"
import { posts } from "@/lib/db/schema"
Expand All @@ -13,19 +12,6 @@ const size = {
height: 630,
}

const geistMonoRegular = readFile(
join(
process.cwd(),
"node_modules/geist/dist/fonts/geist-mono/GeistMono-Regular.ttf"
)
)
const geistMonoBold = readFile(
join(
process.cwd(),
"node_modules/geist/dist/fonts/geist-mono/GeistMono-Bold.ttf"
)
)

export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams
const owner = searchParams.get("owner")
Expand Down
16 changes: 1 addition & 15 deletions apps/web/app/api/og/repo/route.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { and, eq, sql } from "drizzle-orm"
import { readFile } from "fs/promises"
import { ImageResponse } from "next/og"
import type { NextRequest } from "next/server"
import { join } from "path"
import { geistMonoBold, geistMonoRegular } from "@/app/api/og/fonts"
import { db } from "@/lib/db/client"
import { posts } from "@/lib/db/schema"
import { githubFetch } from "@/lib/github-fetch"
Expand All @@ -13,19 +12,6 @@ const size = {
height: 630,
}

const geistMonoRegular = readFile(
join(
process.cwd(),
"node_modules/geist/dist/fonts/geist-mono/GeistMono-Regular.ttf"
)
)
const geistMonoBold = readFile(
join(
process.cwd(),
"node_modules/geist/dist/fonts/geist-mono/GeistMono-Bold.ttf"
)
)

interface GitHubRepoData {
description: string | null
[key: string]: unknown
Expand Down
16 changes: 1 addition & 15 deletions apps/web/app/api/og/user/route.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { eq, sql } from "drizzle-orm"
import { readFile } from "fs/promises"
import { ImageResponse } from "next/og"
import type { NextRequest } from "next/server"
import { join } from "path"
import { geistMonoBold, geistMonoRegular } from "@/app/api/og/fonts"
import { gitHubUserLoader } from "@/lib/auth"
import { db } from "@/lib/db/client"
import { comments } from "@/lib/db/schema"
Expand All @@ -13,19 +12,6 @@ const size = {
height: 630,
}

const geistMonoRegular = readFile(
join(
process.cwd(),
"node_modules/geist/dist/fonts/geist-mono/GeistMono-Regular.ttf"
)
)
const geistMonoBold = readFile(
join(
process.cwd(),
"node_modules/geist/dist/fonts/geist-mono/GeistMono-Bold.ttf"
)
)

export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams
const username = searchParams.get("username")
Expand Down
Binary file added apps/web/public/fonts/GeistMono-Bold.ttf
Binary file not shown.
Binary file added apps/web/public/fonts/GeistMono-Regular.ttf
Binary file not shown.