Merged in fix/sitemap-fixes (pull request #2280)
fix:sitemap - added null check and correct content-type * fix:sitemap - added null check and correct content-type * Revert test code Approved-by: Erik Tiekstra
This commit is contained in:
@@ -20,10 +20,22 @@ export function mergeEntries(
|
||||
|
||||
const entries = [...currentEntries]
|
||||
newEntries.forEach((entry) => {
|
||||
const index = entries.findIndex(
|
||||
({ data }) =>
|
||||
data.uid === entry.data.uid && data.locale === entry.data.locale
|
||||
)
|
||||
if (!entry?.data?.uid || !entry?.data?.locale) {
|
||||
metricsEntriesMerge.dataError(
|
||||
`Invalid entry data, missing uid or locale`,
|
||||
{ entry }
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
const index = entries.findIndex(({ data }) => {
|
||||
if (!data) {
|
||||
metricsEntriesMerge.dataError(`Data is null or undefined,`)
|
||||
return false
|
||||
}
|
||||
|
||||
return data.uid === entry.data.uid && data.locale === entry.data.locale
|
||||
})
|
||||
if (index > -1) {
|
||||
entries[index] = entry
|
||||
} else {
|
||||
|
||||
@@ -49,6 +49,6 @@ export async function GET(
|
||||
const sitemapXML = `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">${entries.join("")}\n</urlset>`
|
||||
|
||||
return new Response(sitemapXML, {
|
||||
headers: { "Content-Type": "text/xml" },
|
||||
headers: { "Content-Type": "application/xml" },
|
||||
})
|
||||
}
|
||||
|
||||
@@ -33,6 +33,6 @@ export async function GET() {
|
||||
const sitemapIndexXML = `<?xml version="1.0" encoding="UTF-8"?>\n<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${urls.join("")}\n</sitemapindex>`
|
||||
|
||||
return new Response(sitemapIndexXML, {
|
||||
headers: { "Content-Type": "text/xml" },
|
||||
headers: { "Content-Type": "application/xml" },
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user