Skip to content

armgit / pdfcn

Public Imported from GitHub
0

Beautiful pdf components, built on Takumi and Forme. 100% Free, Zero config, one command setup.

refactor: remove Open Graph image generation routes and update metadata handling to use static image

Aniket-5088a3c2992ea9f
diff --git a/.github/assets/gh.png b/.github/assets/gh.png
new file mode 100644
index 0000000..226a246
Binary files /dev/null and b/.github/assets/gh.png differ
diff --git a/README.md b/README.md
index b4d2662..f94a31d 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
<p align="center">
- <img src="https://pdfcn.vercel.app/og" alt="pdfcn banner" />
+ <img src="./.github/assets/gh.png" alt="pdfcn banner" />
</p>
<h1 align="center">pdfcn</h1>
diff --git a/app/(app)/docs/[[...slug]]/page.tsx b/app/(app)/docs/[[...slug]]/page.tsx
index 755cdcb..448a2cf 100644
--- a/app/(app)/docs/[[...slug]]/page.tsx
+++ b/app/(app)/docs/[[...slug]]/page.tsx
@@ -17,7 +17,7 @@ import { PageTransition } from "@/components/page-transition";
import { Badge } from "@/components/ui/badge";
import { ROUTES } from "@/constants/routes";
import { formatTitleFromSlug } from "@/lib/docs";
-import { getPageImage, getPageMarkdownUrl, source } from "@/lib/source";
+import { getPageMarkdownUrl, source } from "@/lib/source";
import { absoluteUrl } from "@/lib/utils";
import { mdxComponents } from "@/mdx-components";
import { BreadcrumbJsonLd } from "@/seo/json-ld";
@@ -41,11 +41,9 @@ export const generateMetadata = async (props: {
}
const doc = page.data;
- const ogImage = getPageImage(page).url;
return createPageMetadata({
description: doc.description,
- ogImage,
ogType: "article",
path: page.url,
title: doc.title,
diff --git a/app/og/docs/[...slug]/route.tsx b/app/og/docs/[...slug]/route.tsx
deleted file mode 100644
index 53d8410..0000000
--- a/app/og/docs/[...slug]/route.tsx
+++ /dev/null
@@ -1,64 +0,0 @@
-import { notFound } from "next/navigation";
-import { ImageResponse } from "next/og";
-
-import { LogoMark } from "@/components/logo";
-import { getPageImage, source } from "@/lib/source";
-
-export const revalidate = false;
-
-export const GET = async (
- _req: Request,
- { params }: { params: Promise<{ slug: string[] }> }
-) => {
- const { slug } = await params;
- const page = source.getPage(slug.slice(0, -1));
- if (!page) {
- notFound();
- }
-
- const { title, description } = page.data;
-
- return new ImageResponse(
- <div tw="flex h-full w-full bg-black text-white">
- <div tw="flex border absolute border-stone-700 border-dashed inset-y-0 left-16 w-[1px]" />
- <div tw="flex border absolute border-stone-700 border-dashed inset-y-0 right-16 w-[1px]" />
- <div tw="flex border absolute border-stone-700 inset-x-0 h-[1px] top-16" />
- <div tw="flex border absolute border-stone-700 inset-x-0 h-[1px] bottom-16" />
- <div tw="flex absolute flex-row bottom-24 right-24 text-white">
- <LogoMark width={48} height={48} />
- </div>
- <div tw="flex flex-col absolute w-[896px] justify-center inset-32">
- <div
- tw="tracking-tight flex-grow-1 flex flex-col justify-center leading-[1.1]"
- style={{
- fontSize: title && title.length > 20 ? 64 : 80,
- fontWeight: 600,
- letterSpacing: "-0.04em",
- textWrap: "balance",
- }}
- >
- {title}
- </div>
- <div
- tw="text-[40px] leading-[1.5] flex-grow-1 text-stone-400"
- style={{
- fontWeight: 500,
- textWrap: "balance",
- }}
- >
- {description}
- </div>
- </div>
- </div>,
- {
- height: 630,
- width: 1200,
- }
- );
-};
-
-export const generateStaticParams = () =>
- source.getPages().map((page) => ({
- lang: page.locale,
- slug: getPageImage(page).segments,
- }));
diff --git a/app/og/route.tsx b/app/og/route.tsx
deleted file mode 100644
index dc91510..0000000
--- a/app/og/route.tsx
+++ /dev/null
@@ -1,48 +0,0 @@
-import { ImageResponse } from "next/og";
-
-import { LogoMark } from "@/components/logo";
-import { SITE } from "@/constants/site";
-
-export const GET = (request: Request) => {
- const { searchParams } = new URL(request.url);
- const title = searchParams.get("title") || SITE.NAME;
- const description = searchParams.get("description") || SITE.DESCRIPTION.LONG;
-
- return new ImageResponse(
- <div tw="flex h-full w-full bg-black text-white">
- <div tw="flex border absolute border-stone-700 border-dashed inset-y-0 left-16 w-[1px]" />
- <div tw="flex border absolute border-stone-700 border-dashed inset-y-0 right-16 w-[1px]" />
- <div tw="flex border absolute border-stone-700 inset-x-0 h-[1px] top-16" />
- <div tw="flex border absolute border-stone-700 inset-x-0 h-[1px] bottom-16" />
- <div tw="flex absolute flex-row bottom-24 right-24 text-white">
- <LogoMark width={48} height={48} />
- </div>
- <div tw="flex flex-col absolute w-[896px] justify-center inset-32">
- <div
- tw="tracking-tight flex-grow-1 flex flex-col justify-center leading-[1.1]"
- style={{
- fontSize: title && title.length > 20 ? 64 : 80,
- fontWeight: 600,
- letterSpacing: "-0.04em",
- textWrap: "balance",
- }}
- >
- {title}
- </div>
- <div
- tw="text-[40px] leading-[1.5] flex-grow-1 text-stone-400"
- style={{
- fontWeight: 500,
- textWrap: "balance",
- }}
- >
- {description}
- </div>
- </div>
- </div>,
- {
- height: 630,
- width: 1200,
- }
- );
-};
diff --git a/constants/routes.ts b/constants/routes.ts
index c660204..398e150 100644
--- a/constants/routes.ts
+++ b/constants/routes.ts
@@ -18,7 +18,6 @@ export const ROUTES = {
LLMS_MD: "/llms.md",
MANIFEST: "/manifest.webmanifest",
MCP: "/mcp",
- OG: "/og",
OPENAPI: "/openapi.json",
REGISTRY: "/r/registry.json",
ROBOTS: "/robots.txt",
diff --git a/constants/site.ts b/constants/site.ts
index dfbd86e..4d8cac4 100644
--- a/constants/site.ts
+++ b/constants/site.ts
@@ -1,5 +1,3 @@
-import { ROUTES } from "@/constants/routes";
-
export const FALLBACK_SITE_ORIGIN = "https://pdfcn.dev" as const;
const getBaseUrl = () => {
@@ -35,7 +33,7 @@ export const SITE = {
"npx shadcn add",
] as const,
NAME: "pdfcn",
- OG_IMAGE: `${baseUrl}${ROUTES.OG}`,
+ OG_IMAGE: `${baseUrl}/og.png`,
REGISTRY: "@pdfcn",
URL: baseUrl,
};
diff --git a/lib/docs.ts b/lib/docs.ts
index 0a3279c..d267a91 100644
--- a/lib/docs.ts
+++ b/lib/docs.ts
@@ -49,6 +49,5 @@ export const formatTitleFromSlug = (slug: string): string =>
export const homeContentRoute = `${ROUTES.LLMS_MD}/content.md`;
export const docsContentRoute = `${ROUTES.LLMS_MD}${ROUTES.DOCS}`;
-export const docsImageRoute = `${ROUTES.OG}${ROUTES.DOCS}`;
export const PAGES_NEW: string[] = [ROUTES.DOCS_CHANGELOG];
diff --git a/lib/source.ts b/lib/source.ts
index c9e8bb5..447b70a 100644
--- a/lib/source.ts
+++ b/lib/source.ts
@@ -4,22 +4,13 @@ import { loader } from "fumadocs-core/source";
import { docs } from "@/.source/server";
import { ROUTES } from "@/constants/routes";
import { AGENT_DOCS_DIRECTIVE_MARKDOWN } from "@/lib/agent-discovery/directive";
-import { docsContentRoute, docsImageRoute } from "@/lib/docs";
+import { docsContentRoute } from "@/lib/docs";
export const source = loader({
baseUrl: ROUTES.DOCS,
source: docs.toFumadocsSource(),
});
-export const getPageImage = (page: InferPageType<typeof source>) => {
- const segments = [...page.slugs, "image.png"];
-
- return {
- segments,
- url: `${docsImageRoute}/${segments.join("/")}`,
- };
-};
-
export const getPageMarkdownUrl = (page: InferPageType<typeof source>) => {
const segments = [...page.slugs, "content.md"];
diff --git a/public/og.png b/public/og.png
new file mode 100644
index 0000000..1ed8c38
Binary files /dev/null and b/public/og.png differ
diff --git a/seo/metadata.ts b/seo/metadata.ts
index 2d1dea4..ddda986 100644
--- a/seo/metadata.ts
+++ b/seo/metadata.ts
@@ -34,8 +34,7 @@ export const createPageMetadata = ({
canonical === ROUTES.DOCS || canonical.startsWith(`${ROUTES.DOCS}/`)
? `${canonical}.md`
: undefined;
- const resolvedOgImage =
- ogImage ?? `${ROUTES.OG}${canonical === ROUTES.HOME ? "" : canonical}`;
+ const resolvedOgImage = ogImage ?? SITE.OG_IMAGE;
const resolvedTitle = ogTitle ?? title;
return {