2025-10-06 19:23:28 +02:00
|
|
|
import type { GetServerSideProps } from "next";
|
2025-10-20 16:22:20 +02:00
|
|
|
import { env } from "~/env";
|
2026-01-20 18:38:17 +01:00
|
|
|
import { buildRicercaUrl } from "~/providers/RicercaProvider";
|
2025-10-06 19:23:28 +02:00
|
|
|
import { generateSSGHelper } from "~/server/utils/ssgHelper";
|
|
|
|
|
|
|
|
|
|
async function generateSiteMap() {
|
|
|
|
|
const helper = generateSSGHelper();
|
2026-01-23 13:55:44 +01:00
|
|
|
const codici = await helper.annunci.getCodici.fetch();
|
|
|
|
|
const dynamicUrls = codici.map((cod) => {
|
|
|
|
|
return `${env.NEXT_PUBLIC_BASE_URL}/annuncio/${cod}`;
|
|
|
|
|
});
|
2025-10-06 19:23:28 +02:00
|
|
|
const staticUrls = [
|
|
|
|
|
env.NEXT_PUBLIC_BASE_URL,
|
|
|
|
|
`${env.NEXT_PUBLIC_BASE_URL}/contatti`,
|
|
|
|
|
`${env.NEXT_PUBLIC_BASE_URL}/prezzi`,
|
|
|
|
|
`${env.NEXT_PUBLIC_BASE_URL}/chi-siamo`,
|
|
|
|
|
`${env.NEXT_PUBLIC_BASE_URL}/proprietari`,
|
|
|
|
|
`${env.NEXT_PUBLIC_BASE_URL}/guida`,
|
|
|
|
|
`${env.NEXT_PUBLIC_BASE_URL}/annunci`,
|
2026-01-20 18:38:17 +01:00
|
|
|
`${env.NEXT_PUBLIC_BASE_URL}${buildRicercaUrl({ tipo: "Transitorio" })}`,
|
|
|
|
|
`${env.NEXT_PUBLIC_BASE_URL}${buildRicercaUrl({ comune: "Bassano del Grappa" })}`,
|
|
|
|
|
`${env.NEXT_PUBLIC_BASE_URL}${buildRicercaUrl({ comune: "Bassano del Grappa", tipo: "Transitorio" })}`,
|
|
|
|
|
`${env.NEXT_PUBLIC_BASE_URL}${buildRicercaUrl({ tipo: "Stabile" })}`,
|
|
|
|
|
`${env.NEXT_PUBLIC_BASE_URL}${buildRicercaUrl({ comune: "Marostica" })}`,
|
2025-10-06 19:23:28 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const allUrls = [...staticUrls, ...dynamicUrls];
|
|
|
|
|
|
|
|
|
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
|
<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) => {
|
2026-01-23 13:55:44 +01:00
|
|
|
const escapedUrl = url
|
|
|
|
|
.replace(/&/g, "&")
|
|
|
|
|
.replace(/'/g, "'")
|
|
|
|
|
.replace(/"/g, """)
|
|
|
|
|
.replace(/>/g, ">")
|
|
|
|
|
.replace(/</g, "<");
|
|
|
|
|
|
2025-10-06 19:23:28 +02:00
|
|
|
return `
|
|
|
|
|
<url>
|
2026-01-23 13:55:44 +01:00
|
|
|
<loc>${escapedUrl}</loc>
|
2025-10-06 19:23:28 +02:00
|
|
|
<lastmod>${new Date().toISOString()}</lastmod>
|
|
|
|
|
<changefreq>hourly</changefreq>
|
|
|
|
|
<priority>0.7</priority>
|
|
|
|
|
</url>
|
|
|
|
|
`;
|
|
|
|
|
})
|
|
|
|
|
.join("")}
|
|
|
|
|
</urlset>
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-09 17:33:02 +01:00
|
|
|
/**
|
|
|
|
|
* Pagina sitemap: /sitemap.xml
|
|
|
|
|
*/
|
2025-10-06 19:23:28 +02:00
|
|
|
export const getServerSideProps = (async (context) => {
|
|
|
|
|
const sitemap = await generateSiteMap();
|
|
|
|
|
context.res.setHeader("Content-Type", "text/xml");
|
|
|
|
|
context.res.write(sitemap);
|
|
|
|
|
context.res.end();
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
props: {},
|
|
|
|
|
};
|
|
|
|
|
}) satisfies GetServerSideProps;
|
|
|
|
|
|
|
|
|
|
// You must export a React component as the default export, but it will not be rendered.
|
|
|
|
|
// Its sole purpose is to allow Next.js to compile the file as a Page.
|
|
|
|
|
export default function Sitemap() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|