const fs = require('fs'); const path = require('path'); function getKstDate(d = new Date()) { return d.toLocaleDateString('sv-SE', { timeZone: 'Asia/Seoul' }); } const siteDomains = { seoul: 'https://aeseo.cloud', gyeonggi: 'https://aeseo.shop', incheon: 'https://aeseo.site', gwangju: 'https://aeseo.store', busan: 'https://soohyun.cloud', daegu: 'https://soohyun.store', ulsan: 'https://soohyun.xyz', site1: 'https://aeseo.cloud' }; const subjects = ['수학', '영어', '국어', '과학', '사회']; const grades = ['초등학생', '중학생', '고등학생']; const todayKst = getKstDate(); for (const [dir, baseUrl] of Object.entries(siteDomains)) { const regionsPath = path.join(__dirname, dir, 'data', 'regions.json'); if (!fs.existsSync(regionsPath)) continue; const regionsData = JSON.parse(fs.readFileSync(regionsPath, 'utf8')); const list = regionsData.list || []; let xml = '\n'; xml += '\n'; xml += ` \n ${baseUrl}/\n ${todayKst}\n daily\n 1.0\n \n`; const seenDongs = new Set(); for (const r of list) { if (!r.dong || seenDongs.has(r.dong)) continue; seenDongs.add(r.dong); const encDong = encodeURIComponent(r.dong); xml += ` \n ${baseUrl}/${encDong}\n ${todayKst}\n weekly\n 0.8\n \n`; for (const g of grades) { const encGrade = encodeURIComponent(g); for (const sub of subjects) { const encSub = encodeURIComponent(sub); xml += ` \n ${baseUrl}/${encDong}/${encGrade}/${encSub}\n ${todayKst}\n weekly\n 0.7\n \n`; } } } xml += '\n'; const sitemapPath = path.join(__dirname, dir, 'public', 'sitemap.xml'); fs.writeFileSync(sitemapPath, xml, 'utf8'); console.log(`Updated sitemap.xml for ${dir}: ${seenDongs.size} dongs, ${1 + seenDongs.size * (1 + grades.length * subjects.length)} total URLs`); }