Repository Public
1// Auteur : Simon-Pierre Boucher — contact@spboucher.ai2// Sitemaps des 3,7 M de fiches /estimation/[id], découpés par plages de rowid3// (contigus 1..N dans la DB). Servis à /estimation/sitemap/[id].xml.4import type { MetadataRoute } from "next";5import { getDb } from "@/lib/db";6import { SITE_URL } from "@/lib/seo";78export const dynamic = "force-dynamic";910/** 45 000 URLs par fichier (marge sous la limite de 50 000 du protocole). */11const CHUNK = 45_000;1213function maxRowid(): number {14 return (15 getDb().prepare("SELECT MAX(rowid) AS m FROM units").get() as { m: number }16 ).m;17}1819export async function generateSitemaps(): Promise<{ id: number }[]> {20 const n = Math.ceil(maxRowid() / CHUNK);21 return Array.from({ length: n }, (_, id) => ({ id }));22}2324export default async function sitemap(props: {25 id: Promise<string>;26}): Promise<MetadataRoute.Sitemap> {27 const id = Number(await props.id);28 const rows = getDb()29 .prepare(30 "SELECT id_provinc FROM units WHERE rowid > ? AND rowid <= ? ORDER BY rowid"31 )32 .all(id * CHUNK, (id + 1) * CHUNK) as { id_provinc: string }[];33 return rows.map((r) => ({34 url: `${SITE_URL}/estimation/${encodeURIComponent(r.id_provinc)}`,35 changeFrequency: "yearly",36 priority: 0.5,37 }));38}39