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

Feat/generate social sharing image #34

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
45 changes: 45 additions & 0 deletions app/opengraph-image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import NextImage from "next/image";
import { ImageResponse } from "next/og";
import config from "./config.mts";

// // Route segment config
export const runtime = "edge";

// Image metadata
export const alt = config.meta.title;
export const size = {
width: 600,
height: 315
};

export const contentType = "image/png";

// Image generation
export default async function Image() {
return new ImageResponse(
(
// ImageResponse JSX element
<div className="flex min-h-[630px] min-w-[1200px] flex-col items-center justify-center bg-slate-900">
<div className="flex w-4/12 flex-col gap-6">
<NextImage
src="./logo.svg"
alt={config.meta.logo}
width={size.width}
height={size.height}
className="self-center"
/>
<div className="max-w-fit self-center text-center">
<p className="mb-4 text-lg">{config.meta.description}</p>
<span className="text-lg text-[#00e6a7]">{config.meta.siteUrl}</span>
</div>
</div>
</div>
),
// ImageResponse options
{
// For convenience, we can re-use the exported opengraph-image
// size config to also set the ImageResponse's width and height.
...size
}
);
}
45 changes: 45 additions & 0 deletions app/twitter-image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import NextImage from "next/image";
import { ImageResponse } from "next/og";
import config from "./config.mts";

// // Route segment config
export const runtime = "edge";

// Image metadata
export const alt = config.meta.title;
export const size = {
width: 600,
height: 315
};

export const contentType = "image/png";

// Image generation
export default async function Image() {
return new ImageResponse(
(
// ImageResponse JSX element
<div className="flex min-h-[630px] min-w-[1200px] flex-col items-center justify-center bg-slate-900">
<div className="flex w-4/12 flex-col gap-6">
<NextImage
src="./logo.svg"
alt={config.meta.logo}
width={size.width}
height={size.height}
className="self-center"
/>
<div className="max-w-fit self-center text-center">
<p className="mb-4 text-lg">{config.meta.description}</p>
<span className="text-lg text-[#00e6a7]">{config.meta.siteUrl}</span>
</div>
</div>
</div>
),
// ImageResponse options
{
// For convenience, we can re-use the exported opengraph-image
// size config to also set the ImageResponse's width and height.
...size
}
);
}