방식 개편

This commit is contained in:
2026-11-05 14:07:55 +09:00
parent 6d78eccb65
commit 67a7fa0326
156 changed files with 107591 additions and 12747 deletions
+40 -38
View File
@@ -1,50 +1,52 @@
const fs = require('fs');
const path = require('path');
// 한국 표준시 (KST) 기준 날짜 (YYYY-MM-DD)
function getKstDate(d = new Date()) {
return d.toLocaleDateString('sv-SE', { timeZone: 'Asia/Seoul' });
}
// Write-if-changed: 내용이 동일하면 파일 수정을 건너뛰어 mtime 유지
function writeIfChanged(filePath, newContent) {
if (fs.existsSync(filePath)) {
const existing = fs.readFileSync(filePath, 'utf8');
if (existing === newContent) {
console.log(` [Skip] No change in ${path.basename(filePath)} (mtime preserved)`);
return false;
}
}
fs.writeFileSync(filePath, newContent, 'utf8');
console.log(` [Write] Updated ${path.basename(filePath)} with new content`);
return true;
}
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 projects = ['seoul', 'gyeonggi', 'incheon', 'daegu', 'busan', 'gwangju', 'ulsan', 'site1'];
// 오늘 KST 날짜
const subjects = ['수학', '영어', '국어', '과학', '사회'];
const grades = ['초등학생', '중학생', '고등학생'];
const todayKst = getKstDate();
projects.forEach(p => {
const sitemapPath = path.join('c:/Users/kkgu8/OneDrive/Desktop/kyounggu/educo/example/web', p, 'public', 'sitemap.xml');
if (!fs.existsSync(sitemapPath)) return;
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 || [];
const xmlContent = fs.readFileSync(sitemapPath, 'utf8');
// <url> 블록 파싱 및 <lastmod> 주입 (기존 lastmod가 없으면 추가, 있으면 유지)
// url 내부에 lastmod가 없을 경우 </url> 바로 앞에 <lastmod>YYYY-MM-DD</lastmod> 추가
const updatedXml = xmlContent.replace(/<url>([\s\S]*?)<\/url>/g, (match, inner) => {
if (inner.includes('<lastmod>')) {
return match; // 이미 lastmod가 있으면 기존 유지
}
// changefreq나 priority 앞에 lastmod 삽입
const lastmodTag = `\n <lastmod>${todayKst}</lastmod>`;
if (inner.includes('<changefreq>')) {
return `<url>${inner.replace('<changefreq>', `${lastmodTag}\n <changefreq>`)}</url>`;
}
return `<url>${inner}${lastmodTag}\n </url>`;
});
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`;
console.log(`Checking sitemap for ${p}...`);
writeIfChanged(sitemapPath, updatedXml);
});
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`);
}