Skip to content

πŸ“ˆ Open source, privacy-first web analytics β€” a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

feat: Opengraph image cards support

Blue Mouse54c86cd042e4
diff --git a/docs/app/[[...slug]]/page.tsx b/docs/app/[[...slug]]/page.tsx
index 8bf0d8fc5..0c9f98b50 100644
--- a/docs/app/[[...slug]]/page.tsx
+++ b/docs/app/[[...slug]]/page.tsx
@@ -52,8 +52,25 @@ export async function generateMetadata(props: { params: Promise<{ slug?: string[
const page = source.getPage(params.slug);
if (!page) notFound();
+ const ogParams = new URLSearchParams({ title: page.data.title, label: "Docs" });
+ if (page.data.description) {
+ ogParams.set("description", page.data.description);
+ }
+ const ogImageUrl = `https://swetrix.com/api/og-image.png?${ogParams.toString()}`;
+
return {
title: page.data.title,
description: page.data.description,
+ openGraph: {
+ title: page.data.title,
+ description: page.data.description,
+ images: [{ url: ogImageUrl, width: 1800, height: 945, alt: page.data.title }],
+ },
+ twitter: {
+ card: "summary_large_image",
+ title: page.data.title,
+ description: page.data.description,
+ images: [ogImageUrl],
+ },
};
}
diff --git a/docs/app/layout.tsx b/docs/app/layout.tsx
index 69cf504d5..ba565d94a 100644
--- a/docs/app/layout.tsx
+++ b/docs/app/layout.tsx
@@ -7,6 +7,9 @@ import Footer from "./components/Footer";
import Analytics from "./components/Analytics";
import "./global.css";
+const defaultOgImage =
+ "https://swetrix.com/api/og-image.png?title=Swetrix+Docs&description=Open-source%2C+privacy-first+web+analytics+documentation&label=Docs";
+
export const metadata = {
title: {
template: "%s | Swetrix Docs",
@@ -14,6 +17,17 @@ export const metadata = {
},
description: "Swetrix documentation β€” turn traffic into insights.",
icons: { icon: "/favicon.ico" },
+ openGraph: {
+ title: "Swetrix Docs",
+ description: "Swetrix documentation β€” turn traffic into insights.",
+ images: [{ url: defaultOgImage, width: 1800, height: 945, alt: "Swetrix Docs" }],
+ },
+ twitter: {
+ card: "summary_large_image" as const,
+ title: "Swetrix Docs",
+ description: "Swetrix documentation β€” turn traffic into insights.",
+ images: [defaultOgImage],
+ },
};
export default function RootLayout({ children }: { children: ReactNode }) {