Files
Talks/tools/sync-portal.mjs
Le Prévost-Corvellec Arnault 354c8cd9ef Add Makefile, package.json, and initial configuration for VitePress and Slidev integration
- Introduced a Makefile for streamlined commands related to building, running, and managing presentations.
- Created package.json to define project metadata, dependencies, and scripts for development and testing.
- Added .gitignore entries to exclude build artifacts and temporary files from version control.
- Included playwright.config.mjs for end-to-end testing setup with Playwright.
- Added README.md for project documentation, outlining setup instructions and development guidelines.
2026-04-11 15:59:20 +02:00

68 lines
2.4 KiB
JavaScript

#!/usr/bin/env node
/**
* Lit chaque slides/<slug>/meta.json, écrit presentations.json, index featured, liste + fiches.
* Retire les fiches portal obsolètes.
*
* TALKS_ROOT (optionnel) : racine du dépôt — tests.
*/
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { sitePath } from './site-base.mjs'
import {
readAllMeta,
generateListPageMarkdown,
generateDetailPageMarkdown,
patchIndexFeaturedContent,
} from './presentation-contracts.mjs'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const root = process.env.TALKS_ROOT ? path.resolve(process.env.TALKS_ROOT) : path.resolve(__dirname, '..')
const slidesRoot = path.join(root, 'slides')
const portalData = path.join(root, 'portal', '.vitepress', 'data')
const presentationsDir = path.join(root, 'portal', 'presentations')
function pruneStalePresentationDirs(items) {
const keep = new Set(items.map((p) => p.slug))
if (!fs.existsSync(presentationsDir)) return
for (const d of fs.readdirSync(presentationsDir, { withFileTypes: true })) {
if (!d.isDirectory()) continue
if (!keep.has(d.name)) {
fs.rmSync(path.join(presentationsDir, d.name), { recursive: true, force: true })
console.warn(`[sync] fiche retirée (plus de slides/${d.name}/): presentations/${d.name}/`)
}
}
}
function main() {
const items = readAllMeta(slidesRoot)
fs.mkdirSync(portalData, { recursive: true })
fs.writeFileSync(path.join(portalData, 'presentations.json'), JSON.stringify(items, null, 2), 'utf8')
const indexPath = path.join(root, 'portal', 'index.md')
if (fs.existsSync(indexPath)) {
const raw = fs.readFileSync(indexPath, 'utf8')
const { ok, content } = patchIndexFeaturedContent(raw, items, sitePath)
if (!ok) {
console.warn('[sync] marqueurs FEATURED_START / FEATURED_END absents ou invalides dans portal/index.md')
} else {
fs.writeFileSync(indexPath, content, 'utf8')
}
}
fs.mkdirSync(presentationsDir, { recursive: true })
fs.writeFileSync(path.join(presentationsDir, 'index.md'), generateListPageMarkdown(items, sitePath), 'utf8')
for (const p of items) {
const dir = path.join(presentationsDir, p.slug)
fs.mkdirSync(dir, { recursive: true })
fs.writeFileSync(path.join(dir, 'index.md'), generateDetailPageMarkdown(p, sitePath), 'utf8')
}
pruneStalePresentationDirs(items)
console.log(`[sync] ${items.length} présentation(s) — portal mis à jour`)
}
main()