diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..5b53265 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,7 @@ +# Tech Log — 공개 기록은 읽히라고 있는 것이고, Studio 는 아니다. +User-agent: * +Allow: / +Disallow: /studio +Disallow: /api/ + +Sitemap: https://hyeonworks.com/sitemap.xml diff --git a/src/features/tech-log/presentation/public/components/public-document-header.tsx b/src/features/tech-log/presentation/public/components/public-document-header.tsx index 1b43122..e1e4663 100644 --- a/src/features/tech-log/presentation/public/components/public-document-header.tsx +++ b/src/features/tech-log/presentation/public/components/public-document-header.tsx @@ -5,49 +5,6 @@ import type { components } from "../../../contracts/studio/generated.ts"; import { ProseText } from "../../shared/public-render/prose-text.tsx"; import { DOCUMENT_KIND_LABELS } from "../../shared/document-kind-labels.ts"; -export function PublicDocumentHeader({ record }: { record: PublicRecord }) { - return ( -
- -

{record.title}

- {/* 요약은 여러 문단일 수 있다 — 그대로 넣으면 줄바꿈이 사라져 한 덩어리로 읽힌다. */} - -
-
-
유형
-
{DOCUMENT_KIND_LABELS[record.kind]}
-
-
-
프로젝트
-
{record.projectTitle}
-
-
-
게시
-
{record.publishedLabel}
-
-
-
- ); -} - export function publicRenderModelBase( record: PublicRecord, ): components["schemas"]["PublicRenderModelBase"] { diff --git a/src/features/tech-log/presentation/shared/public-render/public-record-renderer.tsx b/src/features/tech-log/presentation/shared/public-render/public-record-renderer.tsx index 3be152f..659b3a9 100644 --- a/src/features/tech-log/presentation/shared/public-render/public-record-renderer.tsx +++ b/src/features/tech-log/presentation/shared/public-render/public-record-renderer.tsx @@ -14,6 +14,7 @@ import { type PublicRelation, } from "./public-document-relations.tsx"; import { DOCUMENT_KIND_LABELS } from "../document-kind-labels.ts"; +import { useDocumentMetadata } from "../use-document-metadata.ts"; type PublicRenderModel = components["schemas"]["PublicRenderModel"]; type PublicRenderModelBase = components["schemas"]["PublicRenderModelBase"]; @@ -562,6 +563,15 @@ export function PublicRecordRenderer({ model: PublicRenderModel; embedded?: boolean; } & RenderDependencies) { + /* + 탭 제목과 설명에 지금 보는 문서를 반영한다. 라우터는 라우트마다 고정된 이름만 넣어서 + 공개 문서가 전부 "Reference · Tech Log" 였고, 설명은 모든 화면이 "Tech Log frontend" + 하나였다 — 탭을 여럿 띄우거나 링크를 공유하면 어느 글인지 알 수 없었다. + + 미리보기(embedded)는 Studio 안의 한 조각이므로 탭 이름을 건드리지 않는다. + */ + useDocumentMetadata(embedded ? undefined : model.title, model.summary); + switch (model.kind) { case "CASE": return ( diff --git a/src/features/tech-log/presentation/shared/use-document-metadata.ts b/src/features/tech-log/presentation/shared/use-document-metadata.ts new file mode 100644 index 0000000..db37bf4 --- /dev/null +++ b/src/features/tech-log/presentation/shared/use-document-metadata.ts @@ -0,0 +1,32 @@ +import { useEffect } from "react"; + +/** + * 열려 있는 문서를 탭 제목과 설명에 반영한다. + * + *

라우터는 라우트마다 고정된 제목만 넣는다. 그래서 공개 문서가 전부 "Reference · Tech Log" + * 같은 같은 이름이었고, 탭을 여럿 띄우거나 링크를 공유하면 어느 문서인지 알 수 없었다. + * 설명(`meta[name=description]`)은 모든 화면이 "Tech Log frontend" 하나였다. + * + *

라우터가 라우트 전환 시점에 제목을 넣고, 이 훅은 문서를 받은 뒤에 덮어쓴다 — 순서가 + * 그러하므로 서로 다투지 않는다. 화면을 떠날 때는 되돌려, 다음 라우트가 자기 제목을 넣기 전 + * 잠깐 남는 이름이 이전 문서의 것이 되지 않게 한다. + */ +export function useDocumentMetadata(title: string | undefined, description?: string): void { + useEffect(() => { + if (!title) return undefined; + const previousTitle = document.title; + const element = document.querySelector('meta[name="description"]'); + const previousDescription = element?.content; + + document.title = `${title} · Tech Log`; + if (element && description) { + // 설명은 한 줄이어야 한다 — 요약에 문단이 있으면 줄바꿈을 공백으로 접는다. + element.content = description.replace(/\s+/gu, " ").trim().slice(0, 200); + } + + return () => { + document.title = previousTitle; + if (element && previousDescription !== undefined) element.content = previousDescription; + }; + }, [title, description]); +} diff --git a/src/features/tech-log/presentation/studio/components/common-document-fields.tsx b/src/features/tech-log/presentation/studio/components/common-document-fields.tsx index 6903216..9f33de4 100644 --- a/src/features/tech-log/presentation/studio/components/common-document-fields.tsx +++ b/src/features/tech-log/presentation/studio/components/common-document-fields.tsx @@ -11,6 +11,13 @@ type CatalogEntry = components["schemas"]["CatalogEntry"]; */ const SUMMARY_MAX = 2000; +/** + * 목록·검색 카드는 요약을 세 줄에서 자른다. 작성자에게는 그 경계가 보이지 않아서, 500자를 써도 + * 독자가 받는 것은 앞 세 줄뿐이라는 사실을 알 방법이 없었다. 정확한 글자 수는 글자 폭에 따라 + * 달라지므로 어림수로 알린다 — 여기서 필요한 것은 정밀도가 아니라 경계가 있다는 사실이다. + */ +const SUMMARY_CARD_PREVIEW = 90; + /** 이 화면이 자기 칸 아래에 보여 줄 수 있는 경로. 나머지는 게시 버튼 옆에 남는다. */ export const COMMON_FIELD_PATHS = [ "/title", @@ -48,7 +55,7 @@ export function CommonDocumentFields({ 이름이 되어 "요약 412 / 600" 처럼 타자마다 이름이 바뀐다 — 이름은 「요약」로 두고 남은 자리는 그 옆에 따로 보여 준다. */} -