From 746848880901df631f2aa3a5c5b737c704f086c2 Mon Sep 17 00:00:00 2001 From: Emile Rolley Date: Wed, 6 Nov 2024 18:31:22 +0100 Subject: [PATCH] fix: use data from @betagouv/aides-velo instead of local communes.json file --- retrofit/routes/api/ville/+server.js | 4 ++-- src/routes/(front)/sitemap.txt/+server.js | 6 ++++-- src/routes/api/collectivites/+server.js | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/retrofit/routes/api/ville/+server.js b/retrofit/routes/api/ville/+server.js index d8cea15..84ad53b 100644 --- a/retrofit/routes/api/ville/+server.js +++ b/retrofit/routes/api/ville/+server.js @@ -1,10 +1,10 @@ -import data from '$lib/data/communes.json'; +import { data } from '@betagouv/aides-velo'; import { error } from '@sveltejs/kit'; import { rawCityToFullLocalisation } from '$lib/utils'; export function GET({ url }) { const slug = url.searchParams.get('slug'); - const ville = data.find((v) => v.slug === slug); + const ville = data.communes.find((v) => v.slug === slug); if (!ville) { error(404); } diff --git a/src/routes/(front)/sitemap.txt/+server.js b/src/routes/(front)/sitemap.txt/+server.js index 653827a..23b8d74 100644 --- a/src/routes/(front)/sitemap.txt/+server.js +++ b/src/routes/(front)/sitemap.txt/+server.js @@ -1,4 +1,4 @@ -import communes from '$lib/data/communes.json'; +import { data } from '@betagouv/aides-velo'; import { _departementWithSlug } from '../departement/[slug]/+page.server'; /** @type {import('./$types').RequestHandler} */ @@ -10,7 +10,9 @@ export async function GET() { '/forfait-mobilite-durable', '/liste-aides', ..._departementWithSlug.map(({ slug }) => `/departement/${slug}`), - ...communes.sort((a, b) => b.population - a.population).map(({ slug }) => `/ville/${slug}`), + ...data.communes + .sort((a, b) => b.population - a.population) + .map(({ slug }) => `/ville/${slug}`), ] .map((path) => `https://mesaidesvelo.fr${path}`) .join('\n'), diff --git a/src/routes/api/collectivites/+server.js b/src/routes/api/collectivites/+server.js index 5d4c451..3a58dc4 100644 --- a/src/routes/api/collectivites/+server.js +++ b/src/routes/api/collectivites/+server.js @@ -12,10 +12,10 @@ // l'utilisateur. import { rawCityToFullLocalisation, removeAccents } from '$lib/utils'; +import { data } from '@betagouv/aides-velo'; import fuzzysort from 'fuzzysort'; -import data from '$lib/data/communes.json'; -const indexedData = data.flatMap(({ codesPostaux, ...rest }) => +const indexedData = data.communes.flatMap(({ codesPostaux, ...rest }) => codesPostaux.map((codePostal, i) => { const cpPrincipal = i === 0; return {