Skip to content

Commit

Permalink
fix: only filter _sitemap with multi sitemaps
Browse files Browse the repository at this point in the history
Fixes #165
  • Loading branch information
harlan-zw committed Nov 13, 2023
1 parent 94a5214 commit e662cad
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/runtime/sitemap/builder/sitemap-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function buildSitemapIndex(resolvers: NitroUrlResolvers) {
enhancedUrls = applyI18nEnhancements(enhancedUrls, { isI18nMapped, autoI18n, sitemapName: sitemap.sitemapName })
// 3. filtered urls
// TODO make sure include and exclude start with baseURL?
const filteredUrls = filterSitemapUrls(enhancedUrls, sitemap)
const filteredUrls = filterSitemapUrls(enhancedUrls, { ...sitemap, autoI18n, isMultiSitemap: true })
// 4. sort
const sortedUrls = maybeSort(filteredUrls)
// split into the max size which should be 1000
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/sitemap/builder/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export async function buildSitemap(sitemap: SitemapDefinition, resolvers: NitroU
autoLastmod,
autoI18n,
isI18nMapped,
isMultiSitemap,
// sorting
sortEntries,
// chunking
Expand Down Expand Up @@ -117,7 +118,7 @@ export async function buildSitemap(sitemap: SitemapDefinition, resolvers: NitroU
enhancedUrls = applyI18nEnhancements(enhancedUrls, { isI18nMapped, autoI18n, sitemapName: sitemap.sitemapName })
// 3. filtered urls
// TODO make sure include and exclude start with baseURL?
const filteredUrls = filterSitemapUrls(enhancedUrls, { autoI18n, ...sitemap })
const filteredUrls = filterSitemapUrls(enhancedUrls, { isMultiSitemap, autoI18n, ...sitemap })
// 4. sort
const sortedUrls = maybeSort(filteredUrls)
// 5. maybe slice for chunked
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/sitemap/urlset/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ function createFilter(options: CreateFilterOptions = {}): (path: string) => bool
}
}

export function filterSitemapUrls(_urls: ResolvedSitemapUrl[], options: Pick<ModuleRuntimeConfig, 'autoI18n'> & Pick<SitemapDefinition, 'sitemapName' | 'include' | 'exclude'>) {
export function filterSitemapUrls(_urls: ResolvedSitemapUrl[], options: Pick<ModuleRuntimeConfig, 'autoI18n' | 'isMultiSitemap'> & Pick<SitemapDefinition, 'sitemapName' | 'include' | 'exclude'>) {
// base may be wrong here
const urlFilter = createFilter(options)
return _urls.filter((e) => {
if (e._sitemap && options.sitemapName)
if (options.isMultiSitemap && e._sitemap && options.sitemapName)
return e._sitemap === options.sitemapName
try {
const path = parseURL(e.loc).pathname
Expand Down

0 comments on commit e662cad

Please sign in to comment.