AI PROMPTS · 인프라 & 자동화
SEO 사이트맵 자동 생성 스크립트
각 학습 항목을 URL로 매핑해 검색 엔진 최적화를 위한 사이트맵을 생성합니다.
인프라 & 자동화
핵심 설명
각 학습 항목을 URL로 매핑해 검색 엔진 최적화를 위한 사이트맵을 생성합니다.
scripts/sitemap.js
// scripts/sitemap.js
// 사용법: node scripts/sitemap.js > sitemap.xml
const fs = require('fs');
const vm = require('vm');
const BASE_URL = 'https://replace-with-your-pullh-domain.com';
const today = new Date().toISOString().split('T')[0];
function loadData(lang) {
const ctx = { window: { DATA: {} } };
vm.runInNewContext(
fs.readFileSync(`data/${lang}.js`, 'utf8'), ctx
);
return ctx.window.DATA[lang]?.items || [];
}
const urls = [
// 정적 페이지
{ url: '/', priority: '1.0', changefreq: 'weekly' },
{ url: '/?lang=kotlin', priority: '0.9', changefreq: 'weekly' },
{ url: '/?lang=python', priority: '0.9', changefreq: 'weekly' },
{ url: '/?lang=go', priority: '0.9', changefreq: 'weekly' },
{ url: '/?lang=java', priority: '0.9', changefreq: 'weekly' },
{ url: '/?section=ai', priority: '0.8', changefreq: 'monthly' },
{ url: '/?section=vibe',priority: '0.8', changefreq: 'monthly' },
];
// 각 항목별 URL
['kotlin','python','go','java'].forEach(lang => {
const items = loadData(lang);
items.forEach(item => {
urls.push({
url: `/?lang=${lang}&id=${item.id}`,
priority: '0.7',
changefreq: 'monthly',
title: item.title,
});
});
});
const xml = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
${urls.map(({ url, priority, changefreq }) => ` <url>
<loc>${BASE_URL}${url}</loc>
<lastmod>${today}</lastmod>
<changefreq>${changefreq}</changefreq>
<priority>${priority}</priority>
</url>`).join('\n')}
</urlset>`;
process.stdout.write(xml);
process.stderr.write(`\n✅ ${urls.length}개 URL 포함 sitemap.xml 생성 완료\n`);Continue Learning
AI Prompts 학습을 이어가세요
총 20개의 독립 HTML 학습 문서 중 하나입니다. 각 문서는 고유 URL과 canonical 메타데이터를 가집니다.