65 lines
2.7 KiB
TypeScript
65 lines
2.7 KiB
TypeScript
import regionsData from '../../data/regions.json'
|
|
|
|
export default defineEventHandler((event) => {
|
|
const config = useRuntimeConfig()
|
|
const baseUrl = config.public.siteDomain || 'https://aeseo.cloud'
|
|
const list = regionsData.list as Array<{ sido: string, sigungu: string, dong: string }>
|
|
const today = new Date().toISOString().split('T')[0]
|
|
|
|
const subjectImages: Record<string, string> = {
|
|
'수학': `${baseUrl}/img/math-tutoring.png`,
|
|
'영어': `${baseUrl}/img/english-tutoring.png`,
|
|
'국어': `${baseUrl}/img/korean-tutoring.png`,
|
|
'과학': `${baseUrl}/img/science-tutoring.png`,
|
|
'사회': `${baseUrl}/img/social-studies-tutoring.png`
|
|
}
|
|
const subjects = ['수학', '영어', '국어', '과학', '사회']
|
|
const grades = ['초등학생', '중학생', '고등학생']
|
|
|
|
let xml = `<?xml version="1.0" encoding="UTF-8"?>\n`
|
|
xml += `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">\n`
|
|
|
|
// 메인 (대표 이미지 + 5대 과목 이미지 모두 포함)
|
|
xml += ` <url>\n`
|
|
xml += ` <loc>${baseUrl}/</loc>\n`
|
|
xml += ` <lastmod>${today}</lastmod>\n`
|
|
xml += ` <changefreq>daily</changefreq>\n`
|
|
xml += ` <priority>1.0</priority>\n`
|
|
xml += ` <image:image><image:loc>${baseUrl}/img/og-main.png</image:loc></image:image>\n`
|
|
subjects.forEach(sub => {
|
|
xml += ` <image:image><image:loc>${subjectImages[sub]}</image:loc></image:image>\n`
|
|
})
|
|
xml += ` </url>\n`
|
|
|
|
// 동별 주요 과목 및 학년 URL 생성
|
|
list.forEach(r => {
|
|
// 1. 동 대표
|
|
xml += ` <url>\n`
|
|
xml += ` <loc>${baseUrl}/${encodeURIComponent(r.dong)}</loc>\n`
|
|
xml += ` <lastmod>${today}</lastmod>\n`
|
|
xml += ` <changefreq>weekly</changefreq>\n`
|
|
xml += ` <priority>0.8</priority>\n`
|
|
xml += ` <image:image><image:loc>${baseUrl}/img/og-main.png</image:loc></image:image>\n`
|
|
xml += ` <image:image><image:loc>${baseUrl}/img/math-tutoring.png</image:loc></image:image>\n`
|
|
xml += ` </url>\n`
|
|
|
|
// 2. 동/학년/과목 대표 조합
|
|
grades.forEach(g => {
|
|
subjects.forEach(sub => {
|
|
xml += ` <url>\n`
|
|
xml += ` <loc>${baseUrl}/${encodeURIComponent(r.dong)}/${encodeURIComponent(g)}/${encodeURIComponent(sub)}</loc>\n`
|
|
xml += ` <lastmod>${today}</lastmod>\n`
|
|
xml += ` <changefreq>weekly</changefreq>\n`
|
|
xml += ` <priority>0.7</priority>\n`
|
|
xml += ` <image:image><image:loc>${subjectImages[sub]}</image:loc></image:image>\n`
|
|
xml += ` </url>\n`
|
|
})
|
|
})
|
|
})
|
|
|
|
xml += `</urlset>`
|
|
|
|
setHeader(event, 'content-type', 'application/xml; charset=utf-8')
|
|
return xml
|
|
})
|