Skip to content

Commit 806b170

Browse files
fix: Add basePath prefix to all static asset paths for GitHub Pages
Next.js Image component does not auto-prepend basePath in unoptimized export mode. Expose NEXT_PUBLIC_BASE_PATH via env config and prefix all icon/image src paths to fix 404s on GitHub Pages deployment.
1 parent fc8d311 commit 806b170

11 files changed

Lines changed: 17 additions & 11 deletions

File tree

apps/web/next.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ import type { NextConfig } from "next";
22

33
const isGithubPages = process.env.GITHUB_PAGES === 'true';
44

5+
const basePath = isGithubPages ? '/DocStudio' : '';
6+
57
const nextConfig: NextConfig = {
68
// GitHub Pages 使用静态导出,Docker 部署使用 standalone 模式
79
output: isGithubPages ? 'export' : 'standalone',
810
// GitHub Pages 部署在子路径 /DocStudio 下
9-
basePath: isGithubPages ? '/DocStudio' : '',
11+
basePath,
12+
// 将 basePath 暴露给客户端代码,用于静态资源路径拼接
13+
env: {
14+
NEXT_PUBLIC_BASE_PATH: basePath,
15+
},
1016
images: {
1117
// GitHub Pages 不支持 next/image 优化,需要关闭
1218
unoptimized: isGithubPages,

apps/web/src/app/(public)/share/[token]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function ShareHeader({ title }: { title?: string }) {
102102
title="返回首页"
103103
>
104104
<Image
105-
src="/docStudio_icon.png"
105+
src={`${process.env.NEXT_PUBLIC_BASE_PATH || ''}/docStudio_icon.png`}
106106
alt="DocStudio"
107107
width={28}
108108
height={28}

apps/web/src/app/auth/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default function AuthLayout({
1919
<header className="flex items-center justify-between px-6 sm:px-10 py-5">
2020
<a href="/" className="flex items-center gap-2.5">
2121
<Image
22-
src="/docStudio_icon.png"
22+
src={`${process.env.NEXT_PUBLIC_BASE_PATH || ''}/docStudio_icon.png`}
2323
alt="DocStudio"
2424
width={30}
2525
height={30}

apps/web/src/app/contact/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function WeChatCard() {
147147
>
148148
<div className="bg-white dark:bg-[#1C1C20] rounded-2xl shadow-xl shadow-black/10 dark:shadow-black/50 border border-gray-200/80 dark:border-white/[0.08] p-3 flex flex-col items-center gap-2">
149149
<Image
150-
src="/we_chat.png"
150+
src={`${process.env.NEXT_PUBLIC_BASE_PATH || ''}/we_chat.png`}
151151
alt="微信二维码"
152152
width={960}
153153
height={960}

apps/web/src/app/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const metadata: Metadata = {
5858
follow: true,
5959
},
6060
icons: {
61-
icon: '/docStudio_icon.png',
61+
icon: `${process.env.NEXT_PUBLIC_BASE_PATH || ''}/docStudio_icon.png`,
6262
},
6363
};
6464

apps/web/src/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ export default function Home() {
777777
{/* Brand */}
778778
<div className="flex flex-col gap-3">
779779
<div className="flex items-center gap-2.5">
780-
<Image src="/docStudio_icon.png" alt="DocStudio" width={22} height={22} style={{ width: 22, height: 'auto' }} />
780+
<Image src={`${process.env.NEXT_PUBLIC_BASE_PATH || ''}/docStudio_icon.png`} alt="DocStudio" width={22} height={22} style={{ width: 22, height: 'auto' }} />
781781
<span className="text-sm font-semibold text-gray-900 dark:text-gray-100">DocStudio</span>
782782
</div>
783783
<p className="text-[13px] text-gray-500 dark:text-gray-500 leading-relaxed max-w-[220px]">

apps/web/src/app/public/spaces/[id]/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export default function PublicSpaceLayout({
124124

125125
<div className="flex items-center gap-3">
126126
<Link href="/" className="flex items-center gap-2">
127-
<Image src="/docStudio_icon.png" alt="DocStudio" width={24} height={24} />
127+
<Image src={`${process.env.NEXT_PUBLIC_BASE_PATH || ''}/docStudio_icon.png`} alt="DocStudio" width={24} height={24} />
128128
<span className="font-semibold text-gray-900 dark:text-white hidden sm:inline-block">DocStudio</span>
129129
</Link>
130130
</div>

apps/web/src/components/layout/public-header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function PublicHeader() {
8484
<div className="px-4 sm:px-6 lg:px-8 h-16 flex items-center justify-between max-w-7xl mx-auto">
8585
<div className="flex-1 flex justify-start">
8686
<Link href="/" className="flex items-center gap-3 relative group">
87-
<Image src="/docStudio_icon.png" alt="DocStudio" width={32} height={32} style={{ width: 32, height: 'auto' }} />
87+
<Image src={`${process.env.NEXT_PUBLIC_BASE_PATH || ''}/docStudio_icon.png`} alt="DocStudio" width={32} height={32} style={{ width: 32, height: 'auto' }} />
8888

8989
{/* Wrapper for smooth cross-fade of gradient text */}
9090
<div className="relative flex items-center">

apps/web/src/components/layout/sidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export function Sidebar() {
9191
<aside className="w-64 bg-white dark:bg-gray-800 border-r border-gray-200 dark:border-gray-700 flex-shrink-0 flex flex-col h-full">
9292
<div className="h-16 flex items-center gap-3 px-6 border-b border-gray-200 dark:border-gray-700">
9393
<Image
94-
src="/docStudio_icon.png"
94+
src={`${process.env.NEXT_PUBLIC_BASE_PATH || ''}/docStudio_icon.png`}
9595
alt="DocStudio"
9696
width={32}
9797
height={32}

apps/web/src/components/ui/loading-screen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function LoadingScreen({ className }: LoadingScreenProps) {
2626
{/* Center Icon (Logo) */}
2727
<div className="absolute flex items-center justify-center z-10 bg-white dark:bg-gray-900 rounded-full p-1">
2828
<Image
29-
src="/docStudio_icon.png"
29+
src={`${process.env.NEXT_PUBLIC_BASE_PATH || ''}/docStudio_icon.png`}
3030
alt="DocStudio Logo"
3131
width={20}
3232
height={20}

0 commit comments

Comments
 (0)