Files
astro-site-cerveau/scripts/build-carte-o.js
2026-05-11 15:04:53 +02:00

128 lines
3.1 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
function getRadius(niveau, nature) {
if (niveau === 0) return 28
if (niveau === 1) return 18
if (niveau === 2 && nature === 'projet') return 14
return 10
}
// compat backward : nature -> family
function getFamily(nature) {
return nature === 'projet' ? 'ressource' : 'concept'
}
// thematiques rattachees directement au centre (ni ncs-politique ni medecine-corps-social)
const CENTRE_THEMATIQUES = new Set([
'medias-critique',
'justice-securite',
'agriculture',
'urbanisme',
'geopolitique',
])
const NCS_THEMATIQUES = new Set([
'systemique',
'pratiques-collectives',
'pouvoir-domination',
'post-croissance',
'education',
])
const MDCS_THEMATIQUES = new Set([
'art-narration',
'sante-globale',
'spiritualite',
'ia-technologie',
'anthropocene',
])
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) {
const key = source < target ? `${source}|${target}` : `${target}|${source}`
if (edgeSet.has(key)) return
edgeSet.add(key)
edges.push({ source, target })
}
function addNode(obj) {
nodes.push({
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),
})
}
const centreId = data.centre.id
addNode(data.centre)
for (const cf of data.concepts_force) {
addNode(cf)
addEdge(centreId, cf.id)
}
for (const th of data.thematiques) {
addNode(th)
if (NCS_THEMATIQUES.has(th.id)) {
addEdge('ncs-politique', th.id)
} else if (MDCS_THEMATIQUES.has(th.id)) {
addEdge('medecine-corps-social', th.id)
} else if (CENTRE_THEMATIQUES.has(th.id)) {
addEdge(centreId, th.id)
}
}
for (const proj of data.projets) {
addNode(proj)
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)