한국-멕시코전 전용 공유 카드 + 앱 배너 이미지
This commit is contained in:
1 parent
dc262009f9
commit
65e7c7571c
7 files changed
+199
-1
No files matched your search
@@ -1,3 +1,10 @@
|
||||
# 공유 크롤러(카카오톡·트위터·페북 등) 판별 → /match/:id 만 백엔드 OG 프리렌더로.
|
||||
# 일반 사용자(JS 실행)는 0 → 기존 SPA 그대로.
|
||||
map $http_user_agent $is_share_crawler {
|
||||
default 0;
|
||||
"~*(kakaotalk|facebookexternalhit|facebot|twitterbot|slackbot|discordbot|telegrambot|whatsapp|line\\b|skypeuripreview|pinterest|redditbot|googlebot|bingbot|daumoa|yeti)" 1;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
@@ -13,6 +20,21 @@ server {
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# 경기 공유 링크: 크롤러면 백엔드 OG 프리렌더, 사람이면 SPA.
|
||||
# (418 → 내부 named location 으로 우회: if + try_files 충돌 회피 정석 패턴)
|
||||
location /match/ {
|
||||
error_page 418 = @og_prerender;
|
||||
if ($is_share_crawler) { return 418; }
|
||||
try_files $uri /index.html;
|
||||
}
|
||||
location @og_prerender {
|
||||
proxy_pass http://api:8000;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# SPA 폴백 — 클라이언트 라우팅(/match/:id 등)
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
# 경기별 공유 썸네일 (OG 이미지)
|
||||
|
||||
카카오톡·트위터 등에서 특정 경기 링크(`/match/:id`)를 공유할 때 뜨는 미리보기
|
||||
이미지를 여기에 둔다. 미등록 경기는 기본 썸네일(`assets/bi/og-image.png`)로 폴백.
|
||||
|
||||
## 용도 두 가지
|
||||
|
||||
- **앱 안 배너**(매치 상세 페이지): 세로/원본 이미지. `pages/MatchDetail.tsx` 에서 직접 참조.
|
||||
예) `kor_mex.png` (세로 816×1456)
|
||||
- **공유 카드**(카톡·트위터 미리보기): 가로 **1200 × 630** 합성본. `share.py` 의 `OG_IMAGES` 에 등록.
|
||||
예) `kor_mex_card.png`
|
||||
|
||||
세로 원본만 있으면 카드용 가로본은 아래 스크립트로 자동 합성(원본을 가운데 두고
|
||||
배경은 블러로 채움 → 잘림 없음):
|
||||
```python
|
||||
from PIL import Image, ImageFilter, ImageEnhance
|
||||
W, H = 1200, 630
|
||||
src = Image.open("kor_mex.png").convert("RGB"); sw, sh = src.size
|
||||
s = max(W/sw, H/sh); bw, bh = int(sw*s)+1, int(sh*s)+1
|
||||
bg = src.resize((bw,bh), Image.LANCZOS).crop(((bw-W)//2,(bh-H)//2,(bw-W)//2+W,(bh-H)//2+H))
|
||||
bg = ImageEnhance.Brightness(bg.filter(ImageFilter.GaussianBlur(22))).enhance(0.55)
|
||||
fw = int(sw*(H/sh)); bg.paste(src.resize((fw,H), Image.LANCZOS), ((W-fw)//2, 0))
|
||||
bg.save("kor_mex_card.png", "PNG")
|
||||
```
|
||||
|
||||
## 적용 방법 (예: 한국-멕시코전)
|
||||
|
||||
1. 세로 원본을 이 폴더에 넣는다 → `kor_mex.png` (앱 배너용)
|
||||
2. 위 스크립트로 가로 카드 합성 → `kor_mex_card.png` (공유 카드용)
|
||||
3. `backend/app/routers/share.py` 의 `OG_IMAGES` 에 등록:
|
||||
```python
|
||||
OG_IMAGES = {
|
||||
frozenset({"KOR", "MEX"}): "kor_mex_card.png",
|
||||
}
|
||||
```
|
||||
4. 배포: 서버에서 `git pull && docker compose up --build -d`
|
||||
|
||||
## 동작 원리
|
||||
|
||||
- nginx 가 공유 크롤러(UA)만 `/match/:id` → 백엔드 OG 프리렌더로 보낸다.
|
||||
- 백엔드가 경기 ID(`{조}_{팀A}_{팀B}_{날짜}`)에서 두 팀 코드를 뽑아
|
||||
`OG_IMAGES` 에 있으면 해당 이미지를, 없으면 기본 썸네일을 단 HTML 을 반환.
|
||||
- 일반 사용자는 영향 없이 기존 SPA 그대로.
|
||||
|
||||
팀 코드 순서는 무관(`KOR_MEX` = `MEX_KOR`). 한국-멕시코 경기 ID 는
|
||||
`A_MEX_KOR_20260619`.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.4 MiB |
@@ -59,6 +59,13 @@ export default function MatchDetail() {
|
||||
const hook = lang === "en" ? t.hook(aShort, bShort) : match.hookText;
|
||||
const url = matchUrl(match.matchId);
|
||||
|
||||
// 특정 경기 전용 비주얼 배너(코드쌍 → 이미지). 등록된 경기에만 노출.
|
||||
const codes = new Set([match.teamA.code, match.teamB.code]);
|
||||
const matchBanner =
|
||||
codes.has("KOR") && codes.has("MEX")
|
||||
? "/assets/og/kor_mex.png"
|
||||
: null;
|
||||
|
||||
return (
|
||||
<main className="shell">
|
||||
<Hero
|
||||
@@ -81,6 +88,18 @@ export default function MatchDetail() {
|
||||
<span className="text-[var(--green)]">⫽</span>
|
||||
</h1>
|
||||
|
||||
{/* 경기 전용 비주얼 배너 (한국-멕시코 등 등록된 경기만) */}
|
||||
{matchBanner && (
|
||||
<div className="mt-5 overflow-hidden rounded-2xl border border-white/10 shadow-[0_12px_32px_rgba(0,0,0,0.45)]">
|
||||
<img
|
||||
src={matchBanner}
|
||||
alt={`${aShort} vs ${bShort}`}
|
||||
loading="lazy"
|
||||
className="block max-h-[440px] w-full object-cover"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<MatchupHUD match={match} lang={lang} />
|
||||
<Arena
|
||||
match={match}
|
||||
|
||||
Reference in new issue
Block a user