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() {
|
async function generateSiteMap() {
|
||||||
const helper = generateSSGHelper();
|
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 = [
|
const staticUrls = [
|
||||||
env.NEXT_PUBLIC_BASE_URL,
|
env.NEXT_PUBLIC_BASE_URL,
|
||||||
`${env.NEXT_PUBLIC_BASE_URL}/contatti`,
|
`${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">
|
<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
|
${allUrls
|
||||||
.map((url) => {
|
.map((url) => {
|
||||||
|
const escapedUrl = url
|
||||||
|
.replace(/&/g, "&")
|
||||||
|
.replace(/'/g, "'")
|
||||||
|
.replace(/"/g, """)
|
||||||
|
.replace(/>/g, ">")
|
||||||
|
.replace(/</g, "<");
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<url>
|
<url>
|
||||||
<loc>${url}</loc>
|
<loc>${escapedUrl}</loc>
|
||||||
<lastmod>${new Date().toISOString()}</lastmod>
|
<lastmod>${new Date().toISOString()}</lastmod>
|
||||||
<changefreq>hourly</changefreq>
|
<changefreq>hourly</changefreq>
|
||||||
<priority>0.7</priority>
|
<priority>0.7</priority>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue