|
|
@@ -0,0 +1,89 @@
|
|
|
+import { MetadataRoute } from 'next'
|
|
|
+import { serverGet, serverPost } from "@/utils/request"
|
|
|
+
|
|
|
+export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
|
|
+ const baseUrl = process.env.NEXT_PUBLIC_DOMAIN || 'http://www.hnsoyon.com'
|
|
|
+
|
|
|
+ // 1. 静态路由
|
|
|
+ const staticRoutes: MetadataRoute.Sitemap = [
|
|
|
+ '',
|
|
|
+ '/about',
|
|
|
+ '/about/recruitList',
|
|
|
+ '/business',
|
|
|
+ '/news',
|
|
|
+ '/products',
|
|
|
+ '/solutions',
|
|
|
+ '/support',
|
|
|
+ ].map((route) => ({
|
|
|
+ url: `${baseUrl}${route}`,
|
|
|
+ lastModified: new Date(),
|
|
|
+ changeFrequency: route === '' ? 'daily' : 'weekly',
|
|
|
+ priority: route === '' ? 1 : 0.8,
|
|
|
+ }))
|
|
|
+
|
|
|
+ // 2. 动态路由获取
|
|
|
+ const dynamicRoutes: MetadataRoute.Sitemap = []
|
|
|
+
|
|
|
+ // 获取新闻列表
|
|
|
+ try {
|
|
|
+ const newsRes = await serverGet<any>("/webSite/getNewsUpdatesListWithoutSpecialNews", { pageNum: 1, pageSize: 100 })
|
|
|
+ const specialNewsRes = await serverGet<any>("/webSite/getSpecialNewsUpdatesList", { pageNum: 1, pageSize: 20 })
|
|
|
+ const newsRecords = [
|
|
|
+ ...(newsRes.code === 200 ? (newsRes.data?.records || []) : []),
|
|
|
+ ...(specialNewsRes.code === 200 ? (specialNewsRes.data?.records || []) : [])
|
|
|
+ ]
|
|
|
+ const newsUrls: MetadataRoute.Sitemap = newsRecords.map((item: any) => ({
|
|
|
+ url: `${baseUrl}/news/${item.id}`,
|
|
|
+ lastModified: item.updateTime ? new Date(item.updateTime) : new Date(),
|
|
|
+ changeFrequency: 'monthly' as const,
|
|
|
+ priority: 0.6,
|
|
|
+ }))
|
|
|
+ dynamicRoutes.push(...newsUrls)
|
|
|
+ } catch (error) {
|
|
|
+ console.error("生成 Sitemap 时获取新闻列表失败:", error)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取产品列表
|
|
|
+ try {
|
|
|
+ const productRes = await serverGet<any>("/webSite/getProductByPage", { pageNum: 1, pageSize: 100 })
|
|
|
+ const productUrls: MetadataRoute.Sitemap = (productRes.code === 200 ? (productRes.data?.records || []) : []).map((item: any) => ({
|
|
|
+ url: `${baseUrl}/products/${item.id}`,
|
|
|
+ lastModified: item.updateTime ? new Date(item.updateTime) : new Date(),
|
|
|
+ changeFrequency: 'monthly' as const,
|
|
|
+ priority: 0.7,
|
|
|
+ }))
|
|
|
+ dynamicRoutes.push(...productUrls)
|
|
|
+ } catch (error) {
|
|
|
+ console.error("生成 Sitemap 时获取产品列表失败:", error)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取解决方案列表
|
|
|
+ try {
|
|
|
+ const solutionRes = await serverGet<any>("/webSite/getSolution", { pageNum: 1, pageSize: 100 })
|
|
|
+ const solutionUrls: MetadataRoute.Sitemap = (solutionRes.code === 200 ? (solutionRes.data?.records || []) : []).map((item: any) => ({
|
|
|
+ url: `${baseUrl}/solutions/${item.id}`,
|
|
|
+ lastModified: item.updateTime ? new Date(item.updateTime) : new Date(),
|
|
|
+ changeFrequency: 'monthly' as const,
|
|
|
+ priority: 0.7,
|
|
|
+ }))
|
|
|
+ dynamicRoutes.push(...solutionUrls)
|
|
|
+ } catch (error) {
|
|
|
+ console.error("生成 Sitemap 时获取解决方案失败:", error)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取招聘列表 (POST 请求)
|
|
|
+ try {
|
|
|
+ const recruitRes = await serverPost<any>("/webSite/getRecruitmentInfoByPage", { pageNum: 1, pageSize: 50 })
|
|
|
+ const recruitUrls: MetadataRoute.Sitemap = (recruitRes.code === 200 ? (recruitRes.data?.records || []) : []).map((item: any) => ({
|
|
|
+ url: `${baseUrl}/about/recruitList/${item.id}`,
|
|
|
+ lastModified: item.updateTime ? new Date(item.updateTime) : new Date(),
|
|
|
+ changeFrequency: 'monthly' as const,
|
|
|
+ priority: 0.5,
|
|
|
+ }))
|
|
|
+ dynamicRoutes.push(...recruitUrls)
|
|
|
+ } catch (error) {
|
|
|
+ console.error("生成 Sitemap 时获取招聘列表失败:", error)
|
|
|
+ }
|
|
|
+
|
|
|
+ return [...staticRoutes, ...dynamicRoutes]
|
|
|
+}
|