SPB Git forge

spb/toveli

Public
14commits 1branches 0releases
1.1 MBsize
maindefault branch
2 h agolast push
TypeScript 50.6% JavaScript 46.1% SQL 2.1% Shell 0.6% CSS 0.5%
1.6 KB · 13 lines typescript
Raw Blame History
1import type { MetadataRoute } from "next";2import { dbAvailable, getDb } from "@/lib/db";3export const dynamic = "force-dynamic";4export default function sitemap(): MetadataRoute.Sitemap {5  const base = "https://www.toveli.ca"; const now = new Date();6  const fixed: MetadataRoute.Sitemap = ["", "/recherche?marche=achat", "/recherche?marche=location", "/carte", "/estimer", "/marche", "/financement", "/methodologie", "/assistant"].map((p) => ({ url: base + p, lastModified: now, changeFrequency: "daily", priority: p === "" ? 1 : 0.7 }));7  if (!dbAvailable()) return fixed;8  const cities = getDb().prepare("SELECT name, n_sale, n_rent FROM place WHERE kind='city' AND (n_sale >= 20 OR n_rent >= 20)").all() as { name: string; n_sale: number; n_rent: number }[];9  const cityUrls: MetadataRoute.Sitemap = cities.flatMap((c) => [...(c.n_sale >= 20 ? [{ url: `${base}/recherche?marche=achat&ville=${encodeURIComponent(c.name)}`, lastModified: now, changeFrequency: "daily" as const, priority: 0.6 }] : []), ...(c.n_rent >= 20 ? [{ url: `${base}/recherche?marche=location&ville=${encodeURIComponent(c.name)}`, lastModified: now, changeFrequency: "daily" as const, priority: 0.6 }] : [])]);10  const listings = getDb().prepare("SELECT uid, last_seen FROM listing WHERE image_count > 0 AND quality_score >= 70 ORDER BY first_seen DESC LIMIT 20000").all() as { uid: string; last_seen: string | null }[];11  return [...fixed, ...cityUrls, ...listings.map((l) => ({ url: `${base}/annonce/${encodeURIComponent(l.uid)}`, lastModified: l.last_seen ? new Date(l.last_seen) : now, changeFrequency: "weekly" as const, priority: 0.5 }))];12}13