Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds missing JavaScript codeblock in Opengraph Image API reference #50996

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default async function Image() {
}
```

```jsx filename="app/about/opengraph-image.js" switcher
```jsx filename="app/about/opengraph-image.jsx" switcher
import { ImageResponse } from 'next/server'

// Route segment config
Expand Down Expand Up @@ -225,7 +225,7 @@ export default function Image({ params }: { params: { slug: string } }) {
}
```

```jsx filename="app/shop/[slug]/opengraph-image.js" switcher
```jsx filename="app/shop/[slug]/opengraph-image.jsx" switcher
export default function Image({ params }) {
// ...
}
Expand Down Expand Up @@ -262,7 +262,7 @@ export const alt = 'My images alt text'
export default function Image() {}
```

```jsx filename="opengraph-image.js / twitter-image.js" switcher
```jsx filename="opengraph-image.jsx / twitter-image.jsx" switcher
export const alt = 'My images alt text'

export default function Image() {}
Expand All @@ -280,7 +280,7 @@ export const size = { width: 1200, height: 630 }
export default function Image() {}
```

```jsx filename="opengraph-image.js / twitter-image.js" switcher
```jsx filename="opengraph-image.jsx / twitter-image.jsx" switcher
export const size = { width: 1200, height: 630 }

export default function Image() {}
Expand All @@ -299,7 +299,7 @@ export const contentType = 'image/png'
export default function Image() {}
```

```jsx filename="opengraph-image.js / twitter-image.js" switcher
```jsx filename="opengraph-image.jsx / twitter-image.jsx" switcher
export const contentType = 'image/png'

export default function Image() {}
Expand All @@ -326,7 +326,7 @@ export const runtime = 'edge'
export default function Image() {}
```

```jsx filename="app/opengraph-image.js" switcher
```jsx filename="app/opengraph-image.jsx" switcher
export const runtime = 'edge'

export default function Image() {}
Expand Down Expand Up @@ -380,3 +380,43 @@ export default async function Image({ params }: { params: { slug: string } }) {
)
}
```

```jsx filename="app/posts/[slug]/opengraph-image.jsx" switcher
import { ImageResponse } from 'next/server'

export const runtime = 'edge'

export const alt = 'About Acme'
export const size = {
width: 1200,
height: 630,
}
export const contentType = 'image/png'

export default async function Image({ params }) {
const post = await fetch(`https://.../posts/${params.slug}`).then((res) =>
res.json()
)

return new ImageResponse(
(
<div
style={{
fontSize: 48,
background: 'white',
width: '100%',
height: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
{post.title}
</div>
),
{
...size,
}
)
}
```