|
@@ -1,7 +1,11 @@
|
|
|
import { Metadata } from "next";
|
|
import { Metadata } from "next";
|
|
|
|
|
|
|
|
import { NotionPage } from "@/components/notion-page";
|
|
import { NotionPage } from "@/components/notion-page";
|
|
|
-import { getPageContent } from "@/lib/notion";
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ getPageContent,
|
|
|
|
|
+ extractDescription,
|
|
|
|
|
+ customMapImageUrl,
|
|
|
|
|
+} from "@/lib/notion";
|
|
|
import { siteConfig } from "@/config/site";
|
|
import { siteConfig } from "@/config/site";
|
|
|
|
|
|
|
|
export const revalidate = 3600;
|
|
export const revalidate = 3600;
|
|
@@ -12,27 +16,40 @@ export async function generateMetadata({
|
|
|
params: Promise<{ blogId: string }>;
|
|
params: Promise<{ blogId: string }>;
|
|
|
}): Promise<Metadata> {
|
|
}): Promise<Metadata> {
|
|
|
const { blogId } = await params;
|
|
const { blogId } = await params;
|
|
|
- const { title } = await getPageContent(blogId);
|
|
|
|
|
|
|
+ const { title, recordMap } = await getPageContent(blogId);
|
|
|
|
|
|
|
|
const postTitle = title || "Blog Post";
|
|
const postTitle = title || "Blog Post";
|
|
|
|
|
+ const description =
|
|
|
|
|
+ extractDescription(recordMap) ||
|
|
|
|
|
+ `${postTitle} - by ${siteConfig.author}`;
|
|
|
|
|
+
|
|
|
|
|
+ const block = recordMap.block[blogId]?.value;
|
|
|
|
|
+ const coverUrl = block?.format?.page_cover;
|
|
|
|
|
+ const ogImages = coverUrl
|
|
|
|
|
+ ? [{ url: customMapImageUrl(coverUrl, block), alt: postTitle }]
|
|
|
|
|
+ : [{ url: "/og-image.png", alt: postTitle }];
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
title: postTitle,
|
|
title: postTitle,
|
|
|
- description: `${postTitle} - by ${siteConfig.author}`,
|
|
|
|
|
|
|
+ description,
|
|
|
alternates: {
|
|
alternates: {
|
|
|
canonical: `/blog/${blogId}`,
|
|
canonical: `/blog/${blogId}`,
|
|
|
},
|
|
},
|
|
|
openGraph: {
|
|
openGraph: {
|
|
|
title: postTitle,
|
|
title: postTitle,
|
|
|
- description: `${postTitle} - by ${siteConfig.author}`,
|
|
|
|
|
|
|
+ description,
|
|
|
type: "article",
|
|
type: "article",
|
|
|
url: `/blog/${blogId}`,
|
|
url: `/blog/${blogId}`,
|
|
|
authors: [siteConfig.author],
|
|
authors: [siteConfig.author],
|
|
|
|
|
+ publishedTime: new Date(block?.created_time).toISOString(),
|
|
|
|
|
+ modifiedTime: new Date(block?.last_edited_time).toISOString(),
|
|
|
|
|
+ images: ogImages,
|
|
|
},
|
|
},
|
|
|
twitter: {
|
|
twitter: {
|
|
|
card: "summary_large_image",
|
|
card: "summary_large_image",
|
|
|
title: postTitle,
|
|
title: postTitle,
|
|
|
- description: `${postTitle} - by ${siteConfig.author}`,
|
|
|
|
|
|
|
+ description,
|
|
|
|
|
+ images: ogImages.map((img) => img.url),
|
|
|
},
|
|
},
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
@@ -45,10 +62,22 @@ export default async function Page({
|
|
|
const { blogId } = await params;
|
|
const { blogId } = await params;
|
|
|
const { recordMap, title } = await getPageContent(blogId);
|
|
const { recordMap, title } = await getPageContent(blogId);
|
|
|
|
|
|
|
|
|
|
+ const block = recordMap.block[blogId]?.value;
|
|
|
|
|
+ const coverUrl = block?.format?.page_cover;
|
|
|
|
|
+ const description =
|
|
|
|
|
+ extractDescription(recordMap) ||
|
|
|
|
|
+ `${title} - by ${siteConfig.author}`;
|
|
|
|
|
+
|
|
|
const jsonLd = {
|
|
const jsonLd = {
|
|
|
"@context": "https://schema.org",
|
|
"@context": "https://schema.org",
|
|
|
"@type": "Article",
|
|
"@type": "Article",
|
|
|
headline: title,
|
|
headline: title,
|
|
|
|
|
+ description,
|
|
|
|
|
+ datePublished: new Date(block?.created_time).toISOString(),
|
|
|
|
|
+ dateModified: new Date(block?.last_edited_time).toISOString(),
|
|
|
|
|
+ ...(coverUrl && {
|
|
|
|
|
+ image: customMapImageUrl(coverUrl, block),
|
|
|
|
|
+ }),
|
|
|
author: {
|
|
author: {
|
|
|
"@type": "Person",
|
|
"@type": "Person",
|
|
|
name: siteConfig.author,
|
|
name: siteConfig.author,
|
|
@@ -59,6 +88,10 @@ export default async function Page({
|
|
|
name: siteConfig.author,
|
|
name: siteConfig.author,
|
|
|
url: siteConfig.url,
|
|
url: siteConfig.url,
|
|
|
},
|
|
},
|
|
|
|
|
+ mainEntityOfPage: {
|
|
|
|
|
+ "@type": "WebPage",
|
|
|
|
|
+ "@id": `${siteConfig.url}/blog/${blogId}`,
|
|
|
|
|
+ },
|
|
|
url: `${siteConfig.url}/blog/${blogId}`,
|
|
url: `${siteConfig.url}/blog/${blogId}`,
|
|
|
};
|
|
};
|
|
|
|
|
|