@@ -36,10 +36,12 @@ module.exports = (options, context) => {
36
36
37
37
log ( 'Generating sitemap...' )
38
38
39
- const { pages, locales } = context . getSiteData
39
+ const { pages, locales, base } = context . getSiteData
40
40
? context . getSiteData ( )
41
41
: context
42
42
43
+ const withBase = url => base . replace ( / \/ $ / , '' ) + url
44
+
43
45
// Sort the locale keys in reverse order so that longer locales, such as '/en/', match before the default '/'
44
46
const localeKeys = ( locales && Object . keys ( locales ) . sort ( ) . reverse ( ) ) || [ ]
45
47
const localesByNormalizedPagePath = pages . reduce ( ( map , page ) => {
@@ -75,7 +77,7 @@ module.exports = (options, context) => {
75
77
links = relatedLocales . map ( localePrefix => {
76
78
return {
77
79
lang : locales [ localePrefix ] . lang ,
78
- url : normalizedPath . replace ( '/' , localePrefix )
80
+ url : withBase ( normalizedPath . replace ( '/' , localePrefix ) )
79
81
}
80
82
} )
81
83
}
@@ -100,7 +102,12 @@ module.exports = (options, context) => {
100
102
} )
101
103
102
104
pagesMap . forEach ( ( page , url ) => {
103
- if ( ! exclude . includes ( url ) ) sitemap . add ( { url, ...page } )
105
+ if ( ! exclude . includes ( url ) ) {
106
+ sitemap . add ( {
107
+ url : withBase ( url ) ,
108
+ ...page
109
+ } )
110
+ }
104
111
} )
105
112
106
113
urls . forEach ( item => {
0 commit comments