Files
astro-site-cerveau/scripts/build-carte-o.js
T
Jules NenyandClaude Opus 5.5 fec977a58f feat(carte-o): brouillon des 17 accroches au survol (à valider par Jules)
Champ problematique ajouté aux 17 nodes de carte-o-source.yaml (source
éditoriale), propagé par build-carte-o.js, lu en priorité par l'infobulle
de CarteO.vue. Page temporaire /apercu-accroches pour la relecture :
À SUPPRIMER avant merge. Branche partie de wip/pont-tailwind4-20260817 :
ne pas merger telle quelle dans main (elle embarque le pont non validé),
cherry-pick de ce commit seul, sans la page d'aperçu.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SHuEiSieLhPY2uZbCu6uQb
2026-09-29 14:06:25 +02:00

115 lines
3.4 KiB
JavaScript

#!/usr/bin/env node
import fs from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import yaml from 'js-yaml'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const REPO_ROOT = path.resolve(__dirname, '..')
const SOURCE = path.join(REPO_ROOT, 'public/data/carte-o-source.yaml')
const OUTPUT = path.join(REPO_ROOT, 'public/data/carte-o.json')
// radius par niveau + nature (V1.2-N palette minimaliste)
function getRadius(niveau, nature) {
if (niveau === 0) return 30
if (nature === 'projet') return 18
if (niveau === 1) return 16
return 12
}
// compat backward : nature -> family
function getFamily(nature) {
return nature === 'projet' ? 'ressource' : 'concept'
}
// V1.2-N : noeud central fusionne -> toutes les thematiques sont rattachees au centre
// (les anciens groupes NCS_THEMATIQUES / MDCS_THEMATIQUES sont supprimes avec leurs sous-noeuds)
async function main() {
const raw = await fs.readFile(SOURCE, 'utf-8')
const data = yaml.load(raw)
const nodes = []
const edges = []
const edgeSet = new Set()
function addEdge(source, target, opts = {}) {
const key = source < target ? `${source}|${target}` : `${target}|${source}`
if (edgeSet.has(key)) return
edgeSet.add(key)
const edge = { source, target }
// V1.3-D : tag les edges au noeud central pour permettre tuning force-link
// (TMIP relie au centre = link court/fort, autres essais = link standard)
if (opts.central) edge.central = true
edges.push(edge)
}
function addNode(obj) {
const node = {
id: obj.id,
label: obj.label,
niveau: obj.niveau,
nature: obj.nature,
statut: obj.statut,
resume: obj.resume || null,
radius: getRadius(obj.niveau, obj.nature),
family: getFamily(obj.nature),
}
// V1.2-O : propage le champ optionnel domain (logo plateforme via Brandfetch CDN)
if (obj.domain) node.domain = obj.domain
// P3 §3 : accroche problematisee affichee au survol (une tension, pas une definition)
if (obj.problematique) node.problematique = obj.problematique
nodes.push(node)
}
const centreId = data.centre.id
addNode(data.centre)
// concepts_force vide en V1.2-N (fusionne dans le centre)
for (const cf of (data.concepts_force || [])) {
addNode(cf)
addEdge(centreId, cf.id)
}
// toutes les thematiques rattachees directement au noeud central
for (const th of data.thematiques) {
addNode(th)
addEdge(centreId, th.id, { central: true })
}
for (const proj of data.projets) {
addNode(proj)
// V1.3-D : edge explicite projet -> central (pont vision <-> pratique)
if (proj.lien_central) {
addEdge(centreId, proj.id, { central: true })
}
for (const thId of (proj.liens_thematiques || [])) {
addEdge(proj.id, thId)
}
}
await fs.mkdir(path.dirname(OUTPUT), { recursive: true })
await fs.writeFile(
OUTPUT,
JSON.stringify({
version: data.version,
generatedAt: new Date().toISOString(),
nodes,
edges,
}, null, 2),
'utf-8',
)
console.log(`[carte-o] OK : ${nodes.length} nodes / ${edges.length} edges -> ${OUTPUT}`)
}
main().catch(err => {
console.error('[carte-o] FAIL', err)
process.exit(1)
})
// V1 scrape vault - reactiver en V1.2 pour enrichissement automatique
// Source : scripts/build-carte-o.js@be7fc09 (scrape AEP/Articles globby + gray-matter + wikilinks edges)