From 833943a286c5e8dc5dc307638691f7a833c428d2 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Mon, 31 Aug 2026 09:18:27 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B2=80=EC=83=89=20=EA=B2=B0=EA=B3=BC?= =?UTF-8?q?=EC=97=90=20=EC=B0=BE=EC=9D=80=20=EB=A7=90=EC=9D=84=20=ED=91=9C?= =?UTF-8?q?=EC=8B=9C=ED=95=98=EA=B3=A0=20=EB=A6=B4=EB=A6=AC=EC=8A=A4=20?= =?UTF-8?q?=ED=83=AD=20=EC=A0=9C=EB=AA=A9=EC=9D=84=20=EA=B5=AC=EB=B6=84?= =?UTF-8?q?=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 검색 결과가 제목과 요약을 그대로 보여 주기만 했다. "session" 으로 찾아도 어느 대목이 걸렸는지 눈으로 다시 찾아야 했고, 요약은 목록에서 세 줄로 잘리므로 걸린 대목이 잘린 뒤쪽이면 왜 이 결과가 나왔는지조차 알 수 없었다. 대소문자는 구분하지 않는다 — 이 저장소의 글은 Session 과 session 을 섞어 쓴다. 배경을 칠하는 대신 밑줄과 굵기로 표시해 목록의 회색 톤을 지킨다. 릴리스 탭 제목이 판마다 「변경 기록 · Tech Log」로 같았다. 이 화면은 공개 문서 렌더러를 타지 않아 앞서 붙인 훅이 닿지 않았다. 훅은 이른 return 보다 앞에 둔다. 처음에 데이터를 꺼낸 뒤에 불렀더니 렌더마다 호출 순서가 달라져 lint 가 잡았다. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_011nAjrqNHGPNngN4aUbcyvJ --- .../public/components/search-dialog.tsx | 9 ++++- .../public/pages/release-page.tsx | 13 ++++++- .../presentation/shared/highlight-match.tsx | 37 ++++++++++++++++++ .../tech-log/presentation/styles/globals.css | 3 ++ tests/component/highlight-match.test.tsx | 38 +++++++++++++++++++ 5 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 src/features/tech-log/presentation/shared/highlight-match.tsx create mode 100644 tests/component/highlight-match.test.tsx diff --git a/src/features/tech-log/presentation/public/components/search-dialog.tsx b/src/features/tech-log/presentation/public/components/search-dialog.tsx index c16439d..43ecc06 100644 --- a/src/features/tech-log/presentation/public/components/search-dialog.tsx +++ b/src/features/tech-log/presentation/public/components/search-dialog.tsx @@ -2,6 +2,7 @@ import { useId, useRef, useState } from "react"; import { Link } from "react-router-dom"; import { usePublicContent } from "../use-public-content.tsx"; +import { HighlightMatch } from "../../shared/highlight-match.tsx"; type SearchDialogProps = { className?: string; @@ -105,8 +106,12 @@ export function SearchDialog({
  • {entry.contentType} - {entry.title} -

    {entry.summary}

    + + + +

    + +

  • ))} diff --git a/src/features/tech-log/presentation/public/pages/release-page.tsx b/src/features/tech-log/presentation/public/pages/release-page.tsx index fb3de3c..de9616c 100644 --- a/src/features/tech-log/presentation/public/pages/release-page.tsx +++ b/src/features/tech-log/presentation/public/pages/release-page.tsx @@ -6,6 +6,7 @@ import { } from "../../../../../presentation/routes/route-input.tsx"; import { usePublicContent } from "../use-public-content.tsx"; import { ProseText } from "../../shared/public-render/prose-text.tsx"; +import { useDocumentMetadata } from "../../shared/use-document-metadata.ts"; export function ReleasePage() { const { params } = useRouteInput<"TECH_LOG_RELEASE">(); @@ -13,9 +14,17 @@ export function ReleasePage() { const view = usePublicContent(["tech-log", "release", version], async (queries) => ({ release: await queries.getRelease(version), })); - if (!view.ready) return view.fallback; + /* + 탭 제목이 릴리스마다 「변경 기록 · Tech Log」로 같아 어느 판인지 알 수 없었다. + 훅은 이른 return 보다 앞에 있어야 한다 — 렌더마다 같은 순서로 불려야 하므로. + */ + const release = view.ready ? view.data.release : undefined; + useDocumentMetadata( + release ? `v${release.version} ${release.title}` : undefined, + release?.summary, + ); - const { release } = view.data; + if (!view.ready) return view.fallback; if (!release) return ; return ( diff --git a/src/features/tech-log/presentation/shared/highlight-match.tsx b/src/features/tech-log/presentation/shared/highlight-match.tsx new file mode 100644 index 0000000..4b23630 --- /dev/null +++ b/src/features/tech-log/presentation/shared/highlight-match.tsx @@ -0,0 +1,37 @@ +import { Fragment } from "react"; + +/** + * 검색 결과에서 찾은 말을 표시한다. + * + *

    결과 목록은 제목과 요약을 그대로 보여 주기만 했다. "session" 으로 찾아도 어느 대목이 + * 걸린 것인지 눈으로 다시 찾아야 했고, 요약이 세 줄로 잘리므로 걸린 대목이 잘린 뒤쪽에 있으면 + * 왜 이 결과가 나왔는지조차 알 수 없었다. + * + *

    대소문자는 구분하지 않는다 — 이 저장소의 글은 `Session` 과 `session` 을 섞어 쓴다. + */ +function escapeForRegExp(value: string): string { + return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&"); +} + +export function HighlightMatch({ text, query }: { text: string; query: string }) { + const needle = query.trim(); + if (!needle) return <>{text}; + + const pattern = new RegExp(`(${escapeForRegExp(needle)})`, "giu"); + const parts = text.split(pattern); + // 걸린 곳이 없으면 원문 그대로 — 쪼갠 조각을 다시 붙이지 않는다. + if (parts.length === 1) return <>{text}; + + return ( + <> + {parts.map((part, index) => + // split 이 만든 조각 중 홀수 자리가 잡힌 부분이다. + index % 2 === 1 ? ( + {part} + ) : ( + {part} + ), + )} + + ); +} diff --git a/src/features/tech-log/presentation/styles/globals.css b/src/features/tech-log/presentation/styles/globals.css index 67ec74e..8f957c7 100644 --- a/src/features/tech-log/presentation/styles/globals.css +++ b/src/features/tech-log/presentation/styles/globals.css @@ -1404,6 +1404,9 @@ dialog::backdrop { line-height: 1.5; } +/* 검색에서 걸린 말. 배경을 칠하는 대신 밑줄과 굵기로 — 목록의 회색 톤을 깨지 않는다. */ +.search-results mark { background: none; color: var(--ink); font-weight: 650; text-decoration: underline; text-underline-offset: 3px; } + .search-results a:hover strong { color: var(--signal); } diff --git a/tests/component/highlight-match.test.tsx b/tests/component/highlight-match.test.tsx new file mode 100644 index 0000000..f750bd1 --- /dev/null +++ b/tests/component/highlight-match.test.tsx @@ -0,0 +1,38 @@ +// @vitest-environment jsdom + +import { render } from "@testing-library/react"; +import { describe, expect, it } from "vitest"; + +import { HighlightMatch } from "../../src/features/tech-log/presentation/shared/highlight-match.tsx"; + +/** + * 검색 결과가 제목과 요약을 그대로 보여 주기만 해서, 무엇이 걸려 이 결과가 나왔는지 눈으로 + * 다시 찾아야 했다. + */ +describe("검색어 강조", () => { + it("찾은 말을 표시한다", () => { + const { container } = render( + , + ); + const marks = [...container.querySelectorAll("mark")].map((m) => m.textContent); + // 대소문자를 구분하지 않는다 — 이 저장소의 글은 둘을 섞어 쓴다. + expect(marks).toEqual(["Session", "session"]); + expect(container.textContent).toBe("Session Cookie와 session ID는 다르다"); + }); + + it("걸린 곳이 없으면 원문 그대로 둔다", () => { + const { container } = render(); + expect(container.querySelectorAll("mark")).toHaveLength(0); + expect(container.textContent).toBe("토큰 경계"); + }); + + it("정규식 문자가 들어가도 깨지지 않는다", () => { + const { container } = render(); + expect(container.querySelectorAll("mark")).toHaveLength(2); + }); + + it("빈 검색어면 아무것도 표시하지 않는다", () => { + const { container } = render(); + expect(container.querySelectorAll("mark")).toHaveLength(0); + }); +});