Skip to content

Commit

Permalink
update to follow layouts refactor for card/font
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane98c committed Jan 9, 2025
1 parent b9c275a commit 9e66bb0
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions pages/api/og.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import React from 'react'
import { ImageResponse } from 'next/og'
import { BlogPostOG, getBlogPostFonts } from '@carbonplan/layouts'
import { getBlogPostCard } from '@carbonplan/layouts'
import { postMetadata } from '../../utils/post-metadata'

export const runtime = 'edge'

export default async function handler(req) {
try {
const fonts = await getBlogPostFonts()
const { searchParams } = new URL(req.url)
const id = searchParams.get('id')

Expand All @@ -26,21 +24,17 @@ export default async function handler(req) {
)
const forceWrapAuthors = searchParams.get('forceWrapAuthors') === 'true'

return new ImageResponse(
(
<BlogPostOG
title={title}
date={date}
authors={authors}
forceWrapAuthors={forceWrapAuthors}
/>
),
{
width: 1200,
height: 630,
fonts,
}
)
const { component, fonts, options } = await getBlogPostCard({
title,
date,
authors,
forceWrapAuthors,
})

return new ImageResponse(component, {
...options,
fonts,
})
} catch (error) {
console.log(`${error.message}`)
return new Response('Failed to generate the image', {
Expand Down

0 comments on commit 9e66bb0

Please sign in to comment.