feat(site): 오늘의 날씨 문구 로딩과 조건별 순환 추가

목업에만 있던 날씨 문구 계약을 제품 payload와 렌더러에 연결한다. 군산 전용 장소를 다른 사업장에 복사하지 않도록 공통 안내를 별도 JSON으로 관리한다.

날씨 변환 단위 테스트 3건, 렌더링 테스트 3건 및 TypeScript·ESLint 통과. 전체 발행 테스트는 깨끗한 renderer 재빌드 후 별도 확인.
This commit is contained in:
minaChoi committed 2026-09-15 16:23:53 +09:00
1 parent f2087aad5e
commit 820a2e9e35
10 files changed
+149 -8

No files matched your search

+1 -1
View File
@@ -1230,6 +1230,6 @@ ssh King_admin "rm -rf ~/data2/o2o-site-AEO/tmp-stay-deploy"
| 렌더러의 카로셀 자동 넘김 | 운영 사이트에 그대로 있다. 고치려면 `use-rail-autoplay.ts` 를 고치고 **전체 재굽기 + `republish_all.py`** |
| ~~일정 정거장의 체류 대비 이동~~ | **해결(2026-09-11)** — 규칙 15·16 을 감사에 넣었다. 전수 검수 21/21 (`SCHEDULE.md`) |
| 렌더러의 가요 다방 판 배치 | 운영 사이트도 `flex-wrap` 이라 곡이 늘면 진열대가 된다(`SongsSection.tsx`). 목업은 CSS 로 덮었다(**2.5** 7). 제품에 옮기려면 **전체 재굽기 + `republish_all.py`** |
| 날씨 문구를 만드는 경로 | 제품에는 없다 — `site_payload.py` `_weather()` 는 기온·하늘·관측시각만 싣는다. `notes`·`tempNotes` 는 이 목업에서 손으로 적은 것이고, 사이트마다 자동으로 나오려면 생성 잡이 하나 필요하다 |
| 날씨 문구를 만드는 경로 | 2026-09-15: 제품에 공통 안내 50개를 읽어 `noteSets`·`tempNoteSets`로 싣고 20초마다 순환하는 경로를 추가했다([WEATHER.md](../../../../docs/WEATHER.md)). 이 목업의 군산 전용 문구는 그대로다. 지역별 장소 추천을 자동 생성하는 잡은 아직 없다 |
| 오늘의 한 장 39장 (365일 중 39일) | 확인되는 소재가 거기까지다. 받은 `gunsan_365_story_db.xlsx` 는 365행이지만 실제 주제가 52개(한 주제를 운영 슬롯 7가지로 복제)이고 231행이 `검증필요`, 시·수필은 빈 슬롯이다. 더 채우려면 **군산을 소재로 한 시·수필을 출처와 함께 찾아야** 한다 |
| 일정을 이미지/링크로 공유 | 이미지 저장은 가능(카드를 PNG 로). 링크는 지금 섹션까지만 간다 — 탭·코스가 URL 에 안 남는다 |
+28
View File
@@ -0,0 +1,28 @@
import {useEffect, useState} from 'react';
/** 첫 렌더는 고정해 SSR과 맞추고, 이후에는 한 바퀴 안에서 중복 없이 돌린다. */
export function useWeatherNote(lines: string[] | undefined, fallback?: string) {
const [selection, setSelection] = useState<{lines: string[]; index: number}>();
useEffect(() => {
if (!lines?.length) return;
let remaining: number[] = [];
let previous = -1;
const next = () => {
if (!remaining.length) remaining = lines.map((_, index) => index);
const choices = remaining.filter((index) => index !== previous);
const available = choices.length ? choices : remaining;
const index = available[Math.floor(Math.random() * available.length)];
remaining = remaining.filter((value) => value !== index);
previous = index;
setSelection({lines, index});
};
// effect 안의 동기 setState 대신 첫 타이머에서 무작위 문구로 전환한다.
const first = window.setTimeout(next, 0);
const timer = window.setInterval(next, 20_000);
return () => {
window.clearTimeout(first);
window.clearInterval(timer);
};
}, [lines]);
return lines?.[selection?.lines === lines ? selection.index : 0] ?? fallback;
}
@@ -11,6 +11,7 @@
*/
import {useSite} from '@site/lib/site-context';
import {useLiveWeather} from '@site/lib/use-live-weather';
import {useWeatherNote} from '@site/lib/use-weather-note';
import {weatherBand, weatherMood} from '@site/lib/derive';
import {Card, Section} from '@site/lib/ui';
import './weather.css';
@@ -32,12 +33,12 @@ export function WeatherSection() {
longitude: payload.place.longitude,
});
if (!weather) return null;
const mood = weatherMood(weather.condition);
const band = weatherBand(weather.temperature);
const mood = weatherMood(weather?.condition ?? '');
const band = weatherBand(weather?.temperature ?? 0);
const notes = payload.local.weather;
const skyKey = weather?.condition === '구름많음' ? '구름많음' : mood;
// 조건별 문장이 우선. 없으면 예전 한 칸(note)으로 떨어진다 — 옛 payload 도 깨지지 않는다.
const line = payload.local.weather?.notes?.[mood] ?? weather.note;
const line = useWeatherNote(notes?.noteSets?.[skyKey], notes?.notes?.[mood] ?? weather?.note);
/*
* ★ 기온 줄 (2026-09-09, 사장님: "기온에 따라서 문구 다르게, 펜션지역의 관광에 맞춰서")
* 하늘 줄은 집 안 이야기(마당·CAFÉ)라 "그래서 오늘 어디를 가지"에는 답하지 않았다.
@@ -45,7 +46,8 @@ export function WeatherSection() {
* ★ 없으면 줄 자체를 그리지 않는다 — 기온대는 항상 계산되지만 문장은 사장님이 적은
* 것뿐이라, 빈 칸을 우리가 채우면 지어낸 관광 안내가 된다.
*/
const bandLine = payload.local.weather?.tempNotes?.[band];
const bandLine = useWeatherNote(notes?.tempNoteSets?.[band], notes?.tempNotes?.[band]);
if (!weather) return null;
const observed = observedText(weather.observedAt);
return (
@@ -0,0 +1,30 @@
import {expect, it} from 'vitest';
import {renderToStaticMarkup} from 'react-dom/server';
import {SiteProvider} from '@site/lib/site-context';
import {MOONLIGHT_STAY_PAYLOAD} from '@site/fixtures/moonlight-stay';
import {WeatherSection} from './WeatherSection';
import type {WeatherSnapshot} from '@o2o/shared';
function render(weather?: WeatherSnapshot) {
const payload = structuredClone(MOONLIGHT_STAY_PAYLOAD);
payload.local.weather = weather;
return renderToStaticMarkup(<SiteProvider payload={payload}><WeatherSection /></SiteProvider>);
}
it('uses the first sky and temperature lines for deterministic HTML', () => {
const weather = {temperature: 30, observedAt: '2026-09-15T12:00', condition: '구름많음', noteSets: {'구름많음': ['구름 첫 줄', '다음 줄']}, tempNoteSets: {'혹서': ['더위 첫 줄']}};
expect(render(weather)).toContain('구름 첫 줄');
expect(render(weather)).toContain('더위 첫 줄');
expect(render(weather)).not.toContain('다음 줄');
expect(render(weather)).toBe(render(weather));
});
it('preserves legacy single notes', () => {
const html = render({temperature: 15, observedAt: '2026-09-15T12:00', condition: '비', notes: {'비': '기존 비 안내'}, tempNotes: {'쌀쌀': '겉옷 안내'}});
expect(html).toContain('기존 비 안내');
expect(html).toContain('겉옷 안내');
});
it('does not invent weather when an observation is missing', () => {
expect(render()).toBe('');
});