Add blog CMS with tracked public posts
Build Check / build (pull_request) Successful in 34s
Build Check / push-image (pull_request) Has been skipped
Build Check / deploy-coolify (pull_request) Has been skipped

This commit is contained in:
2026-07-17 22:02:25 +00:00
parent ef63164d58
commit 912e5edb81
24 changed files with 1667 additions and 36 deletions
+32
View File
@@ -0,0 +1,32 @@
import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
import { toBlogPost } from "@/lib/blogs";
type Params = { params: Promise<{ slug: string }> };
export const dynamic = "force-dynamic";
export async function GET(_req: Request, { params }: Params) {
const { slug } = await params;
const post = await prisma.$transaction(async (tx) => {
const found = await tx.blogPost.findFirst({
where: { slug, isPublished: true },
});
if (!found) {
return null;
}
return tx.blogPost.update({
where: { id: found.id },
data: { views: { increment: 1 } },
});
});
if (!post) {
return NextResponse.json({ error: "Not found" }, { status: 404 });
}
return NextResponse.json(toBlogPost(post));
}