infoalloggi-monorepo/apps/infoalloggi/src/pages/sitemap.xml.ts
Marco Pedone 699579b432 feat: update environment variable handling and dependencies
- Added @t3-oss/env-nextjs for improved environment variable management.
- Updated zod to version 4.1.12 for enhanced validation capabilities.
- Upgraded jiti to version 2.6.1 for better module loading.
- Refactored environment variable imports from env.mjs to env.ts.
- Removed deprecated env.mjs file and replaced it with a new env.ts file using @t3-oss/env-nextjs.
- Adjusted various components and API routes to utilize the new environment variable structure.
- Updated next.config.js to support the new environment variable management.
- Modified Docker configuration to align with new BASE_URL handling.
2025-10-20 16:22:20 +02:00

57 lines
1.9 KiB
TypeScript

import type { GetServerSideProps } from "next";
import { env } from "~/env";
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;
}