-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateImageMap.js
More file actions
29 lines (23 loc) · 831 Bytes
/
generateImageMap.js
File metadata and controls
29 lines (23 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const fs = require('fs');
const path = require('path');
// Caminho para a pasta de imagens
const candidatosPath = path.join(__dirname, 'assets/img/candidatos');
// Obter todos os arquivos da pasta
const files = fs.readdirSync(candidatosPath);
// Criar o mapeamento
const imageMap = files.reduce((map, file) => {
const match = file.match(/FSE(\d+)_div\.jpg/);
if (match) {
const id = parseInt(match[1], 10);
map[id] = `../../../assets/img/candidatos/${file}`;
}
return map;
}, {});
// Gerar o arquivo final com `require` embutido
const imageMapContent = `export default {
${Object.entries(imageMap)
.map(([key, value]) => ` ${key}: require('${value}')`)
.join(',\n')}
};`;
fs.writeFileSync('./imageMap.js', imageMapContent);
console.log('Mapa de imagens gerado com sucesso!');