Skip to content

Commit

Permalink
fix: base config ignored
Browse files Browse the repository at this point in the history
fixes #26
  • Loading branch information
ekoeryanto authored Nov 8, 2019
1 parent 376895f commit f3648c3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ module.exports = (options, context) => {

log('Generating sitemap...')

const { pages, locales } = context.getSiteData
const { pages, locales, base } = context.getSiteData
? context.getSiteData()
: context

const withBase = url => base.replace(/\/$/, '') + url

// Sort the locale keys in reverse order so that longer locales, such as '/en/', match before the default '/'
const localeKeys = (locales && Object.keys(locales).sort().reverse()) || []
const localesByNormalizedPagePath = pages.reduce((map, page) => {
Expand Down Expand Up @@ -75,7 +77,7 @@ module.exports = (options, context) => {
links = relatedLocales.map(localePrefix => {
return {
lang: locales[localePrefix].lang,
url: normalizedPath.replace('/', localePrefix)
url: withBase(normalizedPath.replace('/', localePrefix))
}
})
}
Expand All @@ -100,7 +102,12 @@ module.exports = (options, context) => {
})

pagesMap.forEach((page, url) => {
if (!exclude.includes(url)) sitemap.add({ url, ...page })
if (!exclude.includes(url)) {
sitemap.add({
url: withBase(url),
...page
})
}
})

urls.forEach(item => {
Expand Down

0 comments on commit f3648c3

Please sign in to comment.