@@ -33,19 +33,19 @@ export function useNitroUrlResolvers(e: H3Event): NitroUrlResolvers {
33
33
}
34
34
}
35
35
36
- export async function createSitemap ( e : H3Event , definition : SitemapDefinition , runtimeConfig : ModuleRuntimeConfig ) {
36
+ export async function createSitemap ( event : H3Event , definition : SitemapDefinition , runtimeConfig : ModuleRuntimeConfig ) {
37
37
const { sitemapName } = definition
38
38
const nitro = useNitroApp ( )
39
- const resolvers = useNitroUrlResolvers ( e )
39
+ const resolvers = useNitroUrlResolvers ( event )
40
40
let sitemapUrls = await buildSitemapUrls ( definition , resolvers , runtimeConfig )
41
41
42
42
const routeRuleMatcher = createNitroRouteRuleMatcher ( )
43
43
const { autoI18n } = runtimeConfig
44
- sitemapUrls = sitemapUrls . map ( ( e ) => {
45
- // blocked by nuxt-simple-robots (this is a polyfill if not installed)
46
- if ( ! getPathRobotConfig ( e , { path : e . _path . pathname , skipSiteIndexable : true } ) . indexable )
44
+ sitemapUrls = sitemapUrls . map ( ( u ) => {
45
+ const path = u . _path ?. pathname || u . loc
46
+ // blocked by @nuxtjs /robots (this is a polyfill if not installed)
47
+ if ( ! getPathRobotConfig ( event , { path, skipSiteIndexable : true } ) . indexable )
47
48
return false
48
- const path = e . _path . pathname
49
49
let routeRules = routeRuleMatcher ( path )
50
50
// apply top-level path without prefix, users can still target the localed path
51
51
if ( autoI18n ?. locales && autoI18n ?. strategy !== 'no_prefix' ) {
@@ -70,7 +70,7 @@ export async function createSitemap(e: H3Event, definition: SitemapDefinition, r
70
70
if ( routeRules . redirect || hasRobotsDisabled )
71
71
return false
72
72
73
- return routeRules . sitemap ? defu ( e , routeRules . sitemap ) as ResolvedSitemapUrl : e
73
+ return routeRules . sitemap ? defu ( u , routeRules . sitemap ) as ResolvedSitemapUrl : u
74
74
} ) . filter ( Boolean )
75
75
76
76
// 6. nitro hooks
@@ -88,11 +88,11 @@ export async function createSitemap(e: H3Event, definition: SitemapDefinition, r
88
88
const ctx = { sitemap, sitemapName }
89
89
await nitro . hooks . callHook ( 'sitemap:output' , ctx )
90
90
// need to clone the config object to make it writable
91
- setHeader ( e , 'Content-Type' , 'text/xml; charset=UTF-8' )
91
+ setHeader ( event , 'Content-Type' , 'text/xml; charset=UTF-8' )
92
92
if ( runtimeConfig . cacheMaxAgeSeconds )
93
- setHeader ( e , 'Cache-Control' , `public, max-age=${ runtimeConfig . cacheMaxAgeSeconds } , must-revalidate` )
93
+ setHeader ( event , 'Cache-Control' , `public, max-age=${ runtimeConfig . cacheMaxAgeSeconds } , must-revalidate` )
94
94
else
95
- setHeader ( e , 'Cache-Control' , `no-cache, no-store` )
96
- e . context . _isSitemap = true
95
+ setHeader ( event , 'Cache-Control' , `no-cache, no-store` )
96
+ event . context . _isSitemap = true
97
97
return ctx . sitemap
98
98
}
0 commit comments