76 lignes
2.4 KiB
JavaScript
76 lignes
2.4 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* tools/export-selection.js
|
|
*
|
|
* Exporte l'ensemble des photos affichées dans la galerie de index.html
|
|
* vers le dossier C:\Users\theog\Desktop\Selection_Photos_Portfolio
|
|
* pour faciliter le tri direct par suppression de fichiers.
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const ROOT_DIR = path.resolve(__dirname, '..');
|
|
const INDEX_HTML = path.join(ROOT_DIR, 'index.html');
|
|
const DESKTOP_TARGET = 'C:\\Users\\theog\\Desktop\\Selection_Photos_Portfolio';
|
|
|
|
console.log('[EXPORT] Analyse de index.html pour identifier les photos de la galerie...');
|
|
|
|
if (!fs.existsSync(INDEX_HTML)) {
|
|
console.error(`[ERREUR] Fichier introuvable : ${INDEX_HTML}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const html = fs.readFileSync(INDEX_HTML, 'utf8');
|
|
|
|
// Extraction de la section galerie (#gallery-root)
|
|
const galleryMatch = html.match(/id="gallery-root"[\s\S]*?id="cloudWrapper"/);
|
|
if (!galleryMatch) {
|
|
console.error('[ERREUR] Impossible de trouver la section #gallery-root dans index.html');
|
|
process.exit(1);
|
|
}
|
|
|
|
const galleryHtml = galleryMatch[0];
|
|
const imgRegex = /src="(assets\/img\/[^"]+)"/g;
|
|
const photos = [];
|
|
let m;
|
|
|
|
while ((m = imgRegex.exec(galleryHtml)) !== null) {
|
|
const relPath = m[1];
|
|
if (!photos.includes(relPath)) {
|
|
photos.push(relPath);
|
|
}
|
|
}
|
|
|
|
console.log(`[EXPORT] ${photos.length} photos uniques détectées dans la galerie.`);
|
|
|
|
// Création du dossier cible sur le bureau
|
|
if (!fs.existsSync(DESKTOP_TARGET)) {
|
|
fs.mkdirSync(DESKTOP_TARGET, { recursive: true });
|
|
console.log(`[EXPORT] Dossier créé : ${DESKTOP_TARGET}`);
|
|
} else {
|
|
console.log(`[EXPORT] Dossier existant : ${DESKTOP_TARGET}`);
|
|
}
|
|
|
|
let copiedCount = 0;
|
|
for (const rel of photos) {
|
|
const srcFile = path.join(ROOT_DIR, rel);
|
|
const fileName = path.basename(rel);
|
|
const destFile = path.join(DESKTOP_TARGET, fileName);
|
|
|
|
if (fs.existsSync(srcFile)) {
|
|
fs.copyFileSync(srcFile, destFile);
|
|
copiedCount++;
|
|
console.log(` ✓ Copié : ${fileName}`);
|
|
} else {
|
|
console.warn(` ⚠ Source absente : ${srcFile}`);
|
|
}
|
|
}
|
|
|
|
console.log('================================================================');
|
|
console.log(`[SUCCÈS] ${copiedCount}/${photos.length} photos copiées dans :`);
|
|
console.log(DESKTOP_TARGET);
|
|
console.log('Tu peux maintenant supprimer les photos non retenues pour garder');
|
|
console.log('uniquement ta sélection de 8 à 12 clichés.');
|
|
console.log('================================================================');
|