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 projects = ['seoul', 'gyeonggi', 'incheon', 'daegu', 'busan', 'gwangju', 'ulsan', 'site1']; // 오늘 KST 날짜 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; const xmlContent = fs.readFileSync(sitemapPath, 'utf8'); // 블록 파싱 및 주입 (기존 lastmod가 없으면 추가, 있으면 유지) // url 내부에 lastmod가 없을 경우 바로 앞에 YYYY-MM-DD 추가 const updatedXml = xmlContent.replace(/([\s\S]*?)<\/url>/g, (match, inner) => { if (inner.includes('')) { return match; // 이미 lastmod가 있으면 기존 유지 } // changefreq나 priority 앞에 lastmod 삽입 const lastmodTag = `\n ${todayKst}`; if (inner.includes('')) { return `${inner.replace('', `${lastmodTag}\n `)}`; } return `${inner}${lastmodTag}\n `; }); console.log(`Checking sitemap for ${p}...`); writeIfChanged(sitemapPath, updatedXml); });