Skip to content

Commit

Permalink
fix: avoid duplicate sitemap entries
Browse files Browse the repository at this point in the history
Fixes #3
  • Loading branch information
harlan-zw committed Jan 5, 2023
1 parent 21e2f69 commit cfde25e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ declare module 'nitropack' {
nitro.options.prerender.routes = nitro.options.prerender.routes || []
nitro.options.prerender.routes.push('/sitemap.xml')

let sitemapRoutes: string[] = []
const sitemapRoutes = new Set<string>()

const outputSitemap = async () => {
if (sitemapRoutes.length === 0)
if (sitemapRoutes.size === 0)
return

const start = Date.now()
Expand All @@ -111,7 +111,7 @@ declare module 'nitropack' {
// @ts-expect-error untyped
const fixSlashes = (url: string) => nuxt.options.sitemap?.trailingSlash ? withTrailingSlash(url) : withoutTrailingSlash(url)

const urls = sitemapRoutes
const urls = [...sitemapRoutes]
// filter for config
.filter(urlFilter)
// fix order
Expand Down Expand Up @@ -140,13 +140,13 @@ declare module 'nitropack' {
nitro.logger.log(chalk.gray(
` └─ /sitemap.xml (${generateTimeMS}ms)`,
))
sitemapRoutes = []
sitemapRoutes.clear()
}

nitro.hooks.hook('prerender:route', async ({ route }) => {
// check if the route path is not for a file
if (!route.includes('.'))
sitemapRoutes.push(route)
sitemapRoutes.add(route)
})

// SSR mode
Expand Down

0 comments on commit cfde25e

Please sign in to comment.