MCPcopy Create free account
hub / github.com/context-space/context-space / generateDynamicLocalizedUrls

Function generateDynamicLocalizedUrls

web/src/app/sitemap.ts:65–108  ·  view source on GitHub ↗

* 为动态页面生成多语言 URL

(
  pathTemplate: (locale: string) => string,
  options: {
    priority: number
    changeFrequency: MetadataRoute.Sitemap[0]["changeFrequency"]
    lastModified?: Date
  },
)

Source from the content-addressed store, hash-verified

63 * 为动态页面生成多语言 URL
64 */
65function generateDynamicLocalizedUrls(
66 pathTemplate: (locale: string) => string,
67 options: {
68 priority: number
69 changeFrequency: MetadataRoute.Sitemap[0]["changeFrequency"]
70 lastModified?: Date
71 },
72): MetadataRoute.Sitemap {
73 const { priority, changeFrequency, lastModified = new Date() } = options
74
75 return locales.flatMap((locale) => {
76 const urls: MetadataRoute.Sitemap = []
77
78 if (locale === defaultLocale) {
79 // 为默认语言生成不带语言前缀的 URL
80 const path = pathTemplate("")
81 urls.push({
82 url: `${baseURL}${path}`,
83 lastModified,
84 changeFrequency,
85 priority,
86 })
87 // 也生成带语言前缀的版本
88 const localizedPath = pathTemplate(`/${locale}`)
89 urls.push({
90 url: `${baseURL}${localizedPath}`,
91 lastModified,
92 changeFrequency,
93 priority: Math.max(priority - 0.1, 0.1),
94 })
95 } else {
96 // 非默认语言生成带语言前缀的 URL
97 const localizedPath = pathTemplate(`/${locale}`)
98 urls.push({
99 url: `${baseURL}${localizedPath}`,
100 lastModified,
101 changeFrequency,
102 priority,
103 })
104 }
105
106 return urls
107 })
108}
109
110export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
111 const now = new Date()

Callers 1

sitemapFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected