[feat] solution/backend,site: 발행 사이트 제목·keywords 메타에 SiteOntology 키워드 — 이 가게 자료로 거른 것만
숙박 사이트를 빌드할 때 SiteOntology(o2o-site-ontology)에 이 가게 프로필을 보내 검색 키워드를 받고, 이 가게의 확인된 자료로 거른 것만 `<meta name="keywords">` 와 제목 업종어 자리에 싣는다. 실측(2026-09-14, 스테이머뭄 프로필): 추천 10건 중 `군산 독채 마당 펜션`·`군산 독채 복층 펜션`· `군산 커플 프라이빗 펜션` 이 status=ok 로 왔다 — SiteOntology 사실 필터는 수용 인원과 일부 시설만 본다. 사전에는 `선유도 독채펜션`(다른 권역)·`군산 펜션 최저가`(가격 주장)도 있다. 메타 태그와 제목은 AI 검색이 그대로 읽는 자리라, 키워드의 모든 낱말이 이 가게 자료에 있을 때만 싣는다. SiteOntology 쪽 함정도 실측으로 막았다 — 없는 regionId 는 500(외래키), 해석 안 된 query 도 201 로 입력 문자열 검색 결과를 준다. - services/external/site_ontology.py: publish(generate:false) → match 두 번 호출. 500 이면 지역 없이 재시도, resolved 가 우리 place_id 가 아니면 실패로 본다 - services/seo_keywords.py: 스냅샷 → 프로필(있음=features · 없음=뺌 · 모름=unverified), 낱말 대조 거르기, 업종어뿐인 단어 제외, 제목은 유형 레인 코어 중 시·군 이름을 품고 예약·추천이 없는 것. 숙박만 - services/build_service.py: 스냅샷 직후 호출해 snapshot["seo"] 에 싣는다(= 발행 기록). 실패해도 발행 계속 - services/site_payload.py · shared site-payload.ts: 선택 필드 `seo` — 옛 payload·목업은 그대로 - site/src/seo/meta.ts · head.ts: 제목 `<상호> · <대표 키워드>`(15자 미만이면 예전 제목), keywords 태그는 키워드가 있을 때만(빈 태그를 만들지 않는다) - config_models.py · .env.example: SITE_ONTOLOGY_URL — 비우면 호출하지 않는다 - docs/ARCHITECTURE.md 발행 파이프라인 · docs/DEVLOG.md pytest tests/test_seo_keywords.py 16 passed · 백엔드 전체 650 passed(실패 2건은 이전부터: test_rate_limit_closes_the_tap · test_사이트_디렉터리_밖의_thumbs_에_올린다) site tsc·eslint 통과 · vitest 63 passed · frontend·admin tsc 통과 실제 발행 한 바퀴(로컬 SiteOntology :3100): 스테이머뭄 → `<title>스테이머뭄 · 군산 독채펜션</title>` + keywords 9건, 렌더 게이트 불일치 0건. SiteOntology 없는 payload 는 제목·head 가 예전 그대로 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LBR4o9Nth3g4eoQEnL1iat
This commit is contained in:
1 parent
c07e2bddf4
commit
b2c8bb033e
13 files changed
+882
-2
No files matched your search
@@ -145,6 +145,13 @@ export function renderHead({payload, meta, scriptSrc, cssHrefs = []}: HeadOption
|
||||
' <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />',
|
||||
` <title>${escapeHtml(meta.title)}</title>`,
|
||||
tag('meta', {name: 'description', content: meta.description}),
|
||||
/*
|
||||
* SiteOntology 키워드. 구글은 이 태그를 순위에 쓰지 않는다 — 비용이 없어 싣는 자리이고,
|
||||
* 순위에 닿는 자리는 위의 title 이다(meta.ts homeTitle).
|
||||
* ★ 조건부로 넣는다. tag() 는 빈 **속성**만 빼고 태그는 만든다 — 그대로 두면 키워드가 없는
|
||||
* 모든 사이트에 `<meta name="keywords" />` 빈 태그가 박힌다(meta.test.ts 가 잡았다).
|
||||
*/
|
||||
...(meta.keywords ? [tag('meta', {name: 'keywords', content: meta.keywords})] : []),
|
||||
tag('link', {rel: 'canonical', href: meta.canonical}),
|
||||
// 색인을 막을 이유가 없다 — 이 사이트는 색인되라고 존재한다.
|
||||
tag('meta', {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* SiteOntology 키워드 → 제목 · 메타 키워드.
|
||||
*
|
||||
* ★ 백엔드(services/seo_keywords)가 이미 이 가게 자료로 거른 값만 payload.seo 로 온다.
|
||||
* 여기서 지키는 것은 **자리**다 — 키워드가 없거나 제목이 너무 짧아지면 예전 제목으로 떨어져야 하고,
|
||||
* 키워드가 없는 옛 payload(목업 포함)는 head 가 한 글자도 바뀌면 안 된다.
|
||||
*/
|
||||
import {describe, expect, it} from 'vitest';
|
||||
|
||||
import type {SitePayload} from '@o2o/shared';
|
||||
|
||||
import {MOONLIGHT_STAY_PAYLOAD} from '../fixtures/moonlight-stay';
|
||||
import {renderHead} from './head';
|
||||
import {homeMeta} from './meta';
|
||||
|
||||
function withSeo(seo: SitePayload['seo']): SitePayload {
|
||||
return {...MOONLIGHT_STAY_PAYLOAD, seo};
|
||||
}
|
||||
|
||||
describe('homeMeta — 제목', () => {
|
||||
it('대표 키워드가 있으면 업종어 자리를 대신한다', () => {
|
||||
const meta = homeMeta(withSeo({keywords: [], titleKeyword: '애월 독채펜션'}));
|
||||
expect(meta.title).toBe('달빛스테이 제주 · 애월 독채펜션');
|
||||
});
|
||||
|
||||
it('없으면 예전 제목 그대로다', () => {
|
||||
expect(homeMeta(withSeo({keywords: ['애월 독채펜션']})).title).toBe(homeMeta(MOONLIGHT_STAY_PAYLOAD).title);
|
||||
expect(homeMeta(MOONLIGHT_STAY_PAYLOAD).title).toContain('숙소');
|
||||
});
|
||||
|
||||
it('15자보다 짧아지면 예전 제목으로 떨어진다 — Bing 이 Title too short 로 잡는다', () => {
|
||||
const meta = homeMeta(withSeo({keywords: [], titleKeyword: '독채'}));
|
||||
expect(meta.title).toBe(homeMeta(MOONLIGHT_STAY_PAYLOAD).title);
|
||||
});
|
||||
});
|
||||
|
||||
describe('renderHead — keywords 메타', () => {
|
||||
it('키워드를 쉼표로 이어 싣고 이스케이프한다', () => {
|
||||
const payload = withSeo({keywords: ['애월 독채펜션', '고내리 "바다" 숙소']});
|
||||
const head = renderHead({payload, meta: homeMeta(payload)});
|
||||
expect(head).toContain('<meta name="keywords" content="애월 독채펜션, 고내리 "바다" 숙소" />');
|
||||
});
|
||||
|
||||
it('키워드가 없으면 태그를 만들지 않는다', () => {
|
||||
const head = renderHead({payload: MOONLIGHT_STAY_PAYLOAD, meta: homeMeta(MOONLIGHT_STAY_PAYLOAD)});
|
||||
expect(head).not.toContain('name="keywords"');
|
||||
const empty = withSeo({keywords: []});
|
||||
expect(renderHead({payload: empty, meta: homeMeta(empty)})).not.toContain('name="keywords"');
|
||||
});
|
||||
});
|
||||
@@ -19,6 +19,8 @@ export interface PageMeta {
|
||||
canonical: string;
|
||||
ogImage?: string;
|
||||
ogImageAlt?: string;
|
||||
/** `<meta name="keywords">`. SiteOntology 키워드가 없으면 비어 태그를 만들지 않는다. */
|
||||
keywords?: string;
|
||||
}
|
||||
|
||||
function url(payload: SitePayload, ...parts: string[]): string {
|
||||
@@ -128,15 +130,28 @@ const CATEGORY_WORD: Record<PlaceCategory, string> = {
|
||||
[PlaceCategory.CLINIC]: '의원',
|
||||
};
|
||||
|
||||
/** Bing 웹마스터도구가 이보다 짧은 제목을 Error(Title too short)로 잡는다. */
|
||||
const MIN_TITLE_LENGTH = 15;
|
||||
|
||||
/**
|
||||
* `<상호> · <지역> <업종>`.
|
||||
*
|
||||
* ★ `<상호> · <시군구>` 였다. "스테이,머뭄 · 군산시" 는 12자인데 Bing 웹마스터도구가
|
||||
* **15자 미만을 Error(Title too short)** 로 잡는다. 광역시도와 업종어를 같이 실어
|
||||
* 길이도 채우고 "군산 숙소" 같은 질의에도 걸리게 한다.
|
||||
* ★ SiteOntology 대표 키워드가 오면 `<상호> · <키워드>` 다 (2026-09-14).
|
||||
* "숙소" 는 업종별 고정어라 "군산 숙소" 질의에만 걸린다. 키워드는 백엔드가 이 가게 자료로 거르고
|
||||
* 시·군 이름을 품은 것만 보내므로(services/seo_keywords) 지역 신호는 그대로 남는다.
|
||||
* 붙였더니 15자보다 짧으면 예전 제목으로 떨어진다.
|
||||
*/
|
||||
function homeTitle(payload: SitePayload): string {
|
||||
const {place} = payload;
|
||||
const keyword = payload.seo?.titleKeyword?.trim();
|
||||
if (keyword) {
|
||||
const title = `${place.name} · ${keyword}`;
|
||||
if (title.length >= MIN_TITLE_LENGTH) return title;
|
||||
}
|
||||
|
||||
const region = place.addressRegion && place.addressRegion !== localName(payload)
|
||||
? place.addressRegion
|
||||
: undefined;
|
||||
@@ -144,6 +159,12 @@ function homeTitle(payload: SitePayload): string {
|
||||
return [place.name, where].filter(Boolean).join(' · ');
|
||||
}
|
||||
|
||||
/** `<meta name="keywords">` 값. 키워드가 없으면 undefined — head 가 태그를 만들지 않는다. */
|
||||
export function metaKeywords(payload: SitePayload): string | undefined {
|
||||
const words = (payload.seo?.keywords ?? []).map((word) => word.trim()).filter(Boolean);
|
||||
return words.length > 0 ? words.join(', ') : undefined;
|
||||
}
|
||||
|
||||
export function homeMeta(payload: SitePayload): PageMeta {
|
||||
const image = primaryImage(payload);
|
||||
return {
|
||||
@@ -152,5 +173,6 @@ export function homeMeta(payload: SitePayload): PageMeta {
|
||||
canonical: url(payload),
|
||||
ogImage: image?.url,
|
||||
ogImageAlt: image?.alt,
|
||||
keywords: metaKeywords(payload),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user