| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- const fs = require('fs');
- const path = require('path');
- const baseDir = path.join(__dirname, '..', 'public', 'images', '500');
- const constantsPath = path.join(__dirname, '..', 'src', 'pages', 'A2main', 'components', 'sceneHotlist', 'constants.ts');
- const backupPath = constantsPath + '.bak';
- function normalize(name) {
- return name.replace(/\s+/g, '').replace(/[“”"'。,、()()《》<>::\[\]【】\-–—,\.·']/g, '').toLowerCase();
- }
- function findBestFolder(name, folders) {
- const n = normalize(name);
- for (const f of folders) {
- if (normalize(f).includes(n) || n.includes(normalize(f))) return f;
- }
- for (const f of folders) {
- const fn = normalize(f);
- if (fn && n.split('').slice(0,6).every(ch => fn.includes(ch))) return f;
- }
- return null;
- }
- function main() {
- const folders = fs.readdirSync(baseDir, { withFileTypes: true })
- .filter(d => d.isDirectory())
- .map(d => d.name);
- let content = fs.readFileSync(constantsPath, 'utf8');
- fs.writeFileSync(backupPath, content, 'utf8');
- const tmp = content.replace(/export const ANT_LIST\s*=/, 'module.exports =');
- const tmpPath = path.join(__dirname, 'tmp_ant_list.js');
- fs.writeFileSync(tmpPath, tmp, 'utf8');
- delete require.cache[require.resolve(tmpPath)];
- const list = require(tmpPath);
- for (const item of list) {
- if (!item.name) continue;
- if (item.imgName && item.imgName.toString().trim()) continue;
- const folder = findBestFolder(item.name, folders);
- if (!folder) continue;
- const files = fs.readdirSync(path.join(baseDir, folder)).filter(f => /\.(jpe?g|png|webp)$/i.test(f));
- if (files.length === 0) continue;
- item.imgName = `${folder}/${files[0]}`;
- item.imgList = files.slice(0, 2).map(f => `${folder}/${f}`);
- }
- const out = 'export const ANT_LIST = ' + JSON.stringify(list, null, 2).replace(/"/g, "'") + ';\n';
- fs.writeFileSync(constantsPath, out, 'utf8');
- console.log('Updated constants.ts (backup at ' + backupPath + ')');
- }
- main();
|