OpenGraphImage.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { readFile } from "fs/promises";
  2. import { join } from "path";
  3. import { ImageResponse } from "next/og";
  4. import LogoIcon from "./icons/logo";
  5. export type Props = {
  6. title?: string;
  7. };
  8. export default async function OpenGraphImage(
  9. props?: Props,
  10. ): Promise<ImageResponse> {
  11. const { title } = {
  12. ...{
  13. title: process.env.SITE_NAME,
  14. },
  15. ...props,
  16. };
  17. const file = await readFile(join(process.cwd(), "./fonts/Inter-Bold.ttf"));
  18. const font = Uint8Array.from(file).buffer;
  19. return new ImageResponse(
  20. (
  21. <div tw="flex h-full w-full flex-col items-center justify-center bg-black">
  22. <div tw="flex h-[160px] w-[160px] flex-none items-center justify-center rounded-3xl border border-neutral-700">
  23. <LogoIcon fill="white" height="58" width="64" />
  24. </div>
  25. <p tw="mt-12 text-6xl font-bold text-white">{title}</p>
  26. </div>
  27. ),
  28. {
  29. width: 1200,
  30. height: 630,
  31. fonts: [
  32. {
  33. name: "Inter",
  34. data: font,
  35. style: "normal",
  36. weight: 700,
  37. },
  38. ],
  39. },
  40. );
  41. }