fix write
This commit is contained in:
parent
59422c5f67
commit
a661d6e690
@ -1,8 +1,8 @@
|
||||
import { notFound, redirect } from "next/navigation";
|
||||
import { getPost } from "../../action";
|
||||
import { Post } from "../../types";
|
||||
import Write from "../Write";
|
||||
import { isLoggedIn } from "@/components/auth";
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
|
||||
export default async function WritePage({
|
||||
params,
|
||||
@ -16,10 +16,20 @@ export default async function WritePage({
|
||||
const slug = (await params).slug?.[0];
|
||||
let post: Post | undefined = undefined;
|
||||
if (slug) {
|
||||
post = (await getPost(slug)) ?? undefined;
|
||||
if (post == null) {
|
||||
const prisma = new PrismaClient();
|
||||
const result =
|
||||
(await prisma.post.findUnique({
|
||||
where: { slug },
|
||||
include: { tags: true },
|
||||
})) ?? undefined;
|
||||
if (result == null) {
|
||||
notFound();
|
||||
}
|
||||
post = {
|
||||
...result,
|
||||
tags: result.tags.map((tag) => tag.name),
|
||||
contentRendered: result.contentRendered as { __html: string },
|
||||
};
|
||||
}
|
||||
return <Write post={post} />;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user