diff --git a/.gitignore b/.gitignore index 1193d0f..61da5fc 100644 --- a/.gitignore +++ b/.gitignore @@ -6,10 +6,11 @@ node_modules .env .vercel_build_output/ .vercel +local/ *.tmp *.tmp.* data-fetch/miniatures/aides-jeunes-repo # Generated at build time -src/data -src/lib/data +src/lib/data/* +!src/lib/data/classement-villeplus.json diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..08d1517 Binary files /dev/null and b/bun.lockb differ diff --git a/data-fetch/maj-villesplus.js b/data-fetch/maj-villesplus.js new file mode 100644 index 0000000..06e4c45 --- /dev/null +++ b/data-fetch/maj-villesplus.js @@ -0,0 +1,28 @@ +import { JSDOM } from 'jsdom'; +import epci from '@etalab/decoupage-administratif/data/epci.json' assert { type: 'json' }; +import { slugify } from '../src/lib/utils.js'; +import { writeJsonData } from '../src/scripts/writeData.js'; + +const source = await fetch('https://www.villes.plus/cyclables/metropoles'); +const { document } = new JSDOM(await source.text()).window; + +const rawMetropoles = [...document.querySelectorAll('h3')].map((h3) => h3.textContent); + +const simplify = (s) => + slugify(s) + .replace(/[0-9]/g, '') + .replace(/((euro)?metropole|de|)/g, '') + .replace(/(^-+|-+$)/g, ''); + +const normalizedEpciNames = rawMetropoles.map( + (line) => epci.find(({ nom }) => simplify(nom).includes(simplify(line)))?.nom +); + +if (normalizedEpciNames.find((n) => !n)) { + console.log('❌ Missing EPCI:'); + console.log(normalizedEpciNames.filter(Boolean).join('\n')); +} else { + console.log("✅ All EPCI's found:"); + console.log(normalizedEpciNames.join('\n')); + writeJsonData('classement-villeplus.json', normalizedEpciNames); +} diff --git a/data-fetch/villes.plus/index.js b/data-fetch/villes.plus/index.js deleted file mode 100644 index 1541838..0000000 --- a/data-fetch/villes.plus/index.js +++ /dev/null @@ -1,34 +0,0 @@ -import epci from '@etalab/decoupage-administratif/data/epci.json' assert { type: 'json' }; -import { slugify } from '../../src/lib/utils.js'; -import { writeJsonData } from '../../src/scripts/writeData.js'; - -// TODO: récupérer ce classement depuis le dépôt ville.plus -const rawClassement = ` -Bordeaux Métropole -Eurométropole de Strasbourg -Toulouse Métropole -Montpellier Méditerranée Métropole -Orléans Métropole -Grenoble-Alpes Métropole -Rennes Métropole -Tours Métropole Val de Loire -Nantes Métropole -Clermont Auvergne Métropole -Métropole du Grand Paris -Métropole de Lyon -Métropole du Grand Nancy -Métropole Européenne de Lille -Brest Métropole -Métropole Rouen Normandie -Metz Métropole -Aix-Marseille-Provence -Nice Côte d'Azur -Saint-Étienne Métropole -`; - -const normalizedEpciNames = rawClassement - .split('\n') - .filter((l) => Boolean(l.trim())) - .map((line) => epci.find(({ nom }) => slugify(nom).includes(slugify(line)))?.nom); - -writeJsonData('classement-villeplus.json', normalizedEpciNames); diff --git a/jsconfig.json b/jsconfig.json deleted file mode 100644 index 2e7e4e3..0000000 --- a/jsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "./.svelte-kit/mesaidesvelo.fr/tsconfig.json" -} diff --git a/package.json b/package.json index 4f67a8c..77cd22a 100644 --- a/package.json +++ b/package.json @@ -1,48 +1,49 @@ { - "name": "mesaidesvelo", - "version": "1.0.0", - "scripts": { - "postinstall": "node ./src/scripts/postinstall.js", - "dev": "VITE_SITE=mesaidesvelo.fr vite dev", - "dev:retrofit": "VITE_SITE=aideretrofit.fr vite dev", - "build": "VITE_SITE=mesaidesvelo.fr vite build", - "build:retrofit": "VITE_SITE=aideretrofit.fr vite build", - "preview": "VITE_SITE=mesaidesvelo.fr vite preview", - "sync-entreprises": "node ./data-fetch/entreprises/download-gsheet-data.js", - "sync": "svelte-kit sync", - "test": "npm run test:playwright && npm run test:vitest -- run", - "test:playwright": "npx playwright test tests/navigation.spec.js", - "test:vitest": "vitest", - "lint": "prettier --ignore-path .gitignore --check --plugin-search-dir=. .", - "format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. ." - }, - "type": "module", - "private": true, - "devDependencies": { - "@actions/core": "^1.10.0", - "@actions/github": "^5.1.1", - "@playwright/test": "^1.35.1", - "@rollup/plugin-yaml": "^4.1.1", - "@sveltejs/adapter-vercel": "^3.0.1", - "@sveltejs/kit": "^1.21.0", - "mdsvex": "^0.11.0", - "node-fetch": "^3.3.1", - "prettier": "^2.8.8", - "prettier-plugin-svelte": "^2.10.1", - "sharp": "=0.32.1", - "svelte": "^4.0.1", - "typescript": "^5.1.6", - "vite": "^4.3.9", - "vite-plugin-windicss": "^1.9.0", - "vitest": "^0.32.2", - "wget-improved": "^3.4.0", - "yaml": "^2.3.1" - }, - "dependencies": { - "@etalab/decoupage-administratif": "^3.0.0", - "fuzzysort": "^2.0.4", - "playwright-aws-lambda": "^0.10.0", - "playwright-core": "^1.35.1", - "publicodes": "^1.0.0-beta.70" - } + "name": "mesaidesvelo", + "version": "1.0.0", + "scripts": { + "postinstall": "node ./src/scripts/postinstall.js", + "dev": "VITE_SITE=mesaidesvelo.fr vite dev", + "dev:retrofit": "VITE_SITE=aideretrofit.fr vite dev", + "build": "VITE_SITE=mesaidesvelo.fr vite build", + "build:retrofit": "VITE_SITE=aideretrofit.fr vite build", + "preview": "VITE_SITE=mesaidesvelo.fr vite preview", + "sync-entreprises": "node ./data-fetch/entreprises/download-gsheet-data.js", + "sync": "svelte-kit sync", + "test": "npm run test:playwright && npm run test:vitest -- run", + "test:playwright": "npx playwright test tests/navigation.spec.js", + "test:vitest": "vitest", + "lint": "prettier --ignore-path .gitignore --check --plugin-search-dir=. .", + "format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. ." + }, + "type": "module", + "private": true, + "devDependencies": { + "@actions/core": "^1.10.0", + "@actions/github": "^5.1.1", + "@playwright/test": "^1.35.1", + "@rollup/plugin-yaml": "^4.1.1", + "@sveltejs/adapter-vercel": "^3.0.1", + "@sveltejs/kit": "^1.21.0", + "mdsvex": "^0.11.0", + "node-fetch": "^3.3.1", + "prettier": "^2.8.8", + "prettier-plugin-svelte": "^2.10.1", + "sharp": "=0.32.1", + "svelte": "^4.0.1", + "typescript": "^5.1.6", + "vite": "^4.3.9", + "vite-plugin-windicss": "^1.9.0", + "vitest": "^0.32.2", + "wget-improved": "^3.4.0", + "yaml": "^2.3.1" + }, + "dependencies": { + "@etalab/decoupage-administratif": "^3.0.0", + "fuzzysort": "^2.0.4", + "jsdom": "^22.1.0", + "playwright-aws-lambda": "^0.10.0", + "playwright-core": "^1.35.1", + "publicodes": "^1.0.0-beta.70" + } } diff --git a/src/lib/data/classement-villeplus.json b/src/lib/data/classement-villeplus.json new file mode 100644 index 0000000..4e2cf32 --- /dev/null +++ b/src/lib/data/classement-villeplus.json @@ -0,0 +1,24 @@ +[ + "Eurométropole de Strasbourg", + "Bordeaux Métropole", + "Grenoble-Alpes-Métropole", + "Toulouse Métropole", + "Montpellier Méditerranée Métropole", + "Métropole Toulon-Provence-Méditerranée", + "Orléans Métropole", + "CC du Bassin de Marennes", + "Métropole du Grand Paris", + "CC de la Plaine Dijonnaise", + "Métropole de Lyon", + "Tours Métropole Val de Loire", + "Nantes Métropole", + "Brest Métropole", + "Métropole du Grand Nancy", + "Métropole Européenne de Lille", + "Clermont Auvergne Métropole", + "Metz Métropole", + "Métropole Rouen Normandie", + "Métropole Nice Côte d'Azur", + "Métropole d'Aix-Marseille-Provence", + "Saint-Etienne Métropole" +] \ No newline at end of file diff --git a/src/routes/(front)/(search)/ville/[slug]/+page.server.js b/src/routes/(front)/(search)/ville/[slug]/+page.server.js index 9127c44..96c83ae 100644 --- a/src/routes/(front)/(search)/ville/[slug]/+page.server.js +++ b/src/routes/(front)/(search)/ville/[slug]/+page.server.js @@ -153,7 +153,16 @@ export async function load({ params }) { }; } - infos.classementVillePlus = classementVilleplus.findIndex((epci) => epci === localisation.epci); + const posClassementVillePlus = classementVilleplus.findIndex( + (epci) => epci === localisation.epci + ); + + if (posClassementVillePlus > -1) { + infos.classementVillePlus = { + position: posClassementVillePlus + 1, + total: classementVilleplus.length, + }; + } if (barometreFubPerCity[localisation.codeInsee]) { const labelsFub = { diff --git a/src/routes/(front)/(search)/ville/[slug]/ExplanationsText.svelte b/src/routes/(front)/(search)/ville/[slug]/ExplanationsText.svelte index 80a2a56..765c6cb 100644 --- a/src/routes/(front)/(search)/ville/[slug]/ExplanationsText.svelte +++ b/src/routes/(front)/(search)/ville/[slug]/ExplanationsText.svelte @@ -254,11 +254,12 @@ Vous pouvez consultez le détail des notes sur le site du baromètre.
- {#if infos.classementVillePlus > -1} + {#if infos.classementVillePlus}- Par ailleurs {leEPCI} se classe {infos.classementVillePlus + 1}{infos.classementVillePlus === 0 ? 'ère' : 'ème'}/20 au classement ville.plus des villes cyclables. + Par ailleurs {leEPCI} se classe {infos.classementVillePlus.position}{infos.classementVillePlus.position === 1 ? 'ère' : 'ème'}/{infos.classementVillePlus.total} au + classement ville.plus des villes cyclables. Ce classement mesure la part de pistes cyclables sécurisées pour relier les différentes mairies de la métropole.
diff --git a/src/scripts/postinstall.js b/src/scripts/postinstall.js index b8e276a..79d088a 100644 --- a/src/scripts/postinstall.js +++ b/src/scripts/postinstall.js @@ -1,4 +1,3 @@ await import('./transform-communes-data.js'); await import('./associate-collectivities.js'); await import('../../data-fetch/miniatures/extract-from-aides-jeunes.js'); -await import('../../data-fetch/villes.plus/index.js'); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..1cb7523 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "./.svelte-kit/mesaidesvelo.fr/tsconfig.json", + "compilerOptions": { + "types": ["bun-types"] + } +}