feat: 지역별 검색 페이지 230장 (/today/{시도}/{지역}, 구로 나뉜 13개 시는 시 페이지) + sitemap 자동 생성

This commit is contained in:
minaChoi committed 2026-10-14 09:12:45 +09:00
1 parent 92cfeabe19
commit e0d2ad2c9b
7 files changed
+3496 -28

No files matched your search

+23 -3
View File
@@ -1,13 +1,15 @@
import { readFileSync, writeFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { dirname, resolve } from 'node:path'
import tailwindcss from '@tailwindcss/vite'
import react from '@vitejs/plugin-react'
import { defineConfig, type Plugin } from 'vite'
type Gak = { name: string; description: string }
type RegionPage = { path: string; name: string; main: string; regions: { code: string; name: string }[] }
const gaks: Gak[] = JSON.parse(readFileSync(resolve(import.meta.dirname, 'seo/gak.json'), 'utf8'))
const gakList = `<ul>${gaks.map((g) => `<li><b>${g.name}</b>: ${g.description}</li>`).join('')}</ul>`
const regionPages: RegionPage[] = JSON.parse(readFileSync(resolve(import.meta.dirname, 'seo/region.json'), 'utf8'))
/** 검색 로봇이 처음 받는 페이지별 HTML. 바뀌지 않는 소개 글만 넣고, 날씨 값은 앱이 뜬 뒤 불러온다 */
const PAGES: { path: string; title: string; description: string; body: string }[] = [
@@ -37,6 +39,19 @@ const PAGES: { path: string; title: string; description: string; body: string }[
},
]
/** 지역마다 한 장: /today/gyeonggi/seongnam. 같은 시도의 다른 지역으로 이어 검색 로봇이 모두 찾게 한다 */
for (const r of regionPages) {
const sido = r.path.split('/')[0]
const near = regionPages.filter((o) => o !== r && o.path.startsWith(`${sido}/`))
const parts = r.regions.length > 1 ? `<p>${r.name}는 ${r.regions.map((g) => g.name.split(' ').at(-1)).join(', ')}별로 따로 계산해요.</p>` : ''
PAGES.push({
path: `today/${r.path}`,
title: `오늘 ${r.name} 날씨, 뭐 할까? | 날씨각`,
description: `오늘 ${r.name} 날씨로 세차·빨래·러닝·피크닉 하기 좋은지 아침·낮·저녁·밤 점수로 알려 드려요. 노을 시각과 미세먼지도 함께 확인하세요.`,
body: `<h1>오늘 ${r.name} 날씨, 뭐 할까?</h1><p>${r.name}의 기상청 예보와 미세먼지로 오늘 하기 좋은 일을 점수로 알려 드려요. 아침, 낮, 저녁, 밤마다 따로 계산해요.</p>${parts}<p>세차각, 빨래각, 러닝각, 우산각처럼 ${gaks.length}가지 일을 매일 새로 계산하고, 오늘 노을이 가장 붉은 시각과 가까운 노을 명소도 알려 드려요.</p>${near.length ? `<h2>${r.name.split(' ')[0]} 다른 지역 날씨</h2><ul>${near.map((o) => `<li><a href="/today/${o.path}">${o.name}</a></li>`).join('')}</ul>` : ''}`,
})
}
const attr = (s: string) => s.replace(/&/g, '&amp;').replace(/"/g, '&quot;')
function seoPages(): Plugin {
@@ -59,8 +74,13 @@ function seoPages(): Plugin {
.replace(/(<meta property="og:url" content=")[^"]*"/, `$1${url}"`)
.replace(/(<link rel="canonical" href=")[^"]*"/, `$1${url}"`)
.replace(/<main>[\s\S]*<\/main>/, `<main>${p.body}<p><a href="/">날씨각 처음으로</a></p></main>`)
writeFileSync(resolve(outDir, `${p.path}.html`), html)
const file = resolve(outDir, `${p.path}.html`)
mkdirSync(dirname(file), { recursive: true })
writeFileSync(file, html)
}
const today = new Date().toISOString().slice(0, 10)
const urls = ['', ...PAGES.map((p) => p.path)].map((path) => ` <url><loc>${site}/${path}</loc><lastmod>${today}</lastmod></url>`)
writeFileSync(resolve(outDir, 'sitemap.xml'), `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${urls.join('\n')}\n</urlset>\n`)
},
}
}