feat(web-next): render /blog/[slug] article detail via blog.articleBySlug
This commit is contained in:
34
apps/web-next/src/app/blog/[slug]/page.tsx
Normal file
34
apps/web-next/src/app/blog/[slug]/page.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { appRouter } from "@repo/core-api";
|
||||
import { bindAllProduction } from "../../../server/bind-production";
|
||||
|
||||
type PageProps = {
|
||||
params: Promise<{ slug: string }>;
|
||||
};
|
||||
|
||||
export default async function BlogPostPage({ params }: PageProps) {
|
||||
await bindAllProduction();
|
||||
const { slug } = await params;
|
||||
const caller = appRouter.createCaller({});
|
||||
const article = await caller.blog.articleBySlug({ slug });
|
||||
|
||||
if (!article) notFound();
|
||||
|
||||
return (
|
||||
<main>
|
||||
<article>
|
||||
<header>
|
||||
<h1>{article.title}</h1>
|
||||
{article.createdAt ? (
|
||||
<time dateTime={article.createdAt.toISOString()}>
|
||||
{article.createdAt.toLocaleDateString()}
|
||||
</time>
|
||||
) : null}
|
||||
</header>
|
||||
<pre style={{ whiteSpace: "pre-wrap" }}>
|
||||
{JSON.stringify(article.content, null, 2)}
|
||||
</pre>
|
||||
</article>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user