Repository navigation
feat(search): 搜索默认新标签打开 + 设置可切换 - #19
Merged
todosdev[bot] merged 1 commit intoOct 29, 2026
Merged
Conversation
设置新增 searchNewTab(KV search_new_tab,无键默认开),SearchBar 公共分支走 window.open(_blank, noopener,noreferrer) 或当前页;管理面加开关,契约与测试同步。 Checkpoint: 2oHVJReFelhYK_YjPky1-
This was referenced Nov 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
window.open(url, "_blank", "noopener,noreferrer")),起始页与会话不再被搜索结果顶掉;管理面「站点设置」新增开关「搜索在新标签页打开」(默认开),可切回当前页跳转。searchNewTab,沿既有 KV 形态存search_new_tab("1"/"0",无此键的存量库按true),前后端类型、读写链与 API 契约文档同步;无 schema 迁移、无新依赖。Changes
搜索与公开页
web/src/components/search-bar.tsx:submit抽出公共分支,按openInNewTab(默认true)决定新标签或当前页;引擎不分叉,自定义引擎同样生效。web/src/components/public-page.tsx:把settings.searchNewTab传入SearchBar(与openInNewTab = true的双重默认兼容旧数据)。web/src/lib/types.ts:SiteSettings增加searchNewTab: boolean。web/src/lib/mockDb.ts:种子数据带上默认开;读取旧 localStorage 时归一化补齐,仅开发环境 mock 生效。管理面设置
web/src/components/admin/settings-panels.tsx:SettingsPanel新增整行开关(RadixSwitch+Label+ 说明文案),随「保存设置」提交;缺字段时按默认开渲染。Worker / 契约
worker/src/types.ts、worker/src/services/site-data.ts:SiteSettingsDto.searchNewTab,读取逻辑(search_new_tab ?? "1") === "1",/api/public、/api/private、/api/admin/settings同步带出。worker/src/routes/admin.ts:SETTING_KEYS增加search_new_tab;PUT /api/admin/settings严格布尔写入"1"/"0",非布尔返回 400searchNewTab must be a boolean。docs/api-contract.md:公开 DTO 示例与站点设置端点补上字段与语义。测试
web/test/search-bar.test.tsx(6 条):默认新标签、显式开启、切引擎后仍新标签、关闭后当前页、切引擎后当前页、空查询不跳转。web/test/settings-panels.test.tsx+3:默认开、关闭后保存false、缺字段按默认开。web/test/public-page.test.tsx+2:设置false时当前页跳转;缺字段时按默认开。worker/test/settings.test.ts+5:无键默认true(admin +/api/public)、"1"/"0"往返并进公开端点、不影响其他设置、非布尔 400、白名单含键;worker/test/setup.test.ts的 settings 键集合断言同步新增字段。Testing
pnpm lint(122 files;28 条既有 warning 均在未改动的 shadcn/ui 与main.tsx,本次改动文件 0 warning)、pnpm format:check(119 files,无改动)、pnpm typecheck(web + worker)、pnpm build、pnpm test→ worker 9 files / 102 tests passed,web 7 files / 34 tests passed。window.open实参为搜索 URL +"_blank"+"noopener,noreferrer",当前页停在/;切到自定义引擎后结论一致;开关关闭后回车为当前页跳转、无新标签目标;管理面开关行 1440/360 两档均无横向溢出,点击关掉后保存实测PUT /api/admin/settings带"searchNewTab": false并回读为false。