Skip to content

Commit bb7d9c7

Browse files
authoredJul 21, 2024··
feat!: new multi sitemaps paths (#320)
1 parent a7c04bc commit bb7d9c7

18 files changed

+80
-87
lines changed
 

‎src/module.ts

+14-11
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,10 @@ declare module 'vue-router' {
319319
nuxt.options.nitro.routeRules['/sitemap.xml'] = { redirect: '/sitemap_index.xml' }
320320
nuxt.options.nitro.routeRules['/sitemap_index.xml'] = routeRules
321321
if (typeof config.sitemaps === 'object') {
322-
for (const k in config.sitemaps)
323-
nuxt.options.nitro.routeRules[`/${k}-sitemap.xml`] = routeRules
322+
for (const k in config.sitemaps) {
323+
nuxt.options.nitro.routeRules[`/sitemap/${k}.xml`] = routeRules
324+
nuxt.options.nitro.routeRules[`/${k}-sitemap.xml`] = { redirect: `/sitemap/${k}.xml` }
325+
}
324326
}
325327
else {
326328
// TODO we should support the chunked generated sitemap names
@@ -394,6 +396,14 @@ declare module 'vue-router' {
394396
addServerHandler({
395397
route: '/sitemap_index.xml',
396398
handler: resolve('./runtime/nitro/routes/sitemap_index.xml'),
399+
lazy: true,
400+
middleware: false,
401+
})
402+
addServerHandler({
403+
route: `/sitemap/**:sitemap`,
404+
handler: resolve('./runtime/nitro/routes/sitemap/[sitemap].xml'),
405+
lazy: true,
406+
middleware: false,
397407
})
398408
sitemaps.index = {
399409
sitemapName: 'index',
@@ -405,15 +415,11 @@ declare module 'vue-router' {
405415
for (const sitemapName in config.sitemaps) {
406416
if (sitemapName === 'index')
407417
continue
408-
addServerHandler({
409-
route: `/${sitemapName}-sitemap.xml`,
410-
handler: resolve('./runtime/nitro/middleware/[sitemap]-sitemap.xml'),
411-
})
412418
const definition = config.sitemaps[sitemapName] as MultiSitemapEntry[string]
413419
sitemaps[sitemapName as keyof typeof sitemaps] = defu(
414420
{
415421
sitemapName,
416-
_route: withBase(`${sitemapName}-sitemap.xml`, nuxt.options.app.baseURL || '/'),
422+
_route: withBase(`sitemap/${sitemapName}.xml`, nuxt.options.app.baseURL || '/'),
417423
_hasSourceChunk: typeof definition.urls !== 'undefined' || definition.sources?.length || !!definition.dynamicUrlsApiEndpoint,
418424
},
419425
{ ...definition, urls: undefined, sources: undefined },
@@ -422,10 +428,7 @@ declare module 'vue-router' {
422428
}
423429
}
424430
else {
425-
// we have to registrer it as a middleware we can't match the URL pattern
426-
addServerHandler({
427-
handler: resolve('./runtime/nitro/middleware/[sitemap]-sitemap.xml'),
428-
})
431+
// we have to register it as a middleware we can't match the URL pattern
429432
sitemaps.chunks = {
430433
sitemapName: 'chunks',
431434
defaults: config.defaults,

‎src/runtime/nitro/routes/sitemap.xsl.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export default defineEventHandler(async (e) => {
1919
const { name: siteName, url: siteUrl } = useSiteConfig(e)
2020

2121
const referrer = getHeader(e, 'Referer')! || '/'
22-
const isNotIndexButHasIndex = referrer !== fixPath('/sitemap.xml') && parseURL(referrer).pathname.endsWith('-sitemap.xml')
22+
const referrerPath = parseURL(referrer).pathname
23+
const isNotIndexButHasIndex = referrerPath !== '/sitemap.xml' && referrerPath !== '/sitemap_index.xml' && referrerPath.endsWith('.xml')
2324
const sitemapName = parseURL(referrer).pathname.split('/').pop()?.split('-sitemap')[0] || fallbackSitemapName
2425
const title = `${siteName}${sitemapName !== 'sitemap.xml' ? ` - ${sitemapName === 'sitemap_index.xml' ? 'index' : sitemapName}` : ''}`.replace(/&/g, '&')
2526

‎src/runtime/nitro/middleware/[sitemap]-sitemap.xml.ts ‎src/runtime/nitro/routes/sitemap/[sitemap].xml.ts

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
import { createError, defineEventHandler } from 'h3'
2-
import { parseURL } from 'ufo'
3-
import { useSimpleSitemapRuntimeConfig } from '../utils'
4-
import { createSitemap } from '../sitemap/nitro'
1+
import { createError, defineEventHandler, getRouterParam } from 'h3'
2+
import { useSimpleSitemapRuntimeConfig } from '../../utils'
3+
import { createSitemap } from '../../sitemap/nitro'
54

65
export default defineEventHandler(async (e) => {
7-
const path = parseURL(e.path).pathname
8-
if (!path.endsWith('-sitemap.xml'))
9-
return
10-
11-
const runtimeConfig = useSimpleSitemapRuntimeConfig()
6+
const runtimeConfig = useSimpleSitemapRuntimeConfig(e)
127
const { sitemaps } = runtimeConfig
138

14-
const sitemapName = path
15-
.replace('-sitemap.xml', '')
16-
.replace('/', '')
9+
const sitemapName = (getRouterParam(e, 'sitemap') || e.path)?.replace('.xml', '')
10+
.replace('/sitemap/', '')
1711
// check if sitemapName can be cast to a number safely
1812
const isChunking = typeof sitemaps.chunks !== 'undefined' && !Number.isNaN(Number(sitemapName))
19-
if (!(sitemapName in sitemaps) && !isChunking) {
13+
if (!sitemapName || (!(sitemapName in sitemaps) && !isChunking)) {
2014
return createError({
2115
statusCode: 404,
2216
message: `Sitemap "${sitemapName}" not found.`,

‎src/runtime/nitro/routes/sitemap_index.xml.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { appendHeader, defineEventHandler, setHeader } from 'h3'
22
import { useSimpleSitemapRuntimeConfig } from '../utils'
33
import { buildSitemapIndex, urlsToIndexXml } from '../sitemap/builder/sitemap-index'
44
import type { SitemapOutputHookCtx } from '../../types'
5-
import { useNitroUrlResolvers } from '..//sitemap/nitro'
5+
import { useNitroUrlResolvers } from '../sitemap/nitro'
66
import { useNitroApp } from '#imports'
77

88
export default defineEventHandler(async (e) => {
@@ -18,7 +18,7 @@ export default defineEventHandler(async (e) => {
1818
e,
1919
'x-nitro-prerender',
2020
sitemaps.filter(entry => !!entry._sitemapName)
21-
.map(entry => encodeURIComponent(`/${entry._sitemapName}-sitemap.xml`)).join(', '),
21+
.map(entry => encodeURIComponent(`/sitemap/${entry._sitemapName}.xml`)).join(', '),
2222
)
2323
}
2424

‎src/runtime/nitro/sitemap/builder/sitemap-index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export async function buildSitemapIndex(resolvers: NitroUrlResolvers, runtimeCon
6464
const sitemap = chunks[name]
6565
const entry: SitemapIndexEntry = {
6666
_sitemapName: name,
67-
sitemap: resolvers.canonicalUrlResolver(`${name}-sitemap.xml`),
67+
sitemap: resolvers.canonicalUrlResolver(`sitemap/${name}.xml`),
6868
}
6969
let lastmod = sitemap.urls
7070
.filter(a => !!a?.lastmod)

‎src/runtime/nitro/sitemap/nitro.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ export function useNitroUrlResolvers(e: H3Event): NitroUrlResolvers {
3333
}
3434
}
3535

36-
export async function createSitemap(e: H3Event, definition: SitemapDefinition, runtimeConfig: ModuleRuntimeConfig) {
36+
export async function createSitemap(event: H3Event, definition: SitemapDefinition, runtimeConfig: ModuleRuntimeConfig) {
3737
const { sitemapName } = definition
3838
const nitro = useNitroApp()
39-
const resolvers = useNitroUrlResolvers(e)
39+
const resolvers = useNitroUrlResolvers(event)
4040
let sitemapUrls = await buildSitemapUrls(definition, resolvers, runtimeConfig)
4141

4242
const routeRuleMatcher = createNitroRouteRuleMatcher()
4343
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)
4748
return false
48-
const path = e._path.pathname
4949
let routeRules = routeRuleMatcher(path)
5050
// apply top-level path without prefix, users can still target the localed path
5151
if (autoI18n?.locales && autoI18n?.strategy !== 'no_prefix') {
@@ -70,7 +70,7 @@ export async function createSitemap(e: H3Event, definition: SitemapDefinition, r
7070
if (routeRules.redirect || hasRobotsDisabled)
7171
return false
7272

73-
return routeRules.sitemap ? defu(e, routeRules.sitemap) as ResolvedSitemapUrl : e
73+
return routeRules.sitemap ? defu(u, routeRules.sitemap) as ResolvedSitemapUrl : u
7474
}).filter(Boolean)
7575

7676
// 6. nitro hooks
@@ -88,11 +88,11 @@ export async function createSitemap(e: H3Event, definition: SitemapDefinition, r
8888
const ctx = { sitemap, sitemapName }
8989
await nitro.hooks.callHook('sitemap:output', ctx)
9090
// 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')
9292
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`)
9494
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
9797
return ctx.sitemap
9898
}

‎test/integration/chunks/default.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ describe('multi chunks', () => {
1717
"<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/__sitemap__/style.xsl"?>
1818
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
1919
<sitemap>
20-
<loc>https://nuxtseo.com/0-sitemap.xml</loc>
20+
<loc>https://nuxtseo.com/sitemap/0.xml</loc>
2121
</sitemap>
2222
<sitemap>
23-
<loc>https://nuxtseo.com/1-sitemap.xml</loc>
23+
<loc>https://nuxtseo.com/sitemap/1.xml</loc>
2424
</sitemap>
2525
<sitemap>
26-
<loc>https://nuxtseo.com/2-sitemap.xml</loc>
26+
<loc>https://nuxtseo.com/sitemap/2.xml</loc>
2727
</sitemap>
2828
<sitemap>
29-
<loc>https://nuxtseo.com/3-sitemap.xml</loc>
29+
<loc>https://nuxtseo.com/sitemap/3.xml</loc>
3030
</sitemap>
3131
</sitemapindex>"
3232
`)
33-
const sitemap0 = await $fetch('/0-sitemap.xml')
33+
const sitemap0 = await $fetch('/sitemap/0.xml')
3434
expect(sitemap0).toMatchInlineSnapshot(`
3535
"<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/__sitemap__/style.xsl"?>
3636
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-image/1.1 http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

‎test/integration/chunks/generate.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ describe('generate', () => {
2727
"<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/__sitemap__/style.xsl"?>
2828
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
2929
<sitemap>
30-
<loc>https://nuxtseo.com/0-sitemap.xml</loc>
30+
<loc>https://nuxtseo.com/sitemap/0.xml</loc>
3131
</sitemap>
3232
<sitemap>
33-
<loc>https://nuxtseo.com/1-sitemap.xml</loc>
33+
<loc>https://nuxtseo.com/sitemap/1.xml</loc>
3434
</sitemap>
3535
<sitemap>
36-
<loc>https://nuxtseo.com/2-sitemap.xml</loc>
36+
<loc>https://nuxtseo.com/sitemap/2.xml</loc>
3737
</sitemap>
3838
<sitemap>
39-
<loc>https://nuxtseo.com/3-sitemap.xml</loc>
39+
<loc>https://nuxtseo.com/sitemap/3.xml</loc>
4040
</sitemap>
4141
</sitemapindex>"
4242
`)
43-
const sitemapEn = (await readFile(resolve(rootDir, '.output/public/0-sitemap.xml'), 'utf-8')).replace(/lastmod>(.*?)</g, 'lastmod><')
43+
const sitemapEn = (await readFile(resolve(rootDir, '.output/public/sitemap/0.xml'), 'utf-8')).replace(/lastmod>(.*?)</g, 'lastmod><')
4444
expect(sitemapEn).toMatchInlineSnapshot(`
4545
"<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/__sitemap__/style.xsl"?>
4646
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-image/1.1 http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

‎test/integration/i18n/domains.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ describe('i18n domains', () => {
4141
"<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/__sitemap__/style.xsl"?>
4242
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
4343
<sitemap>
44-
<loc>https://nuxtseo.com/en-US-sitemap.xml</loc>
44+
<loc>https://nuxtseo.com/sitemap/en-US.xml</loc>
4545
</sitemap>
4646
<sitemap>
47-
<loc>https://nuxtseo.com/es-ES-sitemap.xml</loc>
47+
<loc>https://nuxtseo.com/sitemap/es-ES.xml</loc>
4848
</sitemap>
4949
<sitemap>
50-
<loc>https://nuxtseo.com/fr-FR-sitemap.xml</loc>
50+
<loc>https://nuxtseo.com/sitemap/fr-FR.xml</loc>
5151
</sitemap>
5252
</sitemapindex>"
5353
`)
5454

55-
const fr = await $fetch('/fr-FR-sitemap.xml')
55+
const fr = await $fetch('/sitemap/fr-FR.xml')
5656
expect(fr).toMatchInlineSnapshot(`
5757
"<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/__sitemap__/style.xsl"?>
5858
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-image/1.1 http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

‎test/integration/i18n/dynamic-urls.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ await setup({
2424
})
2525
describe('i18n dynamic urls', () => {
2626
it('basic', async () => {
27-
let sitemap = await $fetch('/en-US-sitemap.xml')
27+
let sitemap = await $fetch('/sitemap/en-US.xml')
2828

2929
// strip lastmod
3030
sitemap = sitemap.replace(/<lastmod>.*<\/lastmod>/g, '')

‎test/integration/i18n/filtering-include.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ await setup({
1919
})
2020
describe('i18n filtering with include', () => {
2121
it('basic', async () => {
22-
const sitemap = await $fetch('/main-sitemap.xml')
22+
const sitemap = await $fetch('/sitemap/main.xml')
2323

2424
expect(sitemap).toMatchInlineSnapshot(`
2525
"<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/__sitemap__/style.xsl"?>

‎test/integration/i18n/filtering-regexp.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ await setup({
2121
})
2222
describe('i18n filtering with regexp', () => {
2323
it('basic', async () => {
24-
let sitemap = await $fetch('/en-US-sitemap.xml')
24+
let sitemap = await $fetch('/sitemap/en-US.xml')
2525

2626
// strip lastmod
2727
sitemap = sitemap.replace(/<lastmod>.*<\/lastmod>/g, '')

‎test/integration/i18n/filtering.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ await setup({
1616
})
1717
describe('i18n filtering', () => {
1818
it('basic', async () => {
19-
let sitemap = await $fetch('/en-US-sitemap.xml')
19+
let sitemap = await $fetch('/sitemap/en-US.xml')
2020

2121
// strip lastmod
2222
sitemap = sitemap.replace(/<lastmod>.*<\/lastmod>/g, '')

‎test/integration/i18n/generate.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ describe('generate', () => {
2727
"<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/__sitemap__/style.xsl"?>
2828
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
2929
<sitemap>
30-
<loc>https://nuxtseo.com/en-US-sitemap.xml</loc>
30+
<loc>https://nuxtseo.com/sitemap/en-US.xml</loc>
3131
</sitemap>
3232
<sitemap>
33-
<loc>https://nuxtseo.com/es-ES-sitemap.xml</loc>
33+
<loc>https://nuxtseo.com/sitemap/es-ES.xml</loc>
3434
</sitemap>
3535
<sitemap>
36-
<loc>https://nuxtseo.com/fr-FR-sitemap.xml</loc>
36+
<loc>https://nuxtseo.com/sitemap/fr-FR.xml</loc>
3737
</sitemap>
3838
</sitemapindex>"
3939
`)
40-
const sitemapEn = (await readFile(resolve(rootDir, '.output/public/en-US-sitemap.xml'), 'utf-8')).replace(/lastmod>(.*?)</g, 'lastmod><')
40+
const sitemapEn = (await readFile(resolve(rootDir, '.output/public/sitemap/en-US.xml'), 'utf-8')).replace(/lastmod>(.*?)</g, 'lastmod><')
4141
expect(sitemapEn).toMatchInlineSnapshot(`
4242
"<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/__sitemap__/style.xsl"?>
4343
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-image/1.1 http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

‎test/integration/i18n/pages-multi.test.ts

+18-23
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ const { resolve } = createResolver(import.meta.url)
66

77
await setup({
88
rootDir: resolve('../../fixtures/i18n'),
9-
build: true,
109
server: true,
1110
nuxtConfig: {
1211
i18n: {
1312
locales: [
14-
'en',
15-
'fr',
13+
{
14+
code: 'en',
15+
iso: 'en-US',
16+
},
17+
{
18+
code: 'es',
19+
iso: 'es-ES',
20+
},
21+
{
22+
code: 'fr',
23+
iso: 'fr-FR',
24+
},
1625
],
1726
pages: {
1827
'about': {
@@ -49,22 +58,22 @@ await setup({
4958
})
5059
describe('i18n pages multi', () => {
5160
it('basic', async () => {
52-
const index = await $fetch('/sitemap.xml')
61+
const index = await $fetch('/sitemap_index.xml')
5362
expect(index).toMatchInlineSnapshot(`
5463
"<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/__sitemap__/style.xsl"?>
5564
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
5665
<sitemap>
57-
<loc>https://nuxtseo.com/en-US-sitemap.xml</loc>
66+
<loc>https://nuxtseo.com/sitemap/en-US.xml</loc>
5867
</sitemap>
5968
<sitemap>
60-
<loc>https://nuxtseo.com/fr-FR-sitemap.xml</loc>
69+
<loc>https://nuxtseo.com/sitemap/es-ES.xml</loc>
6170
</sitemap>
6271
<sitemap>
63-
<loc>https://nuxtseo.com/es-ES-sitemap.xml</loc>
72+
<loc>https://nuxtseo.com/sitemap/fr-FR.xml</loc>
6473
</sitemap>
6574
</sitemapindex>"
6675
`)
67-
const fr = await $fetch('/fr-FR-sitemap.xml')
76+
const fr = await $fetch('/sitemap/fr-FR.xml')
6877
expect(fr).toMatchInlineSnapshot(`
6978
"<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/__sitemap__/style.xsl"?>
7079
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-image/1.1 http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
@@ -85,8 +94,8 @@ describe('i18n pages multi', () => {
8594
<changefreq>weekly</changefreq>
8695
<xhtml:link rel="alternate" hreflang="x-default" href="https://nuxtseo.com/en/__sitemap/url" />
8796
<xhtml:link rel="alternate" hreflang="en-US" href="https://nuxtseo.com/en/__sitemap/url" />
88-
<xhtml:link rel="alternate" hreflang="fr-FR" href="https://nuxtseo.com/fr/__sitemap/url" />
8997
<xhtml:link rel="alternate" hreflang="es-ES" href="https://nuxtseo.com/es/__sitemap/url" />
98+
<xhtml:link rel="alternate" hreflang="fr-FR" href="https://nuxtseo.com/fr/__sitemap/url" />
9099
</url>
91100
<url>
92101
<loc>https://nuxtseo.com/fr/offres/developement</loc>
@@ -114,19 +123,5 @@ describe('i18n pages multi', () => {
114123
</url>
115124
</urlset>"
116125
`)
117-
const es = await $fetch('/es-ES-sitemap.xml')
118-
expect(es).toMatchInlineSnapshot(`
119-
"<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/__sitemap__/style.xsl"?>
120-
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-image/1.1 http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
121-
<url>
122-
<loc>https://nuxtseo.com/es/__sitemap/url</loc>
123-
<changefreq>weekly</changefreq>
124-
<xhtml:link rel="alternate" hreflang="x-default" href="https://nuxtseo.com/en/__sitemap/url" />
125-
<xhtml:link rel="alternate" hreflang="en-US" href="https://nuxtseo.com/en/__sitemap/url" />
126-
<xhtml:link rel="alternate" hreflang="fr-FR" href="https://nuxtseo.com/fr/__sitemap/url" />
127-
<xhtml:link rel="alternate" hreflang="es-ES" href="https://nuxtseo.com/es/__sitemap/url" />
128-
</url>
129-
</urlset>"
130-
`)
131126
}, 60000)
132127
})

‎test/integration/multi/defaults.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ await setup({
3636
})
3737
describe('mutli defaults', () => {
3838
it('basic', async () => {
39-
let sitemap = await $fetch('/foo-sitemap.xml')
39+
let sitemap = await $fetch('/sitemap/foo.xml')
4040
// remove lastmods before tresting
4141
sitemap = sitemap.replace(/lastmod>(.*?)</g, 'lastmod><')
4242
// basic test to make sure we get a valid response

‎test/integration/multi/endpoints.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ await setup({
2525
})
2626
describe('multi endpoints', () => {
2727
it('basic', async () => {
28-
let sitemap = await $fetch('/foo-sitemap.xml')
28+
let sitemap = await $fetch('/sitemap/foo.xml')
2929
// remove lastmods before tresting
3030
sitemap = sitemap.replace(/lastmod>(.*?)</g, 'lastmod><')
3131
// basic test to make sure we get a valid response

‎test/integration/multi/filtering.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ await setup({
3636
})
3737
describe('multi filtering', () => {
3838
it('basic', async () => {
39-
let sitemap = await $fetch('/foo-sitemap.xml')
39+
let sitemap = await $fetch('/sitemap/foo.xml')
4040

4141
// strip lastmod
4242
sitemap = sitemap.replace(/<lastmod>.*<\/lastmod>/g, '')

0 commit comments

Comments
 (0)
Please sign in to comment.