sitemap.config.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import process from 'node:process'
  2. import axios from 'axios'
  3. const BASE_URL = process.env.NODE_ENV === 'production'
  4. ? 'https://www.ejetselection.com'
  5. : 'http://localhost:8000'
  6. export const sitemapConfig = {
  7. hostname: BASE_URL,
  8. // 静态路由
  9. staticRoutes: [
  10. {
  11. loc: '/',
  12. changefreq: 'daily',
  13. priority: 1,
  14. },
  15. {
  16. loc: '/blog',
  17. changefreq: 'daily',
  18. priority: 0.8,
  19. },
  20. {
  21. loc: '/register',
  22. changefreq: 'daily',
  23. priority: 0.8,
  24. },
  25. {
  26. loc: '/collections',
  27. changefreq: 'daily',
  28. priority: 0.8,
  29. },
  30. {
  31. loc: '/about',
  32. changefreq: 'daily',
  33. priority: 0.8,
  34. },
  35. {
  36. loc: '/service',
  37. changefreq: 'daily',
  38. priority: 0.8,
  39. },
  40. {
  41. loc: '/policy',
  42. changefreq: 'daily',
  43. priority: 0.8,
  44. },
  45. {
  46. loc: '/suppliers/all-brands',
  47. changefreq: 'daily',
  48. priority: 0.8,
  49. },
  50. {
  51. loc: '/contact',
  52. changefreq: 'daily',
  53. priority: 0.6,
  54. },
  55. ],
  56. // 动态路由生成函数
  57. async generateDynamicRoutes() {
  58. const routes: any[] = []
  59. try {
  60. // 获取品牌列表
  61. const { data: brandData }: any = await axios.get(`${BASE_URL}/client/brand/list/default`, { params: { pageSize: 10000, pageNo: 1 } })
  62. if (brandData.code === 200) {
  63. brandData.result.records.forEach((brand: any) => {
  64. routes.push({
  65. loc: `${BASE_URL}/brand/${brand.id}`,
  66. changefreq: 'weekly',
  67. priority: 0.7,
  68. })
  69. })
  70. }
  71. // 获取专题列表
  72. const { data: featuredData }: any = await axios.get(`${BASE_URL}/client/topic/list`, { params: { pageSize: 10000, pageNo: 1 } })
  73. if (featuredData.code === 200) {
  74. featuredData.result.records.forEach((item: any) => {
  75. routes.push({
  76. loc: `${BASE_URL}/collections/${item.title}`,
  77. changefreq: 'weekly',
  78. priority: 0.7,
  79. })
  80. })
  81. }
  82. // 获取分类列表
  83. const { data: categoryData }: any = await axios.get(`${BASE_URL}/client/category/merchandise`, { params: { all: false, pageSize: 10000, pageNo: 1 } })
  84. if (categoryData.code === 200) {
  85. categoryData.result.forEach((item: any) => {
  86. routes.push({
  87. loc: `${BASE_URL}/categories/${item.key}`,
  88. changefreq: 'weekly',
  89. priority: 0.7,
  90. })
  91. })
  92. }
  93. // 获取博客列表
  94. const { data: blogData }: any = await axios.get(`${BASE_URL}/client/content/list`, { params: { type: 1, pageSize: 10000, pageNo: 1 } })
  95. if (blogData.code === 200) {
  96. blogData.result.records.forEach((item: any) => {
  97. routes.push({
  98. loc: `${BASE_URL}/blog/${item.contentTitle}`,
  99. changefreq: 'weekly',
  100. priority: 0.7,
  101. })
  102. })
  103. }
  104. // 获取商品列表
  105. const { data: productData }: any = await axios.post(`${BASE_URL}/client/merchandise/list/default`, {}, { params: { pageSize: 10000, pageNo: 1 } })
  106. if (productData.code === 200) {
  107. productData.result.records.forEach((item: any) => {
  108. routes.push({
  109. loc: `${BASE_URL}/product/${item.id}`,
  110. changefreq: 'weekly',
  111. priority: 0.7,
  112. })
  113. })
  114. }
  115. }
  116. catch (error) {
  117. console.error('Error fetching brands:', error)
  118. }
  119. return routes
  120. },
  121. }