import { env } from "../../../lib/env"; import { Suspense } from "react"; import { JsonLd } from "react-schemaorg"; import { CalendarIcon, TagIcon, SquarePenIcon, EyeIcon } from "lucide-react"; import Link from "../../../components/Link"; import Time from "../../../components/Time"; import Comments from "../../../components/Comments"; import Loading from "../../../components/Loading"; import HitCounter from "./counter"; import { getSlugs, getFrontMatter } from "../../../lib/helpers/posts"; import { addMetadata } from "../../../lib/helpers/metadata"; import * as config from "../../../lib/config"; import { POSTS_DIR } from "../../../lib/config/constants"; import { size as ogImageSize } from "./opengraph-image"; import type { Metadata } from "next"; import type { BlogPosting } from "schema-dts"; import styles from "./page.module.css"; // https://nextjs.org/docs/app/api-reference/functions/generate-static-params#disable-rendering-for-unspecified-paths export const dynamicParams = false; // https://nextjs.org/docs/app/building-your-application/rendering/partial-prerendering#using-partial-prerendering export const experimental_ppr = true; export const generateStaticParams = async () => { const slugs = await getSlugs(); // map slugs into a static paths object required by next.js return slugs.map((slug) => ({ slug, })); }; export const generateMetadata = async ({ params }: { params: Promise<{ slug: string }> }): Promise => { const { slug } = await params; const frontmatter = await getFrontMatter(slug); return addMetadata({ title: frontmatter!.title, description: frontmatter!.description, openGraph: { type: "article", authors: [config.authorName], tags: frontmatter!.tags, publishedTime: frontmatter!.date, modifiedTime: frontmatter!.date, }, twitter: { card: "summary_large_image", }, alternates: { canonical: `/${POSTS_DIR}/${slug}`, }, }); }; const Page = async ({ params }: { params: Promise<{ slug: string }> }) => { const { slug } = await params; const frontmatter = await getFrontMatter(slug); const { default: MDXContent } = await import(`../../../${POSTS_DIR}/${slug}/index.mdx`); return ( <> item={{ "@context": "https://schema.org", "@type": "BlogPosting", headline: frontmatter!.title, description: frontmatter!.description, url: frontmatter!.permalink, image: { "@type": "ImageObject", contentUrl: `${env.NEXT_PUBLIC_BASE_URL}/${POSTS_DIR}/${frontmatter!.slug}/opengraph-image`, width: `${ogImageSize.width}`, height: `${ogImageSize.height}`, }, keywords: frontmatter!.tags?.join(", "), datePublished: frontmatter!.date, dateModified: frontmatter!.date, inLanguage: env.NEXT_PUBLIC_SITE_LOCALE, license: config.licenseUrl, author: { // defined in app/layout.tsx "@id": `${env.NEXT_PUBLIC_BASE_URL}/#person`, }, }} />
{frontmatter!.tags && (
{frontmatter!.tags.map((tag) => ( {tag} ))}
)}
Improve This Post
0} >

{!frontmatter!.noComments && (
}>
)} ); }; export default Page;