整合版
```const fs = require('fs');
const path = require('path');
// Check if a year argument is provided
if (process.argv.length < 3) {
console.log("Please provide a year as an argument. Example: node script.js 2023");
process.exit(1);
}
const year = process.argv[2];
const yearPath = path.join('.', year);
// Iterate over HTML files in the year directory
fs.readdirSync(yearPath).forEach((file) => {
if (path.extname(file) === '.html') {
// Read the HTML file
const htmlContent = fs.readFileSync(path.join(yearPath, file), 'utf-8');
// Extract the content of function markerBind
const markerBindContent = htmlContent.match(/function markerBind\(\)\{(.*?)\}/s);
if (markerBindContent && markerBindContent[1]) {
// Write the content to a .js file
fs.writeFileSync(path.join(yearPath, `${path.basename(file, '.html')}.js`), markerBindContent[1]);
}
}
});
// Define setMarkers function
global.setMarkers = (lat, long, htmlString, icon) => {
const city = currentFile.split('_')[1].replace('.js', ''); // Extract city name from file name
if (!city) return;
if (!cityData[city]) cityData[city] = [];
cityData[city].push({
lat,
long,
details: htmlString,
icon,
});
};
let currentFile;
const cityData = {};
// Iterate over .js files in the year directory
fs.readdirSync(yearPath).forEach((file) => {
if (path.extname(file) === '.js') {
// Save the current file name
currentFile = file;
// Read the .js file
const script = fs.readFileSync(path.join(yearPath, file), 'utf-8');
// Evaluate the script
eval(script);
}
});
// Write the city data to a JSON file
fs.writeFileSync(path.join(yearPath, 'cityData.json'), JSON.stringify(cityData, null, 2));```