발행본 HTML 에 그 순간 기온·관측 시각이 박혀 구글과 첫 화면이 며칠 전 날씨를 봤다. 라운드·코랄·미니멀·솔숲은 관측 시각(시간대 없는 KST)을 new Date 로 읽어 굽는 서버(UTC)가 9시간 틀린 값을 박았고, 브라우저 값과 달라 열 때마다 React #418 → 페이지 전체를 다시 그렸다 (실측 /s/joyyy: HTML "22:45 관측" ↔ 브라우저 "13:45 관측"). - lib/use-live-weather.ts: 첫 렌더는 날씨 없음, 하이드레이션 뒤 스냅샷 → 최신 값 - layouts/{round,coral,minimal,pine}/Weather.tsx: 관측 시각을 글자 그대로 읽는다(다른 템플릿과 같게) - lib/format.ts formatKoreanDate: 한국 시간 기준 날짜 — UTC 서버가 0~9시 KST 발행에서 하루 전 날짜를 박던 것 - WeatherSection: 문구 고르는 부분을 weatherLineSources 로 떼어 테스트. HTML 에 날씨가 없음을 테스트로 고정 tsc·eslint 통과 · vitest 128 passed · TZ=UTC 로 구운 10개 사이트 #418 0건 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
68 lines
2.3 KiB
TypeScript
68 lines
2.3 KiB
TypeScript
import type {WeatherSky} from '@o2o/shared';
|
|
import {useSite} from '@site/lib/site-context';
|
|
import {useLiveWeather} from '@site/lib/use-live-weather';
|
|
import {useWeatherNotes} from '@site/lib/use-weather-note';
|
|
import {weatherBand, weatherMood} from '@site/lib/derive';
|
|
import {CloudIcon, RainIcon, SnowIcon, SunIcon} from './icons';
|
|
|
|
const MOOD_ICON = {
|
|
맑음: SunIcon,
|
|
흐림: CloudIcon,
|
|
비: RainIcon,
|
|
눈: SnowIcon,
|
|
} as const;
|
|
|
|
function observed(iso: string): string | undefined {
|
|
const m = /^\d{4}-(\d{2})-(\d{2})T(\d{2}):(\d{2})/.exec(iso);
|
|
return m ? `${Number(m[1])}월 ${Number(m[2])}일 ${m[3]}:${m[4]} 관측` : undefined;
|
|
}
|
|
|
|
export function Weather() {
|
|
const payload = useSite();
|
|
const weather = useLiveWeather({
|
|
initial: payload.local.weather,
|
|
regionCode: payload.place.regionCode,
|
|
latitude: payload.place.latitude,
|
|
longitude: payload.place.longitude,
|
|
});
|
|
const mood = weatherMood(weather?.condition ?? '');
|
|
const band = weatherBand(weather?.temperature ?? 0);
|
|
const notes = payload.local.weather;
|
|
const condition = (weather?.condition ?? '') as WeatherSky;
|
|
const skyKey: WeatherSky = notes?.noteSets?.[condition] ? condition : mood;
|
|
const [line, bandLine] = useWeatherNotes(
|
|
notes?.noteSets?.[skyKey],
|
|
notes?.notes?.[mood] ?? weather?.note,
|
|
notes?.tempNoteSets?.[band],
|
|
notes?.tempNotes?.[band],
|
|
);
|
|
if (!weather) return null;
|
|
const Icon = MOOD_ICON[mood];
|
|
const region = payload.place.addressLocality?.replace(/(시|군)$/, '');
|
|
const at = observed(weather.observedAt);
|
|
|
|
return (
|
|
<section className="sec" id="weather" data-pg="home" aria-labelledby="weather-heading">
|
|
<p className="kicker">오늘의 날씨</p>
|
|
<h2 id="weather-heading">{region ? `지금 ${region}은` : '오늘의 날씨'}</h2>
|
|
<div className="weather" data-band={band}>
|
|
<Icon />
|
|
<div className="t">
|
|
<span className="deg">{Math.round(weather.temperature * 10) / 10}°</span>
|
|
<span className="cond">{weather.condition}</span>
|
|
</div>
|
|
{at && <p className="obs">{at}</p>}
|
|
{line && (
|
|
<p id="wnote" key={line} className="note">
|
|
{line}
|
|
</p>
|
|
)}
|
|
<p className="band">
|
|
<span>{band}</span>
|
|
{bandLine && <em key={bandLine}>{bandLine}</em>}
|
|
</p>
|
|
</div>
|
|
</section>
|
|
);
|
|
}
|