From c8fc3e4b0174cccc9b57645ec8c9e3c87d060592 Mon Sep 17 00:00:00 2001
From: EfosaSO <22990506+EfosaSO@users.noreply.github.com>
Date: Mon, 22 Jan 2024 18:15:31 +0000
Subject: [PATCH] feat: Move open graph to the edge
---
app/opengraph-image.tsx | 87 ++++++++++++++++++++++++++++
{app => assets}/opengraph-image.jpg | Bin
config/site.ts | 2 +-
lib/og/utils.ts | 12 ++++
4 files changed, 100 insertions(+), 1 deletion(-)
create mode 100644 app/opengraph-image.tsx
rename {app => assets}/opengraph-image.jpg (100%)
create mode 100644 lib/og/utils.ts
diff --git a/app/opengraph-image.tsx b/app/opengraph-image.tsx
new file mode 100644
index 00000000..07008fe1
--- /dev/null
+++ b/app/opengraph-image.tsx
@@ -0,0 +1,87 @@
+/* eslint-disable @next/next/no-img-element */
+import { ImageResponse } from "next/og";
+
+import { siteConfig } from "@/config/site";
+import { getFonts } from "@/lib/og/utils";
+import { cn } from "@/lib/utils";
+import { buttonVariants } from "@/components/ui/button";
+import { Icons } from "@/components/shared/icons";
+
+// Route segment config
+export const runtime = "edge";
+export const alt = siteConfig.name;
+export const size = {
+ width: 1200,
+ height: 630,
+};
+
+export const contentType = "image/png";
+
+export default async function Image() {
+ const { calSansFontData, interFontData } = await getFonts();
+
+ return new ImageResponse(
+ (
+
+
+
+
+ Introducing on{" "}
+
+
+
+
+
+
+ Budget Better, Gain More Experience Projectx
+
+
+
+ Empower your financial management with AI-driven insights, making
+ tracking and optimizing your finances effortless.
+
+
+
+
+ ),
+ // ImageResponse options
+ {
+ // For convenience, we can re-use the exported icons size metadata
+ // config to also set the ImageResponse's width and height.
+ ...size,
+ fonts: [
+ {
+ name: "Cal Sans",
+ data: calSansFontData,
+ style: "normal",
+ },
+ {
+ name: "Inter",
+ data: interFontData,
+ style: "normal",
+ },
+ ],
+ },
+ );
+}
diff --git a/app/opengraph-image.jpg b/assets/opengraph-image.jpg
similarity index 100%
rename from app/opengraph-image.jpg
rename to assets/opengraph-image.jpg
diff --git a/config/site.ts b/config/site.ts
index 2d7428c7..522f8c75 100644
--- a/config/site.ts
+++ b/config/site.ts
@@ -8,7 +8,7 @@ export const siteConfig: SiteConfig = {
description:
"Projectx revolutionizes real estate listings with AI-driven efficiency. Streamline your workflow with intuitive tools and seamless integrations. Projectx is tailored for the modern real estate professional who values precision, security, and scalability.",
url: site_url,
- ogImage: `${site_url}/og.jpg`,
+ ogImage: `${site_url}/opengraph-image`,
links: {
twitter: "https://twitter.com/codehagen",
github: "https://github.com/meglerhagen",
diff --git a/lib/og/utils.ts b/lib/og/utils.ts
new file mode 100644
index 00000000..08412fa3
--- /dev/null
+++ b/lib/og/utils.ts
@@ -0,0 +1,12 @@
+export async function getFonts() {
+ const calSansBoldFont = fetch(
+ new URL("../../assets/fonts/CalSans-SemiBold.ttf", import.meta.url),
+ ).then((res) => res.arrayBuffer());
+ const interFont = fetch(
+ new URL("../../assets/fonts/Inter-Regular.ttf", import.meta.url),
+ ).then((res) => res.arrayBuffer());
+
+ const calSansFontData = await calSansBoldFont;
+ const interFontData = await interFont;
+ return { calSansFontData, interFontData };
+}