53 lines
2.2 KiB
JavaScript
53 lines
2.2 KiB
JavaScript
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 = '<?xml version="1.0" encoding="UTF-8"?>\n';
|
|
xml += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n';
|
|
xml += ` <url>\n <loc>${baseUrl}/</loc>\n <lastmod>${todayKst}</lastmod>\n <changefreq>daily</changefreq>\n <priority>1.0</priority>\n </url>\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 += ` <url>\n <loc>${baseUrl}/${encDong}</loc>\n <lastmod>${todayKst}</lastmod>\n <changefreq>weekly</changefreq>\n <priority>0.8</priority>\n </url>\n`;
|
|
for (const g of grades) {
|
|
const encGrade = encodeURIComponent(g);
|
|
for (const sub of subjects) {
|
|
const encSub = encodeURIComponent(sub);
|
|
xml += ` <url>\n <loc>${baseUrl}/${encDong}/${encGrade}/${encSub}</loc>\n <lastmod>${todayKst}</lastmod>\n <changefreq>weekly</changefreq>\n <priority>0.7</priority>\n </url>\n`;
|
|
}
|
|
}
|
|
}
|
|
xml += '</urlset>\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`);
|
|
}
|