fix: 所有内部链接支持动态 BASE_PATH - #25
Merged
Merged
Conversation
- 新增 getUrl 工具函数处理 BASE_URL 前缀 - 修复 Header 导航链接 - 修复 BackButton 返回按钮链接 - 修复 Breadcrumb 面包屑链接 - 修复 404 页面返回首页链接 - 修复 Layout 中的 favicon 和 sitemap 链接 - 修复 index 页面的所有内部链接 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR introduces a centralized URL utility function to handle dynamic BASE_PATH configuration for all internal links. The changes ensure that the blog works correctly in both GitHub Pages (/MyBlog) and self-hosted (/) environments.
Changes:
- Added
getUrl()utility function to centralize BASE_URL path handling - Updated all hard-coded internal links across components and pages to use
getUrl() - Applied the utility to navigation, breadcrumbs, buttons, and layout links
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/utils/getUrl.ts | New utility function for URL path normalization with BASE_URL support |
| src/pages/index.astro | Updated RSS feed and navigation links to use getUrl() |
| src/pages/404.astro | Updated home link to use getUrl() |
| src/layouts/Layout.astro | Updated favicon and sitemap links to use getUrl() |
| src/components/Header.astro | Updated all navigation menu links to use getUrl() |
| src/components/Breadcrumb.astro | Updated breadcrumb navigation links to use getUrl() |
| src/components/BackButton.astro | Updated back button link to use getUrl() |
Comments suppressed due to low confidence (1)
src/components/BackButton.astro:24
- Corrected spelling of 'Praam' to 'Param'.
/* Update Search Praam */
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return pathNameMap[path] || path; | ||
| } | ||
|
|
||
| import { getUrl } from "@/utils/getUrl"; |
There was a problem hiding this comment.
Import statement is placed after the executable code (lines 3-38) instead of at the top of the frontmatter section. Move this import to the top with other imports for consistency and better readability.
xkcoding
added a commit
that referenced
this pull request
Jan 16, 2026
- 新增 getUrl 工具函数处理 BASE_URL 前缀 - 修复 Header 导航链接 - 修复 BackButton 返回按钮链接 - 修复 Breadcrumb 面包屑链接 - 修复 404 页面返回首页链接 - 修复 Layout 中的 favicon 和 sitemap 链接 - 修复 index 页面的所有内部链接 Co-authored-by: 柏玄(沈扬凯) <shenyangkai@xiaohongshu.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
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
getUrl()工具函数统一处理BASE_URL前缀/MyBlog) 和自部署 (/) 环境下都能正常工作Changed Files
src/utils/getUrl.ts- 新增工具函数src/components/Header.astro- 导航链接src/components/BackButton.astro- 返回按钮src/components/Breadcrumb.astro- 面包屑导航src/pages/404.astro- 404 页面返回首页src/layouts/Layout.astro- favicon、sitemapsrc/pages/index.astro- 首页内部链接Test plan
🤖 Generated with Claude Code