Skip to content

Commit

Permalink
fix: merge multi sitemap defaults
Browse files Browse the repository at this point in the history
Fixes #107
  • Loading branch information
harlan-zw committed Jul 30, 2023
1 parent 90b4c48 commit 8d8fa6f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/runtime/sitemap/entries/normalise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function normaliseSitemapData(data: SitemapEntryInput[], options: B
return options.canonicalUrlResolver(s)
}

const defaultEntryData = { ...defaults || {} }
const defaultEntryData = defu(options.sitemap?.defaults, defaults)
if (autoLastmod)
defaultEntryData.lastmod = defaultEntryData.lastmod || new Date()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,36 @@ import { $fetch, setup } from '@nuxt/test-utils'
const { resolve } = createResolver(import.meta.url)

await setup({
rootDir: resolve('../.playground'),
build: true,
server: true,
rootDir: resolve('../../fixtures/basic'),
nuxtConfig: {
sitemap: {
credits: false,
sitemaps: {
foo: {
include: ['/foo/*'],
dynamicUrlsApiEndpoint: '/api/multi-sitemap-sources/foo',
urls: [
'/foo/1',
'/foo/2',
],
defaults: {
changefreq: 'weekly',
priority: 0.7,
},
},
bar: {
include: ['/bar/*'],
dynamicUrlsApiEndpoint: '/api/multi-sitemap-sources/bar',
urls: [
'/bar/1',
'/bar/2',
],
defaults: {
changefreq: 'monthly',
priority: 0.5,
},
},
},
sitemapName: 'test.xml',
siteUrl: 'https://nuxtseo.com',
},
},
})
describe('multiEndpoints', () => {
describe('mutli defaults', () => {
it('basic', async () => {
let sitemap = await $fetch('/foo-sitemap.xml')
// remove lastmods before tresting
Expand All @@ -36,25 +44,15 @@ describe('multiEndpoints', () => {
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><?xml-stylesheet type=\\"text/xsl\\" href=\\"/__sitemap__/style.xsl\\"?>
<urlset xmlns:xsi=\\"http://www.w3.org/2001/XMLSchema-instance\\" xmlns:video=\\"http://www.google.com/schemas/sitemap-video/1.1\\" xmlns:xhtml=\\"http://www.w3.org/1999/xhtml\\" xmlns:image=\\"http://www.google.com/schemas/sitemap-image/1.1\\" xsi:schemaLocation=\\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-image/1.1 http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd\\" xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\">
<url>
<lastmod></lastmod>
<changefreq>weekly</changefreq>
<priority>0.7</priority>
<loc>https://nuxtseo.com/foo/1</loc>
</url>
<url>
<lastmod></lastmod>
<changefreq>weekly</changefreq>
<priority>0.7</priority>
<loc>https://nuxtseo.com/foo/2</loc>
</url>
<url>
<lastmod></lastmod>
<loc>https://nuxtseo.com/foo/3</loc>
</url>
<url>
<lastmod></lastmod>
<loc>https://nuxtseo.com/foo/4</loc>
</url>
<url>
<lastmod></lastmod>
<loc>https://nuxtseo.com/foo/5</loc>
</url>
</urlset>"
`)
}, 60000)
Expand Down

0 comments on commit 8d8fa6f

Please sign in to comment.