feat: render CMS SEO metadata and refresh published page caches
This commit is contained in:
@@ -26,8 +26,7 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
|
||||
for (const tag of tags) {
|
||||
// Next.js 16 要求传入 cache profile;"max" 表示立即使该标签下的缓存完全失效。
|
||||
revalidateTag(tag, "max");
|
||||
revalidateTag(tag, { expire: 0 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ revalidated: tags });
|
||||
|
||||
@@ -4,6 +4,8 @@ import { getBlogBySlug } from "@/services/blog.service";
|
||||
import { getPreviewOrFallback } from "@/services/preview.service";
|
||||
import { BlockRenderer } from "@/blocks/BlockRenderer";
|
||||
import type { BlogPageDetail } from "@/types/wagtail";
|
||||
import { createPageMetadata, getPageSEO } from "@/services/seo.service";
|
||||
import PageSEO from "@/components/layout/PageSEO";
|
||||
|
||||
interface BlogDetailPageProps {
|
||||
params: Promise<{ slug: string }>;
|
||||
@@ -13,8 +15,7 @@ export async function generateMetadata({
|
||||
params,
|
||||
}: BlogDetailPageProps): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const post = await getBlogBySlug(slug).catch(() => null);
|
||||
return { title: post?.title ?? "文章未找到" };
|
||||
return createPageMetadata(await getPageSEO("blog.BlogPage", slug).catch(() => null), "文章未找到");
|
||||
}
|
||||
|
||||
export default async function BlogDetailPage({ params }: BlogDetailPageProps) {
|
||||
@@ -31,6 +32,7 @@ export default async function BlogDetailPage({ params }: BlogDetailPageProps) {
|
||||
|
||||
return (
|
||||
<article className="mx-auto max-w-3xl px-6 py-24">
|
||||
<PageSEO type="blog.BlogPage" slug={slug} />
|
||||
<h1 className="mb-4 text-4xl font-bold text-slate-900">{post.title}</h1>
|
||||
{post.published_at && (
|
||||
<p className="mb-12 text-sm text-slate-500">{post.published_at}</p>
|
||||
|
||||
+6
-3
@@ -1,16 +1,19 @@
|
||||
import Link from "next/link";
|
||||
import type { Metadata } from "next";
|
||||
import { getBlogList } from "@/services/blog.service";
|
||||
import { createPageMetadata, getPageSEO } from "@/services/seo.service";
|
||||
import PageSEO from "@/components/layout/PageSEO";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "技术博客",
|
||||
};
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
return createPageMetadata(await getPageSEO("blog.BlogIndexPage", "blog").catch(() => null), "技术博客");
|
||||
}
|
||||
|
||||
export default async function BlogListPage() {
|
||||
const posts = await getBlogList().catch(() => []);
|
||||
|
||||
return (
|
||||
<div className="mx-auto max-w-4xl px-6 py-24">
|
||||
<PageSEO type="blog.BlogIndexPage" slug="blog" />
|
||||
<h1 className="mb-12 text-4xl font-bold text-slate-900">技术博客</h1>
|
||||
<ul className="space-y-6">
|
||||
{posts.map((post) => (
|
||||
|
||||
@@ -4,6 +4,8 @@ import { getCaseStudyBySlug } from "@/services/case.service";
|
||||
import { getPreviewOrFallback } from "@/services/preview.service";
|
||||
import { BlockRenderer } from "@/blocks/BlockRenderer";
|
||||
import type { CaseStudyPageDetail } from "@/types/wagtail";
|
||||
import { createPageMetadata, getPageSEO } from "@/services/seo.service";
|
||||
import PageSEO from "@/components/layout/PageSEO";
|
||||
|
||||
interface CaseStudyDetailPageProps {
|
||||
params: Promise<{ slug: string }>;
|
||||
@@ -13,8 +15,7 @@ export async function generateMetadata({
|
||||
params,
|
||||
}: CaseStudyDetailPageProps): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const item = await getCaseStudyBySlug(slug).catch(() => null);
|
||||
return { title: item?.title ?? "案例未找到" };
|
||||
return createPageMetadata(await getPageSEO("cases.CaseStudyPage", slug).catch(() => null), "案例未找到");
|
||||
}
|
||||
|
||||
export default async function CaseStudyDetailPage({
|
||||
@@ -33,6 +34,7 @@ export default async function CaseStudyDetailPage({
|
||||
|
||||
return (
|
||||
<article className="mx-auto max-w-3xl px-6 py-24">
|
||||
<PageSEO type="cases.CaseStudyPage" slug={slug} />
|
||||
<h1 className="mb-2 text-4xl font-bold text-slate-900">{item.title}</h1>
|
||||
<p className="mb-12 text-sm text-slate-500">
|
||||
{item.client_name}
|
||||
|
||||
+6
-3
@@ -1,16 +1,19 @@
|
||||
import Link from "next/link";
|
||||
import type { Metadata } from "next";
|
||||
import { getCaseStudyList } from "@/services/case.service";
|
||||
import { createPageMetadata, getPageSEO } from "@/services/seo.service";
|
||||
import PageSEO from "@/components/layout/PageSEO";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "客户案例",
|
||||
};
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
return createPageMetadata(await getPageSEO("cases.CaseStudyIndexPage", "cases").catch(() => null), "客户案例");
|
||||
}
|
||||
|
||||
export default async function CaseStudyListPage() {
|
||||
const caseStudies = await getCaseStudyList().catch(() => []);
|
||||
|
||||
return (
|
||||
<div className="mx-auto max-w-4xl px-6 py-24">
|
||||
<PageSEO type="cases.CaseStudyIndexPage" slug="cases" />
|
||||
<h1 className="mb-12 text-4xl font-bold text-slate-900">客户案例</h1>
|
||||
<ul className="space-y-6">
|
||||
{caseStudies.map((item) => (
|
||||
|
||||
@@ -3,13 +3,11 @@ import { getContactPage } from "@/services/page.service";
|
||||
import { getPreviewOrFallback } from "@/services/preview.service";
|
||||
import { BlockRenderer } from "@/blocks/BlockRenderer";
|
||||
import type { ContactPageDetail } from "@/types/wagtail";
|
||||
import { createPageMetadata, getPageSEO } from "@/services/seo.service";
|
||||
import PageSEO from "@/components/layout/PageSEO";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const page = await getContactPage().catch(() => null);
|
||||
return {
|
||||
title: page?.seo_title_override || page?.title || "联系我们",
|
||||
description: page?.seo_description_override,
|
||||
};
|
||||
return createPageMetadata(await getPageSEO("core.ContactPage", "contact").catch(() => null), "联系我们");
|
||||
}
|
||||
|
||||
export default async function ContactPage() {
|
||||
@@ -36,5 +34,5 @@ export default async function ContactPage() {
|
||||
);
|
||||
}
|
||||
|
||||
return <BlockRenderer blocks={contactPage.body} />;
|
||||
return <><PageSEO type="core.ContactPage" slug="contact" /><BlockRenderer blocks={contactPage.body} /></>;
|
||||
}
|
||||
|
||||
+6
-4
@@ -3,10 +3,12 @@ import { getHomePage } from "@/services/page.service";
|
||||
import { getPreviewOrFallback } from "@/services/preview.service";
|
||||
import { BlockRenderer } from "@/blocks/BlockRenderer";
|
||||
import type { HomePageDetail } from "@/types/wagtail";
|
||||
import { createPageMetadata, getPageSEO } from "@/services/seo.service";
|
||||
import PageSEO from "@/components/layout/PageSEO";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "首页",
|
||||
};
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
return createPageMetadata(await getPageSEO("home.HomePage").catch(() => null), "首页");
|
||||
}
|
||||
|
||||
export default async function Home() {
|
||||
const homePage = await getPreviewOrFallback<HomePageDetail>(
|
||||
@@ -33,5 +35,5 @@ export default async function Home() {
|
||||
);
|
||||
}
|
||||
|
||||
return <BlockRenderer blocks={homePage.body} />;
|
||||
return <><PageSEO type="home.HomePage" /><BlockRenderer blocks={homePage.body} /></>;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import type { Metadata } from "next";
|
||||
import { getSimpleContentPageBySlug } from "@/services/legal.service";
|
||||
import { createPageMetadata, getPageSEO } from "@/services/seo.service";
|
||||
import PageSEO from "@/components/layout/PageSEO";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const page = await getSimpleContentPageBySlug("privacy-policy").catch(() => null);
|
||||
return { title: page?.title ?? "隐私政策" };
|
||||
return createPageMetadata(await getPageSEO("core.SimpleContentPage", "privacy-policy").catch(() => null), "隐私政策");
|
||||
}
|
||||
|
||||
export default async function PrivacyPolicyPage() {
|
||||
@@ -16,6 +17,7 @@ export default async function PrivacyPolicyPage() {
|
||||
|
||||
return (
|
||||
<article className="mx-auto max-w-3xl px-6 py-24">
|
||||
<PageSEO type="core.SimpleContentPage" slug="privacy-policy" />
|
||||
<h1 className="mb-8 text-4xl font-bold text-slate-900">{page.title}</h1>
|
||||
{/* page.body 为 Wagtail RichTextField 渲染出的 HTML,内容仅由后台编辑人员维护,非用户输入,可信任直接渲染 */}
|
||||
<div
|
||||
|
||||
@@ -4,6 +4,8 @@ import { getProductBySlug } from "@/services/product.service";
|
||||
import { getPreviewOrFallback } from "@/services/preview.service";
|
||||
import { BlockRenderer } from "@/blocks/BlockRenderer";
|
||||
import type { ProductPageDetail } from "@/types/wagtail";
|
||||
import { createPageMetadata, getPageSEO } from "@/services/seo.service";
|
||||
import PageSEO from "@/components/layout/PageSEO";
|
||||
|
||||
interface ProductDetailPageProps {
|
||||
params: Promise<{ slug: string }>;
|
||||
@@ -13,8 +15,7 @@ export async function generateMetadata({
|
||||
params,
|
||||
}: ProductDetailPageProps): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const product = await getProductBySlug(slug).catch(() => null);
|
||||
return { title: product?.title ?? "产品未找到" };
|
||||
return createPageMetadata(await getPageSEO("products.ProductPage", slug).catch(() => null), "产品未找到");
|
||||
}
|
||||
|
||||
export default async function ProductDetailPage({
|
||||
@@ -33,6 +34,7 @@ export default async function ProductDetailPage({
|
||||
|
||||
return (
|
||||
<article className="mx-auto max-w-3xl px-6 py-24">
|
||||
<PageSEO type="products.ProductPage" slug={slug} />
|
||||
<h1 className="mb-4 text-4xl font-bold text-slate-900">
|
||||
{product.title}
|
||||
</h1>
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import Link from "next/link";
|
||||
import type { Metadata } from "next";
|
||||
import { getProductList } from "@/services/product.service";
|
||||
import { createPageMetadata, getPageSEO } from "@/services/seo.service";
|
||||
import PageSEO from "@/components/layout/PageSEO";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "产品",
|
||||
};
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
return createPageMetadata(await getPageSEO("products.ProductIndexPage", "products").catch(() => null), "产品");
|
||||
}
|
||||
|
||||
export default async function ProductListPage() {
|
||||
const products = await getProductList().catch(() => []);
|
||||
|
||||
return (
|
||||
<div className="mx-auto max-w-4xl px-6 py-24">
|
||||
<PageSEO type="products.ProductIndexPage" slug="products" />
|
||||
<h1 className="mb-12 text-4xl font-bold text-slate-900">产品</h1>
|
||||
<ul className="space-y-6">
|
||||
{products.map((product) => (
|
||||
|
||||
@@ -4,6 +4,8 @@ import { getSolutionBySlug } from "@/services/solution.service";
|
||||
import { getPreviewOrFallback } from "@/services/preview.service";
|
||||
import { BlockRenderer } from "@/blocks/BlockRenderer";
|
||||
import type { SolutionPageDetail } from "@/types/wagtail";
|
||||
import { createPageMetadata, getPageSEO } from "@/services/seo.service";
|
||||
import PageSEO from "@/components/layout/PageSEO";
|
||||
|
||||
interface SolutionDetailPageProps {
|
||||
params: Promise<{ slug: string }>;
|
||||
@@ -13,8 +15,7 @@ export async function generateMetadata({
|
||||
params,
|
||||
}: SolutionDetailPageProps): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const solution = await getSolutionBySlug(slug).catch(() => null);
|
||||
return { title: solution?.title ?? "解决方案未找到" };
|
||||
return createPageMetadata(await getPageSEO("solutions.SolutionPage", slug).catch(() => null), "解决方案未找到");
|
||||
}
|
||||
|
||||
export default async function SolutionDetailPage({
|
||||
@@ -33,6 +34,7 @@ export default async function SolutionDetailPage({
|
||||
|
||||
return (
|
||||
<article className="mx-auto max-w-3xl px-6 py-24">
|
||||
<PageSEO type="solutions.SolutionPage" slug={slug} />
|
||||
<h1 className="mb-2 text-4xl font-bold text-slate-900">
|
||||
{solution.title}
|
||||
</h1>
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import Link from "next/link";
|
||||
import type { Metadata } from "next";
|
||||
import { getSolutionList } from "@/services/solution.service";
|
||||
import { createPageMetadata, getPageSEO } from "@/services/seo.service";
|
||||
import PageSEO from "@/components/layout/PageSEO";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "解决方案",
|
||||
};
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
return createPageMetadata(await getPageSEO("solutions.SolutionIndexPage", "solutions").catch(() => null), "解决方案");
|
||||
}
|
||||
|
||||
export default async function SolutionListPage() {
|
||||
const solutions = await getSolutionList().catch(() => []);
|
||||
|
||||
return (
|
||||
<div className="mx-auto max-w-4xl px-6 py-24">
|
||||
<PageSEO type="solutions.SolutionIndexPage" slug="solutions" />
|
||||
<h1 className="mb-12 text-4xl font-bold text-slate-900">解决方案</h1>
|
||||
<ul className="space-y-6">
|
||||
{solutions.map((solution) => (
|
||||
|
||||
Reference in New Issue
Block a user