fix: 所有数据页面加 force-dynamic(解决构建时预渲染空数据缓存)
构建时数据库为空,Next.js 缓存了空页面。 加 force-dynamic 强制每次请求时从数据库读取。
This commit is contained in:
@@ -2,6 +2,8 @@ import { Suspense } from "react";
|
|||||||
import { getPublishedPosts } from "@/lib/store";
|
import { getPublishedPosts } from "@/lib/store";
|
||||||
import BlogList from "@/components/BlogList";
|
import BlogList from "@/components/BlogList";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
export const metadata = {
|
export const metadata = {
|
||||||
title: "文章",
|
title: "文章",
|
||||||
description: "胡旭的博客文章 — 技术、随笔、旅行、阅读",
|
description: "胡旭的博客文章 — 技术、随笔、旅行、阅读",
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import Link from "next/link";
|
|||||||
import { getPublicCategories, getPostsByCategory } from "@/lib/store";
|
import { getPublicCategories, getPostsByCategory } from "@/lib/store";
|
||||||
import GsapReveal from "@/components/GsapReveal";
|
import GsapReveal from "@/components/GsapReveal";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
export const metadata = {
|
export const metadata = {
|
||||||
title: "分类",
|
title: "分类",
|
||||||
description: "按分类浏览博客文章",
|
description: "按分类浏览博客文章",
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import { getPublishedPosts } from "@/lib/store";
|
|||||||
import HeroSection from "@/components/HeroSection";
|
import HeroSection from "@/components/HeroSection";
|
||||||
import { FeaturedGrid, RecentList } from "@/components/PostSections";
|
import { FeaturedGrid, RecentList } from "@/components/PostSections";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
export default async function HomePage() {
|
export default async function HomePage() {
|
||||||
const posts = await getPublishedPosts();
|
const posts = await getPublishedPosts();
|
||||||
const featuredPosts = posts.filter((p) => p.featured);
|
const featuredPosts = posts.filter((p) => p.featured);
|
||||||
|
|||||||
@@ -5,10 +5,7 @@ import PostContent from "@/components/PostContent";
|
|||||||
|
|
||||||
const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || "https://asui.xyz";
|
const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || "https://asui.xyz";
|
||||||
|
|
||||||
export async function generateStaticParams() {
|
export const dynamic = "force-dynamic";
|
||||||
const posts = await getPublishedPosts();
|
|
||||||
return posts.map((post) => ({ slug: post.slug }));
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function generateMetadata({
|
export async function generateMetadata({
|
||||||
params,
|
params,
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { getAllTags } from "@/lib/store";
|
import { getAllTags } from "@/lib/store";
|
||||||
import GsapReveal from "@/components/GsapReveal";
|
import GsapReveal from "@/components/GsapReveal";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
export const metadata = {
|
export const metadata = {
|
||||||
title: "标签",
|
title: "标签",
|
||||||
description: "按标签浏览博客文章",
|
description: "按标签浏览博客文章",
|
||||||
|
|||||||
Reference in New Issue
Block a user