From 6b147778e525ec614fa7ff0a2dd68c66b860b818 Mon Sep 17 00:00:00 2001 From: jingrow Date: Wed, 3 Sep 2025 00:46:12 +0800 Subject: [PATCH] =?UTF-8?q?app=E9=87=8C=E9=9D=A2=E7=9A=84=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E5=AE=9E=E7=8E=B0=E5=88=86=E7=BB=84=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/[...slug]/page.jsx | 225 ++++++++++++++++++ app/(presentation)/presentation/layout.jsx | 24 ++ app/{ => (website)}/[...slug]/page.jsx | 0 .../api/get-component-data/route.js | 0 app/{ => (website)}/api/get-menu/route.js | 0 .../api/get-page-data/route.js | 0 app/{ => (website)}/api/revalidate/route.js | 0 app/{ => (website)}/api/send-email/route.js | 0 app/{ => (website)}/api/sitemap/route.js | 0 app/{ => (website)}/contact/page.jsx | 0 app/{ => (website)}/favicon.ico | Bin app/{ => (website)}/globals.css | 0 app/{ => (website)}/layout.jsx | 2 +- app/{ => (website)}/not-found.jsx | 0 app/{ => (website)}/page.jsx | 0 .../products/[...slug]/page.jsx | 0 public/assets/style.css | 2 +- 17 files changed, 251 insertions(+), 2 deletions(-) create mode 100644 app/(presentation)/presentation/[...slug]/page.jsx create mode 100644 app/(presentation)/presentation/layout.jsx rename app/{ => (website)}/[...slug]/page.jsx (100%) rename app/{ => (website)}/api/get-component-data/route.js (100%) rename app/{ => (website)}/api/get-menu/route.js (100%) rename app/{ => (website)}/api/get-page-data/route.js (100%) rename app/{ => (website)}/api/revalidate/route.js (100%) rename app/{ => (website)}/api/send-email/route.js (100%) rename app/{ => (website)}/api/sitemap/route.js (100%) rename app/{ => (website)}/contact/page.jsx (100%) rename app/{ => (website)}/favicon.ico (100%) rename app/{ => (website)}/globals.css (100%) rename app/{ => (website)}/layout.jsx (96%) rename app/{ => (website)}/not-found.jsx (100%) rename app/{ => (website)}/page.jsx (100%) rename app/{ => (website)}/products/[...slug]/page.jsx (100%) diff --git a/app/(presentation)/presentation/[...slug]/page.jsx b/app/(presentation)/presentation/[...slug]/page.jsx new file mode 100644 index 0000000..a525488 --- /dev/null +++ b/app/(presentation)/presentation/[...slug]/page.jsx @@ -0,0 +1,225 @@ +import { getSiteSettings } from "@/utils/data"; +import { notFound } from 'next/navigation'; +import { Suspense } from 'react'; +import { getPageData, getAllSlugs } from "@/utils/data"; + +const LoadingSpinner = () => ( +
+
+
+); + +// Using a static value to comply with Next.js 15 build requirements. +// On-demand revalidation will be handled via the API route. +export const revalidate = 3600; + +export async function generateStaticParams() { + try { + const slugs = await getAllSlugs(); + return slugs.map(slug => ({ + slug: slug, + })); + } catch (error) { + console.error("Failed to generate static params:", error); + return []; + } +} + +export async function generateMetadata({ params }) { + const resolvedParams = await params; + const slugArr = resolvedParams.slug; + const { data, error, page_info } = await getPageData({ + slug_list: slugArr, + downloadFiles: false // Do not download files for metadata + }); + const siteSettings = await getSiteSettings(); + const siteTitle = siteSettings.site_title || ''; + const siteName = siteSettings.site_name || ''; + const siteNameInPageTitles = siteSettings.site_name_in_page_titles || 'None'; + + let title = ''; + if (error) { + title = error.title || 'Page Error'; + return { + title, + description: error.message || '', + }; + } + if (Array.isArray(data) && page_info) { + title = page_info.meta_title || page_info.title || ''; + if (siteName && title) { + if (siteNameInPageTitles === 'After') { + title = `${title} - ${siteName}`; + } else if (siteNameInPageTitles === 'Before') { + title = `${siteName} - ${title}`; + } + } + return { + title, + description: page_info.meta_description || '', + }; + } + title = data?.meta_title || data?.title || ''; + if (siteName && title) { + if (siteNameInPageTitles === 'After') { + title = `${title} - ${siteName}`; + } else if (siteNameInPageTitles === 'Before') { + title = `${siteName} - ${title}`; + } + } + return { + title, + description: data?.meta_description || '', + }; +} + +export default async function DynamicPage({ params, searchParams }) { + const resolvedParams = await params; + const slugArr = resolvedParams.slug; + const siteSettings = await getSiteSettings(); + const pageSize = Number(siteSettings.page_size) || 12; + + // 始终获取第一页的数据用于静态生成 + const { data, error, total } = await getPageData({ + slug_list: slugArr, + page: 1, + page_size: pageSize, + downloadFiles: true // Download files for page rendering + }); + + if (error) { + notFound(); + } + + if (Array.isArray(data)) { + // 列表页面 - 全屏展示 + return ( +
+ }> +
+
+ {data.map((item, index) => ( +
+ {item.image && ( +
+ {item.title +
+ )} +
+

+ {item.title} +

+ {item.subtitle && ( +

+ {item.subtitle} +

+ )} + {item.description && ( +
+ {item.description} +
+ )} + {item.button_text && item.button_link && ( + + {item.button_text} + + )} +
+
+ ))} +
+
+
+
+ ); + } else if (data) { + // 单页内容 - 全屏展示 + return ( +
+
+
+ {/* 主图片区域 */} + {data.image && ( +
+ {data.title} +
+ )} + + {/* 内容区域 */} +
+ {/* 标题 */} +

+ {data.title} +

+ + {/* 副标题 */} + {data.subtitle && ( +
+

+ {data.subtitle} +

+
+ )} + + {/* 主内容 */} +
+ + {/* 附加内容 */} + {data.additional_content && ( +
+

附加信息

+
+
+ )} + + {/* 按钮区域 */} + {(data.button_text || data.button_1_text || data.button_2_text) && ( +
+ {data.button_text && data.button_link && ( + + {data.button_text} + + )} + {data.button_1_text && data.button_1_link && ( + + {data.button_1_text} + + )} + {data.button_2_text && data.button_2_link && ( + + {data.button_2_text} + + )} +
+ )} +
+
+
+
+ ); + } else { + notFound(); + } +} diff --git a/app/(presentation)/presentation/layout.jsx b/app/(presentation)/presentation/layout.jsx new file mode 100644 index 0000000..f85fd44 --- /dev/null +++ b/app/(presentation)/presentation/layout.jsx @@ -0,0 +1,24 @@ +import Context from "@/context/Context"; + + +export default function RootLayout({ children }) { + return ( + + + + + + + + {children} + + + + ); +} diff --git a/app/[...slug]/page.jsx b/app/(website)/[...slug]/page.jsx similarity index 100% rename from app/[...slug]/page.jsx rename to app/(website)/[...slug]/page.jsx diff --git a/app/api/get-component-data/route.js b/app/(website)/api/get-component-data/route.js similarity index 100% rename from app/api/get-component-data/route.js rename to app/(website)/api/get-component-data/route.js diff --git a/app/api/get-menu/route.js b/app/(website)/api/get-menu/route.js similarity index 100% rename from app/api/get-menu/route.js rename to app/(website)/api/get-menu/route.js diff --git a/app/api/get-page-data/route.js b/app/(website)/api/get-page-data/route.js similarity index 100% rename from app/api/get-page-data/route.js rename to app/(website)/api/get-page-data/route.js diff --git a/app/api/revalidate/route.js b/app/(website)/api/revalidate/route.js similarity index 100% rename from app/api/revalidate/route.js rename to app/(website)/api/revalidate/route.js diff --git a/app/api/send-email/route.js b/app/(website)/api/send-email/route.js similarity index 100% rename from app/api/send-email/route.js rename to app/(website)/api/send-email/route.js diff --git a/app/api/sitemap/route.js b/app/(website)/api/sitemap/route.js similarity index 100% rename from app/api/sitemap/route.js rename to app/(website)/api/sitemap/route.js diff --git a/app/contact/page.jsx b/app/(website)/contact/page.jsx similarity index 100% rename from app/contact/page.jsx rename to app/(website)/contact/page.jsx diff --git a/app/favicon.ico b/app/(website)/favicon.ico similarity index 100% rename from app/favicon.ico rename to app/(website)/favicon.ico diff --git a/app/globals.css b/app/(website)/globals.css similarity index 100% rename from app/globals.css rename to app/(website)/globals.css diff --git a/app/layout.jsx b/app/(website)/layout.jsx similarity index 96% rename from app/layout.jsx rename to app/(website)/layout.jsx index de07543..319c5d8 100644 --- a/app/layout.jsx +++ b/app/(website)/layout.jsx @@ -1,4 +1,4 @@ -import "../public/assets/style.css"; +import "@/public/assets/style.css"; import "photoswipe/dist/photoswipe.css"; import Context from "@/context/Context"; import ProgressWrap from "@/components/common/ProgressWrap"; diff --git a/app/not-found.jsx b/app/(website)/not-found.jsx similarity index 100% rename from app/not-found.jsx rename to app/(website)/not-found.jsx diff --git a/app/page.jsx b/app/(website)/page.jsx similarity index 100% rename from app/page.jsx rename to app/(website)/page.jsx diff --git a/app/products/[...slug]/page.jsx b/app/(website)/products/[...slug]/page.jsx similarity index 100% rename from app/products/[...slug]/page.jsx rename to app/(website)/products/[...slug]/page.jsx diff --git a/public/assets/style.css b/public/assets/style.css index 5f784e2..14b1caf 100644 --- a/public/assets/style.css +++ b/public/assets/style.css @@ -1,7 +1,7 @@ @import url("./fonts/unicons/unicons.css"); @import url("./css/plugins.css"); @import url("./css/icon.css"); -@import url("../../app/globals.css"); +@import url("../../app/(website)/globals.css"); @import url("./css/colors/aqua.css"); @import url("./css/colors/fuchsia.css"); @import url("./css/colors/grape.css");