SPB Git

Repository Public

sitemap.ts 2.8 KB 80 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Vrai-Prix8 * File             : src/app/estimation/sitemap.ts9 * Module           : app10 * Repository       : https://git.spboucher.ai/vrai-prix11 * Created          : 2026-08-1312 * Last Modified    : 2026-08-1313 *14 * Author           : Simon-Pierre Boucher15 * Position         : Professor of Finance16 * Institution      : Université du Québec en Outaouais (UQO)17 * Organization     : SP Boucher18 * Website          : https://spboucher.ai19 * Git              : https://git.spboucher.ai20 *21 * Preferred Contact: contact@spboucher.ai22 * Development      : dev@spboucher.ai23 * Support          : support@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Auteur : Simon-Pierre Boucher — contact@spboucher.ai43// Sitemaps des 3,7 M de fiches /estimation/[id], découpés par plages de rowid44// (contigus 1..N dans la DB). Servis à /estimation/sitemap/[id].xml.45import type { MetadataRoute } from "next";46import { getDb } from "@/lib/db";47import { SITE_URL } from "@/lib/seo";4849export const dynamic = "force-dynamic";5051/** 45 000 URLs par fichier (marge sous la limite de 50 000 du protocole). */52const CHUNK = 45_000;5354function maxRowid(): number {55  return (56    getDb().prepare("SELECT MAX(rowid) AS m FROM units").get() as { m: number }57  ).m;58}5960export async function generateSitemaps(): Promise<{ id: number }[]> {61  const n = Math.ceil(maxRowid() / CHUNK);62  return Array.from({ length: n }, (_, id) => ({ id }));63}6465export default async function sitemap(props: {66  id: Promise<string>;67}): Promise<MetadataRoute.Sitemap> {68  const id = Number(await props.id);69  const rows = getDb()70    .prepare(71      "SELECT id_provinc FROM units WHERE rowid > ? AND rowid <= ? ORDER BY rowid"72    )73    .all(id * CHUNK, (id + 1) * CHUNK) as { id_provinc: string }[];74  return rows.map((r) => ({75    url: `${SITE_URL}/estimation/${encodeURIComponent(r.id_provinc)}`,76    changeFrequency: "yearly",77    priority: 0.5,78  }));79}80
Files main
Menu

Theme