fix: 所有数据页面加 force-dynamic(解决构建时预渲染空数据缓存)

构建时数据库为空,Next.js 缓存了空页面。
加 force-dynamic 强制每次请求时从数据库读取。
This commit is contained in:
胡旭
2026-06-24 17:14:26 +08:00
parent 92d190a081
commit 89f8d6e223
5 changed files with 9 additions and 4 deletions
+2
View File
@@ -2,6 +2,8 @@ import { Suspense } from "react";
import { getPublishedPosts } from "@/lib/store";
import BlogList from "@/components/BlogList";
export const dynamic = "force-dynamic";
export const metadata = {
title: "文章",
description: "胡旭的博客文章 — 技术、随笔、旅行、阅读",
+2
View File
@@ -2,6 +2,8 @@ import Link from "next/link";
import { getPublicCategories, getPostsByCategory } from "@/lib/store";
import GsapReveal from "@/components/GsapReveal";
export const dynamic = "force-dynamic";
export const metadata = {
title: "分类",
description: "按分类浏览博客文章",
+2
View File
@@ -2,6 +2,8 @@ import { getPublishedPosts } from "@/lib/store";
import HeroSection from "@/components/HeroSection";
import { FeaturedGrid, RecentList } from "@/components/PostSections";
export const dynamic = "force-dynamic";
export default async function HomePage() {
const posts = await getPublishedPosts();
const featuredPosts = posts.filter((p) => p.featured);
+1 -4
View File
@@ -5,10 +5,7 @@ import PostContent from "@/components/PostContent";
const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || "https://asui.xyz";
export async function generateStaticParams() {
const posts = await getPublishedPosts();
return posts.map((post) => ({ slug: post.slug }));
}
export const dynamic = "force-dynamic";
export async function generateMetadata({
params,
+2
View File
@@ -1,6 +1,8 @@
import { getAllTags } from "@/lib/store";
import GsapReveal from "@/components/GsapReveal";
export const dynamic = "force-dynamic";
export const metadata = {
title: "标签",
description: "按标签浏览博客文章",