feat(theme): make NavTitle component ejectable#3022
Conversation
## 修改总结 ### 1. 创建独立的 NavTitle 文件夹 - 新建 `src/theme/components/NavTitle/index.tsx` - 主组件 - 新建 `src/theme/components/NavTitle/index.scss` - 样式文件 ### 2. 替换 useLocaleSiteData hook 在新的 NavTitle 组件中,将废弃的 `useLocaleSiteData` hook 替换为直接使用 `useSite` 和 `useLang`: ```tsx // 旧代码 const localeData = useLocaleSiteData(); const title = (localeData.title ?? site.title) || 'Home'; // 新代码 const lang = useLang(); const locales = themeConfig?.locales; const localeInfo = locales?.find(locale => locale.lang === lang); const title = (localeInfo?.title ?? site.title) || 'Home'; ``` ### 3. 更新相关文件 - `src/theme/components/Nav/index.tsx` - 从 `@theme` 导入 NavTitle - `src/theme/index.ts` - 导出 NavTitle 组件 - `src/node/eject.ts` - 添加 'NavTitle' 到可 eject 组件列表 - `src/runtime/utils.ts` 和 `src/runtime/index.ts` - 导出 `addTrailingSlash` 工具函数 ### 4. 删除旧文件 - 删除 `src/theme/components/Nav/NavTitle.tsx` - 删除 `src/theme/components/Nav/NavTitle.scss` 现在用户可以通过 `rspress eject NavTitle` 命令来 eject NavTitle 组件并进行自定义。
✅ Deploy Preview for rspress-v2 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Rsdoctor Bundle Diff AnalysisFound 3 projects in monorepo, 3 projects with changes. 📊 Quick Summary
📋 Detailed Reports (Click to expand)📁 nodePath:
📦 Download Diff Report: node Bundle Diff 📁 webPath:
📦 Download Diff Report: web Bundle Diff 📁 node_mdPath:
📦 Download Diff Report: node_md Bundle Diff Generated by Rsdoctor GitHub Action |
There was a problem hiding this comment.
Pull request overview
This PR refactors the NavTitle component to make it ejectable and replaces the deprecated useLocaleSiteData hook with direct usage of useSite and useLang hooks, following the recommended migration pattern.
Changes:
- Moved NavTitle from Nav subfolder to its own top-level component folder with proper export
- Replaced deprecated
useLocaleSiteDatahook withuseSiteanduseLanghooks - Added NavTitle to the list of ejectable components
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/theme/index.ts | Exports NavTitle component for external use |
| packages/core/src/theme/components/NavTitle/index.tsx | Refactored to use useSite/useLang instead of deprecated useLocaleSiteData; logic remains functionally equivalent |
| packages/core/src/theme/components/NavTitle/index.scss | Added CSS styles for logo display and dark mode (new file, previously referenced as NavTitle.scss) |
| packages/core/src/theme/components/Nav/index.tsx | Updated import to use NavTitle from @theme exports instead of local import |
| packages/core/src/runtime/utils.ts | Exports addTrailingSlash utility function |
| packages/core/src/runtime/index.ts | Exports addTrailingSlash from runtime module |
| packages/core/src/node/eject.ts | Added NavTitle to the list of ejectable components |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- **英文**: `website/docs/en/ui/components/nav-title.mdx` - **中文**: `website/docs/zh/ui/components/nav-title.mdx` 文档包含: 1. 组件介绍 2. 基本用法(从配置读取 logo/title) 3. 自定义方式(通过 `navTitle` 属性或 `beforeNavTitle`/`afterNavTitle` 插槽) 4. 配置项说明(logo、logoText、title) 5. 国际化支持说明
Summary
Make NavTitle a standalone ejectable component.
Related Issue
#2963
#2952
Checklist
AI Summary
Changes Made
Moved NavTitle to standalone folder structure
Nav/NavTitle.tsx→NavTitle/index.tsxNav/NavTitle.scss→NavTitle/index.scssReplaced deprecated
useLocaleSiteDatahookuseLocaleSiteData()hook to directly usinguseSite()anduseLang()hooksAdded NavTitle to ejectable components list
getAvailableComponents()ineject.tsrspress eject NavTitleto customize the componentUpdated exports
NavTitlefromtheme/index.tsaddTrailingSlashutility fromruntime/utils.tsandruntime/index.ts(required by NavTitle)Updated Nav component imports
@themeinstead of relative pathWhy These Changes
useLocaleSiteDatahookThis PR was written using Vibe Kanban