mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
## Description This PR ensures that the default prettier config is used for examples and templates. This config is compatible with `prettier@3` as well (upgrading prettier is bigger change that can be a future PR). ## Changes - Updated `.prettierrc.json` in root with `"trailingComma": "es5"` (will be needed upgrading to prettier@3) - Added `examples/.prettierrc.json` with default config (this will change every example) - Added `packages/create-next-app/templates/.prettierrc.json` with default config (this will change every template) ## Related - Fixes #54402 - Closes #54409
94 lines
2.0 KiB
TypeScript
94 lines
2.0 KiB
TypeScript
import type { InferGetStaticPropsType } from "next";
|
|
import { useRouter } from "next/router";
|
|
import ErrorPage from "next/error";
|
|
import Comment from "../../components/comment";
|
|
import Container from "../../components/container";
|
|
import distanceToNow from "../../lib/dateRelative";
|
|
import { getAllPosts, getPostBySlug } from "../../lib/getPost";
|
|
import markdownToHtml from "../../lib/markdownToHtml";
|
|
import Head from "next/head";
|
|
|
|
export default function PostPage({
|
|
post,
|
|
}: InferGetStaticPropsType<typeof getStaticProps>) {
|
|
const router = useRouter();
|
|
|
|
if (!router.isFallback && !post?.slug) {
|
|
return <ErrorPage statusCode={404} />;
|
|
}
|
|
|
|
return (
|
|
<Container>
|
|
<Head>
|
|
<title>{post.title} | My awesome blog</title>
|
|
</Head>
|
|
|
|
{router.isFallback ? (
|
|
<div>Loading…</div>
|
|
) : (
|
|
<div>
|
|
<article>
|
|
<header>
|
|
<h1 className="text-4xl font-bold">{post.title}</h1>
|
|
{post.excerpt ? (
|
|
<p className="mt-2 text-xl">{post.excerpt}</p>
|
|
) : null}
|
|
<time className="flex mt-2 text-gray-400">
|
|
{distanceToNow(new Date(post.date))}
|
|
</time>
|
|
</header>
|
|
|
|
<div
|
|
className="prose mt-10"
|
|
dangerouslySetInnerHTML={{ __html: post.content }}
|
|
/>
|
|
</article>
|
|
|
|
<Comment />
|
|
</div>
|
|
)}
|
|
</Container>
|
|
);
|
|
}
|
|
|
|
type Params = {
|
|
params: {
|
|
slug: string;
|
|
};
|
|
};
|
|
|
|
export async function getStaticProps({ params }: Params) {
|
|
const post = getPostBySlug(params.slug, [
|
|
"slug",
|
|
"title",
|
|
"excerpt",
|
|
"date",
|
|
"content",
|
|
]);
|
|
const content = await markdownToHtml(post.content || "");
|
|
|
|
return {
|
|
props: {
|
|
post: {
|
|
...post,
|
|
content,
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
export async function getStaticPaths() {
|
|
const posts = getAllPosts(["slug"]);
|
|
|
|
return {
|
|
paths: posts.map(({ slug }) => {
|
|
return {
|
|
params: {
|
|
slug,
|
|
},
|
|
};
|
|
}),
|
|
fallback: false,
|
|
};
|
|
}
|