123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- import process from 'node:process'
- import axios from 'axios'
- const BASE_URL = process.env.NODE_ENV === 'production'
- ? 'https://www.ejetselection.com'
- : 'http://localhost:8000'
- export const sitemapConfig = {
- hostname: BASE_URL,
- // 静态路由
- staticRoutes: [
- {
- loc: '/',
- changefreq: 'daily',
- priority: 1,
- },
- {
- loc: '/blog',
- changefreq: 'daily',
- priority: 0.8,
- },
- {
- loc: '/register',
- changefreq: 'daily',
- priority: 0.8,
- },
- {
- loc: '/collections',
- changefreq: 'daily',
- priority: 0.8,
- },
- {
- loc: '/about',
- changefreq: 'daily',
- priority: 0.8,
- },
- {
- loc: '/service',
- changefreq: 'daily',
- priority: 0.8,
- },
- {
- loc: '/policy',
- changefreq: 'daily',
- priority: 0.8,
- },
- {
- loc: '/suppliers/all-brands',
- changefreq: 'daily',
- priority: 0.8,
- },
- {
- loc: '/contact',
- changefreq: 'daily',
- priority: 0.6,
- },
- ],
- // 动态路由生成函数
- async generateDynamicRoutes() {
- const routes: any[] = []
- try {
- // 获取品牌列表
- const { data: brandData }: any = await axios.get(`${BASE_URL}/client/brand/list/default`, { params: { pageSize: 10000, pageNo: 1 } })
- if (brandData.code === 200) {
- brandData.result.records.forEach((brand: any) => {
- routes.push({
- loc: `${BASE_URL}/brand/${brand.id}`,
- changefreq: 'weekly',
- priority: 0.7,
- })
- })
- }
- // 获取专题列表
- const { data: featuredData }: any = await axios.get(`${BASE_URL}/client/topic/list`, { params: { pageSize: 10000, pageNo: 1 } })
- if (featuredData.code === 200) {
- featuredData.result.records.forEach((item: any) => {
- routes.push({
- loc: `${BASE_URL}/collections/${item.title}`,
- changefreq: 'weekly',
- priority: 0.7,
- })
- })
- }
- // 获取分类列表
- const { data: categoryData }: any = await axios.get(`${BASE_URL}/client/category/merchandise`, { params: { all: false, pageSize: 10000, pageNo: 1 } })
- if (categoryData.code === 200) {
- categoryData.result.forEach((item: any) => {
- routes.push({
- loc: `${BASE_URL}/categories/${item.key}`,
- changefreq: 'weekly',
- priority: 0.7,
- })
- })
- }
- // 获取博客列表
- const { data: blogData }: any = await axios.get(`${BASE_URL}/client/content/list`, { params: { type: 1, pageSize: 10000, pageNo: 1 } })
- if (blogData.code === 200) {
- blogData.result.records.forEach((item: any) => {
- routes.push({
- loc: `${BASE_URL}/blog/${item.contentTitle}`,
- changefreq: 'weekly',
- priority: 0.7,
- })
- })
- }
- // 获取商品列表
- const { data: productData }: any = await axios.post(`${BASE_URL}/client/merchandise/list/default`, {}, { params: { pageSize: 10000, pageNo: 1 } })
- if (productData.code === 200) {
- productData.result.records.forEach((item: any) => {
- routes.push({
- loc: `${BASE_URL}/product/${item.id}`,
- changefreq: 'weekly',
- priority: 0.7,
- })
- })
- }
- }
- catch (error) {
- console.error('Error fetching brands:', error)
- }
- return routes
- },
- }
|