Skip to content

Commit f3648c3

Browse files
authoredNov 8, 2019
fix: base config ignored
fixes #26
1 parent 376895f commit f3648c3

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed
 

‎index.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ module.exports = (options, context) => {
3636

3737
log('Generating sitemap...')
3838

39-
const { pages, locales } = context.getSiteData
39+
const { pages, locales, base } = context.getSiteData
4040
? context.getSiteData()
4141
: context
4242

43+
const withBase = url => base.replace(/\/$/, '') + url
44+
4345
// Sort the locale keys in reverse order so that longer locales, such as '/en/', match before the default '/'
4446
const localeKeys = (locales && Object.keys(locales).sort().reverse()) || []
4547
const localesByNormalizedPagePath = pages.reduce((map, page) => {
@@ -75,7 +77,7 @@ module.exports = (options, context) => {
7577
links = relatedLocales.map(localePrefix => {
7678
return {
7779
lang: locales[localePrefix].lang,
78-
url: normalizedPath.replace('/', localePrefix)
80+
url: withBase(normalizedPath.replace('/', localePrefix))
7981
}
8082
})
8183
}
@@ -100,7 +102,12 @@ module.exports = (options, context) => {
100102
})
101103

102104
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+
}
104111
})
105112

106113
urls.forEach(item => {

0 commit comments

Comments
 (0)
Please sign in to comment.