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";
|
2025-10-06 19:23:28 +02:00
|
|
|
import { generateSSGHelper } from "~/server/utils/ssgHelper";
|
|
|
|
|
|
|
|
|
|
async function generateSiteMap() {
|
|
|
|
|
const helper = generateSSGHelper();
|
|
|
|
|
const dynamicUrls = await helper.annunci.getCodici.fetch();
|
|
|
|
|
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`,
|
|
|
|
|
`${env.NEXT_PUBLIC_BASE_URL}/annunci?tipo=Transitorio`,
|
|
|
|
|
`${env.NEXT_PUBLIC_BASE_URL}/annunci?comune=Bassano+del+Grappa`,
|
|
|
|
|
`${env.NEXT_PUBLIC_BASE_URL}/annunci?tipo=Stabile`,
|
|
|
|
|
`${env.NEXT_PUBLIC_BASE_URL}/annunci?comune=Marostica`,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
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) => {
|
|
|
|
|
return `
|
|
|
|
|
<url>
|
|
|
|
|
<loc>${url}</loc>
|
|
|
|
|
<lastmod>${new Date().toISOString()}</lastmod>
|
|
|
|
|
<changefreq>hourly</changefreq>
|
|
|
|
|
<priority>0.7</priority>
|
|
|
|
|
</url>
|
|
|
|
|
`;
|
|
|
|
|
})
|
|
|
|
|
.join("")}
|
|
|
|
|
</urlset>
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|