1

Ajoute un script d'import d'images Wikimedia

This commit is contained in:
2026-03-20 01:41:27 +01:00
parent b518d573bc
commit e11e4ee591
8 changed files with 761 additions and 151 deletions

View File

@@ -1,50 +1,14 @@
const fs = require('fs/promises');
const path = require('path');
const readline = require('readline');
const { spawn } = require('child_process');
const os = require('os');
const { promptForBundlePath } = require('./lib/bundles');
const CONTENT_DIR = path.resolve('content');
const DIAGRAMS_DIR = 'diagrams';
const OUTPUT_DIR = 'images';
const MERMAID_EXTENSION = '.mermaid';
function askQuestion(query) {
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
return new Promise(resolve => rl.question(query, answer => { rl.close(); resolve(answer.trim()); }));
}
async function findLatestBundle(dir) {
let latest = { path: null, time: 0 };
async function search(current) {
const entries = await fs.readdir(current, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(current, entry.name);
if (entry.isDirectory()) {
const hasIndex = (await fs.readdir(fullPath)).includes('index.md');
if (hasIndex) {
const stat = await fs.stat(fullPath);
if (stat.mtimeMs > latest.time) {
latest = { path: fullPath, time: stat.mtimeMs };
}
} else {
await search(fullPath);
}
}
}
}
await search(dir);
return latest.path;
}
async function directoryExists(dirPath) {
try {
const stat = await fs.stat(dirPath);
@@ -221,29 +185,7 @@ async function generateDiagrams(bundlePath) {
async function main() {
const manualPath = process.argv[2];
let bundle;
if (manualPath) {
bundle = path.resolve(manualPath);
} else {
const latest = await findLatestBundle(CONTENT_DIR);
if (!latest) {
console.error('No bundle found in content/.');
return;
}
const confirm = await askQuestion(`Use latest bundle found: ${latest}? (Y/n) `);
if (confirm.toLowerCase() === 'n') {
const inputPath = await askQuestion('Enter the relative path to your bundle: ');
bundle = path.resolve(inputPath);
} else {
bundle = latest;
}
}
const bundle = await promptForBundlePath(manualPath, { contentDir: CONTENT_DIR });
try {
await generateDiagrams(bundle);