[feat] solution: 지역 읽기 섹션 · 엽서 공유를 풀고 · 기존 사이트는 자산 주소만 갈아 끼운다

세 가지가 한 줄기다 — 목업에만 있던 것을 제품으로 옮기면서, 그게 이미 나가 있는
사이트를 건드리지 않게 하는 데까지가 한 변경이다.

① 지역 읽기(mockup/README T7) — 목업은 주입 스크립트로 그렸고 렌더러엔 없었다.
   새로 발행한 업장에서는 영영 빈자리였다(`daily` 가 프롬프트를 빌더에만 둬서 서버가
   그 종류를 몰랐던 것과 같은 사고).
   · shared: `ReadingItem` · `SECTION_ITEM_REQUIRED_KEY.reading` · `reading` 프롬프트
     (프롬프트 단일 출처는 `section-prompts.ts` 하나다 — 코드에 문장을 박지 않는다)
   · backend: STORY_KINDS 등록. `_SEARCH_LINK_KINDS` — 이 종류는 모델의 URL 을 안 받고
     제목으로 만든 네이버 검색 링크를 코드가 붙인다(주소를 짐작해 적으면 없는 문서로 간다)
   · site: '지역 이야기' 여섯 번째 탭. 구운 HTML 은 앞에서 여섯 꼭지, 붙은 뒤 한 번 섞는다
   · 탭 이름은 `{지명} 읽기` — '군산' 을 코드에 박지 않는다

② 엽서 공유가 모든 발행 사이트에서 막혀 있던 것. 사진이 `*.pstatic.net` ·
   `tong.visitkorea.or.kr` 에 있고 그쪽이 `Access-Control-Allow-Origin` 을 안 준다
   (실측 세 곳 모두 없음) — 캔버스가 오염돼 `toBlob` 이 죽는다. 클라이언트에서는 못 넘는다.
   · `prerender.ts mirrorMedia`: 굽기 전에 `s/<slug>/img/<주소해시>.<확장자>` 로 받고
     payload 주소를 우리 오리진 절대주소로 바꾼다(og:image·JSON-LD 도 같은 값을 쓴다)
   · 못 받으면 원래 주소를 쓴다. 파일명이 주소 해시라 다시 구워도 안 받는다
   · `originUrl`·`sourceType` 은 그대로 — DECISIONS 1-2 가 "불가" 면 CRAWL 제외가 먹어야 한다
   · 엽서 미리보기를 240px 로 묶었다(대표: "엽서 ui 너무 큼")

③ **기동이 전부 다시 굽지 않는다** (대표: "전체 재굽기 할 필요가 없어, 사장님이
   재발행하면 끝인데 / css js만 안 깨지게 하란 말이야").
   렌더러를 한 줄 고칠 때마다 이미 나가 있는 사이트의 HTML 이 통째로 바뀌던 자리다.
   · `watch-payloads.mjs`: 기동 = `--refresh-assets` 하나. 한 번도 안 구워진 payload 만 굽는다
   · `prerender.ts refreshBakedAssets`: 구워진 HTML 의 `assets/index-<해시>.css|js` 파일명만
     새 번들로 바꾼다. 내용·payload·접두사는 그대로. 보호 슬러그는 건너뛴다
   · 그래서 ①②는 **다음 발행 때** 그 사이트에 들어간다

문서: AGENTS.md 함정 둘(사진 내려받기 · 기동은 안 굽는다) 추가, 전체 재굽기를 전제하던
옛 항목 둘을 고쳤다. mockup/README T7 은 "제품에 들어갔다" 로, DATA_MODEL 의 STORY kind 목록 갱신.

검증: tsc·eslint 통과(site·frontend), site 79 passed(읽기 4건 추가).
실측 — buru 굽기: 사진 10장 내려받고 og:image 가 우리 주소, 재굽기 때 0건;
`--refresh-assets`: 옛 해시로 바꿔 둔 index.html 1곳이 새 번들 주소로 바뀌고 내용은 그대로.
백엔드 테스트는 이 기계의 5432 가 다른 터널에 물려 있어 못 돌렸다.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
minaChoiandClaude Opus 5 committed 2026-09-15 09:31:19 +09:00
1 parent a1a416ca4a
commit 6b9e01d876
24 files changed
+761 -52

No files matched your search

@@ -60,6 +60,7 @@ const ANCHOR: Record<string, string> = {
songs: 'songs',
daily: 'daily',
chronicle: 'chronicle',
reading: 'reading',
people: 'people',
quiz: 'quiz',
postcard: 'postcard',
@@ -84,6 +85,7 @@ const FALLBACK_LABEL: Record<string, string> = {
songs: '노래',
daily: '일력',
chronicle: '연표',
reading: '읽기',
people: '인물',
quiz: '퀴즈',
postcard: '엽서',
+4 -1
View File
@@ -110,7 +110,10 @@ function stampLines(ctx: CanvasRenderingContext2D, name: string, maxWidth: numbe
* 실측(2026-09-14): 발행본 사진은 네이버 CDN(`*.pstatic.net`)에 있고 그쪽은
* `Access-Control-Allow-Origin` 을 주지 않는다 — 그래서 이 시도는 실패하고,
* **CORS 없이 다시 받아 미리보기만** 세운다(저장·공유는 부르는 쪽이 막는다).
* ★ 근본 해결은 사진을 우리 오리진으로 옮기는 것이다(시연본이 `img/mirror/` 로 그렇게 한다).
* ★ **2026-09-15 에 근본을 고쳤다** — 굽는 쪽이 사진을 내려받아 `s/<slug>/img/` 에 두고
* payload 의 주소를 우리 오리진으로 바꾼다(`scripts/prerender.ts` `mirrorMedia`).
* 같은 오리진이면 오염되지 않아 저장·공유가 열린다. 아래 폴백은 **못 받아 온 사진**
* (CDN 이 거절했거나 타입이 이상한 것)만을 위한 것이라 이제 드물게 탄다.
*/
async function loadImage(url: string): Promise<{img: HTMLImageElement; exportable: boolean}> {
const tryLoad = (crossOrigin: string | null) => new Promise<HTMLImageElement>((resolve, reject) => {
@@ -25,7 +25,9 @@ export function PostcardMakerSection() {
const [hint, setHint] = useState('');
const [touch, setTouch] = useState(false);
/* 사진이 남의 도메인이면 캔버스가 오염돼 파일로 못 뽑는다(postcard-canvas.loadImage 주석).
그때는 미리보기만 남기고 저장·공유를 막는다 — 눌러도 안 되는 단추를 두지 않는다. */
굽는 쪽이 사진을 우리 오리진으로 옮기고부터(prerender `mirrorMedia`) 여기 걸리는 건
**내려받기에 실패한 사진**뿐이다. 그때는 미리보기만 남기고 저장·공유를 막는다 —
눌러도 안 되는 단추를 두지 않는다. */
const [exportable, setExportable] = useState(true);
useEffect(() => {
@@ -109,15 +111,19 @@ export function PostcardMakerSection() {
title="엽서 쓰기"
lead={`${placeName}에서 보내는 한 장을 직접 써 봅니다. 사진을 고르고 한 마디를 적으면 그 자리에서 엽서가 되고, 그대로 공유하거나 저장할 수 있습니다.`}
>
<div className="grid gap-6 sm:grid-cols-[minmax(0,1fr)_minmax(0,320px)]">
{/* ★ 폭을 묶어 둔다 (2026-09-15 대표: "엽서 ui 너무 큼"). 엽서는 1:1 이라 열 폭을
그대로 주면 넓은 화면에서 한 변이 700px 넘는 정사각이 서서, 예약하러 온 손님이
이 한 칸을 스크롤로 넘겨야 다음 섹션에 닿는다. 미리보기는 손바닥만 하면 된다.
★ 320px 도 크다고 했다(2026-09-15, 같은 날 두 번째) — 240px 로 내렸다. */}
<div className="mx-auto grid max-w-2xl gap-4 sm:grid-cols-[minmax(0,240px)_minmax(0,1fr)] sm:items-start">
<canvas
ref={canvasRef}
width={POSTCARD_SIZE}
height={POSTCARD_SIZE}
aria-label="내가 만든 엽서 미리보기"
className="border-line w-full border"
className="border-line mx-auto w-full max-w-[240px] border"
/>
<div className="flex flex-col gap-3">
<div className="flex flex-col gap-2.5">
<div className="slider-viewport" role="radiogroup" aria-label={`엽서 사진 고르기(${photos.length}장)`} tabIndex={0}>
<div className="slider-track" style={{gap: '0.5rem'}}>
{photos.map((photo, i) => (
@@ -125,9 +131,10 @@ export function PostcardMakerSection() {
key={photo.url}
type="button"
onClick={() => setPicked(i)}
aria-pressed={i === picked}
role="radio"
aria-checked={i === picked}
aria-label={`사진 ${i + 1}`}
className="border-line size-16 shrink-0 overflow-hidden rounded border transition-opacity"
className="border-line size-10 shrink-0 overflow-hidden rounded border transition-opacity"
style={{opacity: i === picked ? 1 : 0.5}}
>
<img src={photo.url} alt="" loading="lazy" className="size-full object-cover" />
@@ -137,30 +144,31 @@ export function PostcardMakerSection() {
</div>
<textarea
rows={3}
rows={2}
maxLength={60}
value={text}
placeholder="엽서에 쓸 한 마디를 적어 보세요"
onChange={(e) => { if (withinLineLimit(e.target.value)) setText(e.target.value); }}
className="border-line w-full rounded border p-3 text-[length:var(--fs-sm)]"
className="border-line w-full rounded border p-2.5 text-[length:var(--fs-sm)]"
/>
<p className="text-muted text-[length:var(--fs-xs)]">{text.length}/60</p>
<p className="text-muted -mt-1 text-[length:var(--fs-xs)]">{text.length}/60</p>
{exportable ? (
<div className="flex flex-wrap gap-2">
<button type="button" onClick={() => void share()} className="tap border-line rounded-full border px-4 py-2 text-[length:var(--fs-sm)] font-bold">
<button type="button" onClick={() => void share()} className="tap border-line rounded-full border px-3.5 py-1.5 text-[length:var(--fs-sm)] font-bold">
{touch ? '카카오톡 등으로 공유' : '공유하기'}
</button>
<button
type="button"
onClick={() => void exportBlob().then((b) => b && download(b))}
className="tap border-line rounded-full border px-4 py-2 text-[length:var(--fs-sm)]"
className="tap border-line rounded-full border px-3.5 py-1.5 text-[length:var(--fs-sm)]"
>
이미지로 저장
</button>
</div>
) : (
/* 브라우저 정책이라 여기서는 못 넘는다 — 사진이 이 사이트 주소로 올라와야 풀린다. */
/* 브라우저 정책이라 여기서는 못 넘는다 — 사진이 이 사이트 주소로 와야 풀리고,
그 일은 굽는 쪽(prerender `mirrorMedia`)이 한다. 여기까지 왔다는 건 그게 실패했다는 뜻. */
<p className="text-muted text-[length:var(--fs-sm)]">
이 사진은 다른 사이트에 올라와 있어 저장·공유가 막혀 있습니다. 화면으로만 보여 드립니다.
</p>
@@ -0,0 +1,96 @@
/**
* 지역 읽기 — 도시 이야기 더미에서 **매번 몇 개만** 뽑아 한 꼭지씩 넘겨 본다.
*
* ★ 왜 다 안 보여주나 (2026-09-14 대표: "34개중 15~19개인데 왜 34개라고 써놔?" →
* "그냥 5-6개 정도만 보여주는거 어때?" → "랜덤으로")
* 서른 꼭지를 한 화면에 펴면 스크롤 압박이 된다. 접는 게 아니라 **돌려 보여준다** —
* 다음에 들어오면 다른 조합이 뜬다. 그래서 `<details>` 를 쓰지 않는다(다 남겨야 하는
* FAQ·일력과는 다른 경우다).
* ★ 인용은 손해 보지 않는다 — 안 뽑힌 꼭지도 `window.__SITE_PAYLOAD__` 로 문서 안에 그대로
* 남는다(`scripts/prerender.ts`). 화면에서 고르는 것과 문서에서 지우는 것은 다른 일이다.
* ★ 뽑기는 **붙은 뒤에** 한다. 구운 HTML 과 첫 렌더가 달라지면 하이드레이션이 깨진다 —
* 서버는 앞에서부터 여섯 개를 세우고(크롤러가 읽는 것이 이것이다), 브라우저가 붙는 순간
* 한 번 섞는다. 다시 섞지는 않는다(재렌더마다 바뀌면 읽던 카드가 눈앞에서 사라진다).
* ★ 갈래(문학·역사·…)로 묶어 세우지 않는다. 갈래는 카드 위 이름표로만 쓰고, 뽑기는
* 갈래를 가리지 않는다 — 갈래마다 3~4개씩 뽑던 판은 한 번에 15~19개가 떴다.
*/
import {useEffect, useState} from 'react';
import type {ReadingItem} from '@o2o/shared';
import {useSite} from '@site/lib/site-context';
import {sectionItems, sectionName} from '@site/lib/derive';
import {ITEM_ACCENT, ITEM_BORDER, ITEM_CARD, ItemSection, Rail, SourceLine} from './common';
/** 한 번에 세우는 꼭지 수. 5 와 6 사이에서 흔들어 "볼 때마다 다르다"를 만든다. */
const MIN_PICK = 5;
const MAX_PICK = 6;
function shuffled<T>(list: readonly T[]): T[] {
const copy = list.slice();
for (let i = copy.length - 1; i > 0; i -= 1) {
const j = Math.floor(Math.random() * (i + 1));
[copy[i], copy[j]] = [copy[j], copy[i]];
}
return copy;
}
export function ReadingSection() {
const payload = useSite();
const parsed = sectionItems<ReadingItem>(payload, 'reading');
const all = parsed.items;
// 서버·첫 렌더가 같아야 한다. 섞기는 아래 useEffect 가 붙은 뒤에 한 번만.
const [picked, setPicked] = useState<ReadingItem[]>(() => all.slice(0, MAX_PICK));
useEffect(() => {
if (all.length <= MIN_PICK) return;
const count = Math.random() < 0.5 ? MIN_PICK : MAX_PICK;
setPicked(shuffled(all).slice(0, count));
// 더미 전체가 바뀔 때만 다시 뽑는다(발행본에서는 한 번뿐이다).
}, [all]);
if (all.length === 0) return null;
const region = payload.place.addressLocality ?? '지역';
return (
<ItemSection
id="reading"
name={parsed.title || sectionName(payload, 'reading', `${region} 읽기`)}
subtitle={parsed.subtitle}
>
<Rail label={`${region} 읽기`}>
{picked.map((item, index) => (
<article
key={`${item.title}-${index}`}
className="w-[86%] shrink-0 grow-0 sm:w-[min(600px,56%)]"
>
<div
className="h-full border p-5"
style={{backgroundColor: ITEM_CARD, borderColor: ITEM_BORDER}}
>
{/* 갈래 이름표. '문학면' 처럼 신문 지면으로 부르지 않는다 — 그 틀이 없다. */}
{item.group && (
<p
className="text-[11px] font-bold tracking-[0.18em]"
style={{color: ITEM_ACCENT}}
>
{item.group}
{item.year != null && <span className="font-normal opacity-70"> · {item.year}</span>}
</p>
)}
<h3
className="serif mt-2 border-b-2 pb-2.5 text-xl leading-snug font-bold"
style={{borderColor: 'currentColor'}}
>
{item.title}
</h3>
{/* 서너 문장이 들어온다 — 줄바꿈이 낱말 가운데를 끊지 않게 keep-all 로 둔다. */}
<p className="mt-3 text-[14.5px] leading-[1.8] break-keep opacity-90">{item.body}</p>
<div className="mt-4 border-t border-dashed pt-2.5" style={{borderColor: ITEM_BORDER}}>
<SourceLine source={item.source} verified={item.verified} />
</div>
</div>
</article>
))}
</Rail>
</ItemSection>
);
}
@@ -1,8 +1,8 @@
/**
* 군산 이야기 — 레트로 아이템 다섯을 한 섹션에 묶고 탭으로 가른다.
* 지역 이야기 — 레트로 아이템 다섯을 한 섹션에 묶고 탭으로 가른다.
*
* ★ 왜 묶나 (2026-09-04, 사장님 요청)
* 가요 다방·오늘의 한 장·인물 열전·시간의 골목·오늘의 엽서가 각각 섹션으로 서 있었다.
* 가요 다방·인물 열전·시간의 골목·지역 읽기·오늘의 엽서가 각각 섹션으로 서 있었다.
* 실측 390px 에서 다섯이 합쳐 3,470px — 전체의 17% 이고, 예약하러 온 손님은 이 구간을
* 다섯 화면 넘게 밀어야 아래(주변·FAQ)에 닿았다. 성격이 같은 것들이니 한 자리에 묶고
* **한 번에 하나만** 편다.
@@ -17,6 +17,7 @@ import {sectionItems, sectionName} from '@site/lib/derive';
import {SongsSection} from './SongsSection';
import {PeopleSection} from './PeopleSection';
import {ChronicleSection} from './ChronicleSection';
import {ReadingSection} from './ReadingSection';
import {PostcardSection} from './PostcardSection';
import {ITEM_BORDER, ITEM_INK, ITEM_INVERSE_INK} from './common';
@@ -25,20 +26,28 @@ import {ITEM_BORDER, ITEM_INK, ITEM_INVERSE_INK} from './common';
* 탭은 데이터가 있는 것만 선다 — 사장님이 아이템 하나를 끄면 문장이 곧바로 거짓말이 된다.
* 실제로 '가요 다방'과 '오늘의 한 장'을 뺐더니 셋인데 "다섯 갈래"라고 적혀 있었다.
*/
const COUNT_WORD: Record<number, string> = {1: '한', 2: '두', 3: '세', 4: '네', 5: '다섯'};
const COUNT_WORD: Record<number, string> = {
1: '한', 2: '두', 3: '세', 4: '네', 5: '다섯', 6: '여섯', 7: '일곱',
};
const TABS = [
{id: 'songs', label: '가요 다방', Component: SongsSection},
{id: 'people', label: '인물 열전', Component: PeopleSection},
{id: 'chronicle', label: '시간의 골목', Component: ChronicleSection},
{id: 'postcard', label: '오늘의 엽서', Component: PostcardSection},
] as const;
/* ★ '읽기' 만 라벨에 지명이 든다 — 나머지 넷은 어느 도시에서도 같은 이름이지만
이건 "그 도시를 읽는다" 가 이름의 뜻이라 지명을 빼면 무엇을 읽는지가 사라진다.
지명을 코드에 박지 않는다(`군산 읽기` 는 시연본 한 곳의 값이다). */
const tabsOf = (region: string) =>
[
{id: 'songs', label: '가요 다방', Component: SongsSection},
{id: 'people', label: '인물 열전', Component: PeopleSection},
{id: 'chronicle', label: '시간의 골목', Component: ChronicleSection},
{id: 'reading', label: `${region} 읽기`, Component: ReadingSection},
{id: 'postcard', label: '오늘의 엽서', Component: PostcardSection},
] as const;
export function StorySection() {
const payload = useSite();
const title = sectionName(payload, 'story', `${payload.place.addressLocality ?? '지역'} 이야기`);
const region = payload.place.addressLocality ?? '지역';
const title = sectionName(payload, 'story', `${region} 이야기`);
// 데이터가 있는 것만 탭이 된다 — 눌러서 빈 화면을 보게 하지 않는다.
const tabs = TABS.filter((tab) => sectionItems(payload, tab.id).items.length > 0);
const tabs = tabsOf(region).filter((tab) => sectionItems(payload, tab.id).items.length > 0);
const [active, setActive] = useState(0);
if (tabs.length === 0) return null;
+3 -1
View File
@@ -8,6 +8,7 @@ import {SongsSection} from './SongsSection';
import {DailySection} from './DailySection';
import {PeopleSection} from './PeopleSection';
import {ChronicleSection} from './ChronicleSection';
import {ReadingSection} from './ReadingSection';
import {PostcardSection} from './PostcardSection';
import {QuizSection} from './QuizSection';
import {ItinerarySection} from './ItinerarySection';
@@ -20,12 +21,13 @@ export const ITEM_SECTIONS: Record<string, () => React.ReactElement | null> = {
daily: DailySection,
people: PeopleSection,
chronicle: ChronicleSection,
reading: ReadingSection,
postcard: PostcardSection,
quiz: QuizSection,
itinerary: ItinerarySection,
video: VideoSection,
// 인스타에 올라오는 그때그때의 행사. 사장님이 옮겨 적고 원문 주소를 단다.
event: EventSection,
// 레트로 다섯(가요다방·오늘의한장·인물열전·시간의골목·엽서)을 탭으로 묶은 자리.
// 레트로 아이템(가요다방·인물열전·시간의골목·지역읽기·엽서)을 탭으로 묶은 자리.
story: StorySection,
};
@@ -0,0 +1,62 @@
import {expect, it} from 'vitest';
import {renderToStaticMarkup} from 'react-dom/server';
import type {ReadingItem} from '@o2o/shared';
import {SiteProvider} from '@site/lib/site-context';
import {MOONLIGHT_STAY_PAYLOAD} from '@site/fixtures/moonlight-stay';
import {ReadingSection} from './ReadingSection';
import {StorySection} from './StorySection';
function withReading(items: ReadingItem[]) {
const payload = structuredClone(MOONLIGHT_STAY_PAYLOAD);
payload.local.story = {...(payload.local.story ?? {}), reading: items};
return payload;
}
const ITEMS: ReadingItem[] = Array.from({length: 9}, (_, i) => ({
group: '문학',
title: `꼭지 ${i}`,
body: `본문 ${i}`,
source: {name: '네이버에서 찾아보기', url: `https://search.naver.com/search.naver?query=${i}`},
}));
it('구운 HTML 은 앞에서부터 여섯 꼭지다 — 섞기는 붙은 뒤에 한다', () => {
// 서버와 첫 렌더가 달라지면 하이드레이션이 깨진다. 무작위는 useEffect 뒤에만 돈다.
const html = renderToStaticMarkup(
<SiteProvider payload={withReading(ITEMS)}>
<ReadingSection />
</SiteProvider>,
);
expect(html).toContain('꼭지 0');
expect(html).toContain('꼭지 5');
expect(html).not.toContain('꼭지 6');
});
it('꼭지가 없으면 섹션 자체가 없다', () => {
const html = renderToStaticMarkup(
<SiteProvider payload={withReading([])}>
<ReadingSection />
</SiteProvider>,
);
expect(html).toBe('');
});
it('출처 링크를 그대로 단다 — 검색 링크는 서버가 만든 값이다', () => {
const html = renderToStaticMarkup(
<SiteProvider payload={withReading(ITEMS.slice(0, 1))}>
<ReadingSection />
</SiteProvider>,
);
expect(html).toContain('search.naver.com');
expect(html).toContain('네이버에서 찾아보기');
});
it("'지역 이야기' 탭에 지명이 든 이름으로 선다 — 군산을 코드에 박지 않는다", () => {
const payload = withReading(ITEMS);
const region = payload.place.addressLocality;
const html = renderToStaticMarkup(
<SiteProvider payload={payload}>
<StorySection />
</SiteProvider>,
);
expect(html).toContain(`${region} 읽기`);
});