Skip to content

fix: 所有内部链接支持动态 BASE_PATH - #25

Merged
xkcoding merged 1 commit into
masterfrom
fix/base-path-links
Jan 16, 2026
Merged

xkcoding merged 1 commit into
masterfrom
fix/base-path-links

Conversation

@xkcoding

Copy link
Copy Markdown
Owner

Summary

  • 新增 getUrl() 工具函数统一处理 BASE_URL 前缀
  • 修复所有组件中的硬编码链接,确保在 GitHub Pages (/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、sitemap
  • src/pages/index.astro - 首页内部链接

Test plan

  • 验证 GitHub Pages 部署后所有链接正常
  • 点击文章标题能正确跳转
  • 点击返回按钮能回到首页
  • 面包屑导航链接正常
  • favicon 和 sitemap 正常加载

🤖 Generated with Claude Code

- 新增 getUrl 工具函数处理 BASE_URL 前缀
- 修复 Header 导航链接
- 修复 BackButton 返回按钮链接
- 修复 Breadcrumb 面包屑链接
- 修复 404 页面返回首页链接
- 修复 Layout 中的 favicon 和 sitemap 链接
- 修复 index 页面的所有内部链接

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings January 16, 2026 03:44
@xkcoding
xkcoding merged commit 661180b into master Jan 16, 2026
6 checks passed
@xkcoding
xkcoding deleted the fix/base-path-links branch January 16, 2026 03:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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";

Copilot AI Jan 16, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants