사장님이 고를 수 있는 숙박 템플릿이 고택 하나뿐이었다. 모두 stay2 콘텐츠(날씨·미니 블로그· 지역 이야기·객실·축제·일정·후기·엽서·노래)를 그대로 싣고 모양만 다르다. - layouts/<id>/: 템플릿별 Frame·섹션·CSS. 데스크톱은 넓은 배치(1024px 이상), 모바일 우선 - layouts/kit/kit.css: 탭 전환·시트·예약 폼·접기 등 공통 구조 - shared templates.json · builder.ts · catalog.ts: 템플릿·LayoutId 등록 - seo/head.ts: 템플릿별 한글 웹폰트 — 서로 겹치지 않게 배정 - paper Frame·Intro: 같은 탭을 다시 눌러도 맨 위로, 미니 블로그를 글 여러 개로 - docs/TEMPLATES.md · TEMPLATE_DESIGN.md: 목록과 화면 규칙(간격·접기·✓ 표시·글꼴) eslint·tsc 통과, vitest 123 passed, 템플릿 9개 굽기 성공 · 간격 검사 0건
173 lines
6.5 KiB
TypeScript
173 lines
6.5 KiB
TypeScript
import {useState} from 'react';
|
|
import type {LocalPlace} from '@o2o/shared';
|
|
import {useSite} from '@site/lib/site-context';
|
|
import {naverMapSearchUrl} from '@site/lib/format';
|
|
import {Sheet} from '../paper/Sheet';
|
|
import {useWide} from './useWide';
|
|
|
|
const WALK = 80;
|
|
const RANGES = [
|
|
{id: 'all', label: '전체', test: () => true},
|
|
{id: 'w5', label: '걸어서 5분 이내', test: (m: number) => m <= 5 * WALK},
|
|
{id: 'w10', label: '걸어서 10분 이내', test: (m: number) => m <= 10 * WALK},
|
|
{id: 'far', label: '걸어서 10분 이상', test: (m: number) => m > 10 * WALK},
|
|
] as const;
|
|
const FIRST_ROWS = 5;
|
|
const FIRST_SPOTS = 6;
|
|
const RAIL_MAX = 3;
|
|
|
|
function meters(place: LocalPlace): number {
|
|
if (place.distanceMeters != null) return place.distanceMeters;
|
|
const m = /^([\d.]+)\s*(km|m)$/i.exec((place.distanceText ?? '').trim());
|
|
return m ? Number(m[1]) * (m[2].toLowerCase() === 'km' ? 1000 : 1) : Infinity;
|
|
}
|
|
|
|
const byDistance = (a: LocalPlace, b: LocalPlace) => meters(a) - meters(b);
|
|
const inRange = (id: string) => RANGES.find((r) => r.id === id)?.test ?? (() => true);
|
|
|
|
function RangeTabs({places, value, onChange}: {places: LocalPlace[]; value: string; onChange: (id: string) => void}) {
|
|
const tabs = RANGES.filter((r, i) => {
|
|
const n = places.filter((p) => r.test(meters(p))).length;
|
|
return i === 0 || (n > 0 && n < places.length);
|
|
});
|
|
if (tabs.length < 2) return null;
|
|
return (
|
|
<div className="tabrow" role="tablist">
|
|
{tabs.map((r) => (
|
|
<button key={r.id} type="button" role="tab" aria-current={r.id === value} onClick={() => onChange(r.id)}>
|
|
{r.label} {places.filter((p) => r.test(meters(p))).length}
|
|
</button>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function Around() {
|
|
const payload = useSite();
|
|
const {local} = payload;
|
|
const spots = [...local.attractions].sort(byDistance);
|
|
const eats = [...local.restaurants].sort(byDistance);
|
|
const rail = [...spots, ...eats].filter((place) => place.imageUrl).sort(byDistance);
|
|
const [open, setOpen] = useState<LocalPlace | null>(null);
|
|
const [spotRange, setSpotRange] = useState('all');
|
|
const [eatRange, setEatRange] = useState('all');
|
|
const wide = useWide();
|
|
const firstSpots = wide ? 8 : FIRST_SPOTS;
|
|
const railMax = wide ? 4 : RAIL_MAX;
|
|
if (rail.length === 0 && eats.length === 0) return null;
|
|
|
|
const shownSpots = spots.filter((p) => inRange(spotRange)(meters(p)));
|
|
const shownEats = eats.filter((p) => inRange(eatRange)(meters(p)));
|
|
const row = (place: LocalPlace) => (
|
|
<button key={place.name} type="button" className="itemrow" onClick={() => setOpen(place)}>
|
|
<span>{place.name}</span>
|
|
{place.distanceText && <span className="r">{place.distanceText}</span>}
|
|
</button>
|
|
);
|
|
|
|
const card = (place: LocalPlace) => (
|
|
<button key={place.name} type="button" className="place" onClick={() => setOpen(place)}>
|
|
{place.imageUrl && (
|
|
<div className="ph">
|
|
<img src={place.imageUrl} alt={place.name} loading="lazy" />
|
|
</div>
|
|
)}
|
|
<div className="bd">
|
|
<h3>{place.name}</h3>
|
|
{place.distanceText && <small>{place.distanceText}</small>}
|
|
{place.description && <p className="clamp">{place.description}</p>}
|
|
</div>
|
|
</button>
|
|
);
|
|
|
|
return (
|
|
<>
|
|
{rail.length > 0 && (
|
|
<div data-pg="home">
|
|
<section className="sec" id="around" aria-labelledby="around-heading">
|
|
<div className="head">
|
|
<div>
|
|
<p className="kicker">Travel</p>
|
|
<h2 id="around-heading">걸어서 닿는 곳</h2>
|
|
</div>
|
|
<a href="#/area">지역 소개 →</a>
|
|
</div>
|
|
<div className="guide guide--3">
|
|
{rail.slice(0, railMax).map((place) => (
|
|
<button key={place.name} type="button" className="place" onClick={() => setOpen(place)}>
|
|
<div className="ph">
|
|
<img src={place.imageUrl} alt={place.name} loading="lazy" />
|
|
</div>
|
|
<div className="bd">
|
|
<h3>{place.name}</h3>
|
|
{place.distanceText && <small>{place.distanceText}</small>}
|
|
</div>
|
|
</button>
|
|
))}
|
|
</div>
|
|
<a href="#/area" className="more">
|
|
지역 소개에서 모두 보기
|
|
</a>
|
|
</section>
|
|
</div>
|
|
)}
|
|
|
|
<div data-pg="area" id="guide">
|
|
{spots.length > 0 && (
|
|
<section className="sec" id="walk">
|
|
<p className="kicker">Spot</p>
|
|
<h2>
|
|
주변 명소 <span className="sub">{spots.length}곳</span>
|
|
</h2>
|
|
<RangeTabs places={spots} value={spotRange} onChange={setSpotRange} />
|
|
<div className="cards2">{shownSpots.slice(0, firstSpots).map(card)}</div>
|
|
{shownSpots.length > firstSpots && (
|
|
<details>
|
|
<summary className="more">{shownSpots.length - firstSpots}곳 더 보기</summary>
|
|
<div className="cards2">{shownSpots.slice(firstSpots).map(card)}</div>
|
|
</details>
|
|
)}
|
|
</section>
|
|
)}
|
|
{eats.length > 0 && (
|
|
<section className="sec" id="eat">
|
|
<p className="kicker">Table</p>
|
|
<h2>
|
|
주변 맛집 <span className="sub">{eats.length}곳</span>
|
|
</h2>
|
|
<RangeTabs places={eats} value={eatRange} onChange={setEatRange} />
|
|
<div className="list">
|
|
{shownEats.slice(0, FIRST_ROWS).map(row)}
|
|
{shownEats.length > FIRST_ROWS && (
|
|
<details>
|
|
<summary className="more">{shownEats.length - FIRST_ROWS}곳 더 보기</summary>
|
|
{shownEats.slice(FIRST_ROWS).map(row)}
|
|
</details>
|
|
)}
|
|
</div>
|
|
</section>
|
|
)}
|
|
</div>
|
|
|
|
<Sheet open={open != null} onClose={() => setOpen(null)} label={open?.name ?? ''}>
|
|
{open && (
|
|
<>
|
|
{open.imageUrl && <img src={open.imageUrl} alt={open.name} />}
|
|
<h3>{open.name}</h3>
|
|
<p className="meta">{[open.distanceText, open.category].filter(Boolean).join(' · ')}</p>
|
|
{open.description && <p>{open.description}</p>}
|
|
<a
|
|
className="out"
|
|
href={naverMapSearchUrl(open.searchQuery ?? open.name)}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
네이버에서 보기
|
|
</a>
|
|
</>
|
|
)}
|
|
</Sheet>
|
|
</>
|
|
);
|
|
}
|