diff --git a/src/sitemap.ts b/src/sitemap.ts index 9f608a2..cefc24a 100644 --- a/src/sitemap.ts +++ b/src/sitemap.ts @@ -44,8 +44,15 @@ export function getFormattedSitemap(options: ResolvedOptions, routes: string[]) priority: getOptionByRoute(options.priority, route) ?? defaultOptions.priority, lastmod: getOptionByRoute(options.lastmod, route) ?? defaultOptions.lastmod, } - if (options.i18n) - return Object.assign(formattedSitemap, { link: options.i18n.languages.map(str => ({ lang: str, url: str === options.i18n?.defaultLanguage ? url : `${url}/${str}` })) }) + if (options.i18n) { + const languages = options.i18n.languages.map(str => ({ + lang: str, + url: str === options.i18n?.defaultLanguage ? url : `${url}/${str}`, + })) + return Object.assign(formattedSitemap, { + links: options.i18n.defaultLanguage ? [...languages, { lang: 'x-default', url }] : languages, + }) + } return formattedSitemap }) diff --git a/test/sitemap.test.ts b/test/sitemap.test.ts index 8de3a49..3c62aa4 100644 --- a/test/sitemap.test.ts +++ b/test/sitemap.test.ts @@ -121,7 +121,7 @@ describe('sitemap', () => { { "changefreq": "daily", "lastmod": Any, - "link": [ + "links": [ { "lang": "fr", "url": "http://localhost/route/fr", @@ -143,7 +143,7 @@ describe('sitemap', () => { { "changefreq": "daily", "lastmod": Any, - "link": [ + "links": [ { "lang": "fr", "url": "http://localhost/route", @@ -152,6 +152,10 @@ describe('sitemap', () => { "lang": "en", "url": "http://localhost/route/en", }, + { + "lang": "x-default", + "url": "http://localhost/route", + }, ], "priority": 1, "url": "http://localhost/route",