yiekheng 33087cc5b3 Make list pages fully dynamic; cache only at query level
Docker production build runs without DATABASE_URL, so any page Next
tries to prerender at build (force-static / revalidate without a
dynamic segment) fails on the Prisma call. Homepage, genre page, and
sitemap previously had page-level revalidate, forcing prerender. Add
force-dynamic to each and move the revalidation inside an
unstable_cache wrapper around the Prisma query — result still cached
5m / 1h at runtime, but build no longer touches the DB.

Detail page (/manga/[slug]) keeps page-level revalidate since its
dynamic segment without generateStaticParams was never prerendered at
build anyway.

Update CLAUDE.md caching section to reflect the new strategy.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 20:56:26 +08:00

37 lines
891 B
TypeScript

import type { MetadataRoute } from "next";
import { unstable_cache } from "next/cache";
import { prisma } from "@/lib/db";
export const dynamic = "force-dynamic";
const getSitemapManga = unstable_cache(
async () =>
prisma.manga.findMany({
where: { status: "PUBLISHED" },
select: { slug: true, updatedAt: true },
}),
["sitemap-manga-list"],
{ revalidate: 3600 }
);
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const manga = await getSitemapManga();
const mangaEntries: MetadataRoute.Sitemap = manga.map((m) => ({
url: `https://www.04080616.xyz/manga/${m.slug}`,
lastModified: m.updatedAt,
changeFrequency: "weekly",
priority: 0.8,
}));
return [
{
url: "https://www.04080616.xyz",
lastModified: new Date(),
changeFrequency: "daily",
priority: 1,
},
...mangaEntries,
];
}