fix: escape URLs in sitemap generation to ensure valid XML output
This commit is contained in:
parent
d592c78216
commit
ab3b109652
1 changed files with 12 additions and 2 deletions
|
|
@ -5,7 +5,10 @@ import { generateSSGHelper } from "~/server/utils/ssgHelper";
|
|||
|
||||
async function generateSiteMap() {
|
||||
const helper = generateSSGHelper();
|
||||
const dynamicUrls = await helper.annunci.getCodici.fetch();
|
||||
const codici = await helper.annunci.getCodici.fetch();
|
||||
const dynamicUrls = codici.map((cod) => {
|
||||
return `${env.NEXT_PUBLIC_BASE_URL}/annuncio/${cod}`;
|
||||
});
|
||||
const staticUrls = [
|
||||
env.NEXT_PUBLIC_BASE_URL,
|
||||
`${env.NEXT_PUBLIC_BASE_URL}/contatti`,
|
||||
|
|
@ -27,9 +30,16 @@ async function generateSiteMap() {
|
|||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
|
||||
${allUrls
|
||||
.map((url) => {
|
||||
const escapedUrl = url
|
||||
.replace(/&/g, "&")
|
||||
.replace(/'/g, "'")
|
||||
.replace(/"/g, """)
|
||||
.replace(/>/g, ">")
|
||||
.replace(/</g, "<");
|
||||
|
||||
return `
|
||||
<url>
|
||||
<loc>${url}</loc>
|
||||
<loc>${escapedUrl}</loc>
|
||||
<lastmod>${new Date().toISOString()}</lastmod>
|
||||
<changefreq>hourly</changefreq>
|
||||
<priority>0.7</priority>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue