diff --git a/components/MediaTabProjets.vue b/components/MediaTabProjets.vue index 6acc791..3e98723 100644 --- a/components/MediaTabProjets.vue +++ b/components/MediaTabProjets.vue @@ -8,25 +8,31 @@

-
-
- -
📐
- -

{{ p.titre }}

-

- {{ (p.auteurs || []).filter((a: string) => a !== 'Inconnu').join(', ') }} - - -

-

{{ p.description }}

- - - DĂ©couvrir → + +
-
+ +

Tu as un PFE engagĂ© Ă  partager ? Écris-moi. @@ -35,33 +41,144 @@ diff --git a/package.json b/package.json index c5e116a..00c55be 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "dev": "nuxt dev", "generate": "nuxt generate", "preview": "nuxt preview", - "test": "node scripts/test-echelles-nav.mjs && node scripts/test-figures.mjs && node scripts/test-vue-fiches.mjs && node scripts/test-submit-libre.mjs && node scripts/test-circuit-breaker.mjs && node scripts/test-bandeau.mjs && node scripts/test-outils-data.mjs && node scripts/test-citations.mjs && node scripts/test-seo.mjs && node scripts/test-y.mjs && node scripts/test-connaissances.mjs && node --test \"worker/test/*.test.js\"", + "test": "node scripts/test-echelles-nav.mjs && node scripts/test-figures.mjs && node scripts/test-vue-fiches.mjs && node scripts/test-submit-libre.mjs && node scripts/test-circuit-breaker.mjs && node scripts/test-bandeau.mjs && node scripts/test-outils-data.mjs && node scripts/test-citations.mjs && node scripts/test-seo.mjs && node scripts/test-y.mjs && node scripts/test-connaissances.mjs && node scripts/test-media-data.mjs && node --test \"worker/test/*.test.js\"", "postinstall": "nuxt prepare" }, "dependencies": { diff --git a/scripts/test-media-data.mjs b/scripts/test-media-data.mjs new file mode 100644 index 0000000..62aed75 --- /dev/null +++ b/scripts/test-media-data.mjs @@ -0,0 +1,66 @@ +#!/usr/bin/env node +/** + * Test des donnĂ©es de l'onglet « Publications » (/media?tab=projets, lot XL publications). + * Six projets, auteurs nommĂ©s, jamais « Inconnu », une illustration WebP ≀ 60 Ko par projet, + * et la carte entiĂšre comme seul lien. + * Usage : node scripts/test-media-data.mjs + */ + +import { readFileSync, existsSync, statSync } from 'node:fs' +import { fileURLToPath } from 'node:url' +import { dirname, join } from 'node:path' + +const racine = join(dirname(fileURLToPath(import.meta.url)), '..') +const echecs = [] +let n = 0 +function verifie(ok, message) { + n++ + if (!ok) echecs.push(message) +} + +const { projets } = JSON.parse(readFileSync(join(racine, 'public/data/pfe-engages.json'), 'utf8')) +verifie(Array.isArray(projets) && projets.length === 6, `six projets attendus, ${projets?.length} trouvĂ©s`) +verifie(new Set(projets.map(p => p.id)).size === projets.length, 'identifiants en double') + +const MAX = 60 * 1024 +for (const p of projets) { + const id = p.id + verifie(Array.isArray(p.auteurs) && p.auteurs.length > 0, `${id} : auteurs vides`) + verifie((p.auteurs || []).every(a => typeof a === 'string' && a.trim()), `${id} : un auteur vide`) + verifie(!JSON.stringify(p).includes('Inconnu'), `${id} : « Inconnu » encore prĂ©sent`) + verifie(p.ecole === null || (typeof p.ecole === 'string' && p.ecole.trim()), `${id} : Ă©cole ni nulle ni renseignĂ©e`) + verifie(typeof p.url === 'string' && /^https?:\/\//.test(p.url), `${id} : url absente`) + verifie(typeof p.illustration === 'string' && p.illustration === `/medias/publications/${id}.webp`, + `${id} : illustration attendue en /medias/publications/${id}.webp`) + const fichier = join(racine, 'public', p.illustration || '') + verifie(existsSync(fichier), `${id} : fichier ${p.illustration} absent`) + if (existsSync(fichier)) { + const poids = statSync(fichier).size + verifie(poids <= MAX, `${id} : ${poids} o, au-dessus de 60 Ko`) + const tete = readFileSync(fichier).subarray(0, 12).toString('latin1') + verifie(tete.startsWith('RIFF') && tete.slice(8) === 'WEBP', `${id} : le fichier n'est pas un WebP`) + } + verifie(p.illustration_a_venir === true || (typeof p.credit_illustration === 'string' && p.credit_illustration.trim()), + `${id} : une image tirĂ©e du projet doit porter son crĂ©dit`) +} + +// Seine nature urbaine : site « tous droits rĂ©servĂ©s », placeholder tant que l'auteur n'a pas donnĂ© son accord. +const seine = projets.find(p => p.id === 'seine-nature') +verifie(seine?.illustration_a_venir === true, 'seine-nature : placeholder obligatoire (accord de l\'auteur en attente)') + +// Composant : la carte entiĂšre est le seul lien, plus de « DĂ©couvrir → » en second lien. +const vue = readFileSync(join(racine, 'components/MediaTabProjets.vue'), 'utf8') +const gabarit = vue.slice(vue.indexOf('')) +const grille = gabarit.slice(gabarit.indexOf('projets-grid'), gabarit.indexOf('')) +verifie((grille.match(/ par carte dans la grille') +verifie(/class="projet-carte"/.test(grille), 'la carte porte la classe projet-carte') +verifie(!/[↗→·]/.test(gabarit), 'ni flĂšche ni point mĂ©dian dans le gabarit') +verifie(/loading="lazy"/.test(grille) && /width="800"/.test(grille) && /height="600"/.test(grille), + 'image en lazy avec width et height posĂ©s') + +if (echecs.length) { + for (const e of echecs) console.log(`FAIL ${e}`) + console.log(`\n${n - echecs.length}/${n} vĂ©rifications OK — ${echecs.length} Ă©chec(s)`) + process.exit(1) +} +console.log(`${n} vĂ©rifications OK`)