Skip to content

Commit 6dd747e

Browse files
committed
build: configure base path for GitHub Pages deployment
- Update astro.config.mjs with the repository name as base - Use import.meta.env.BASE_URL for all links to support sub-path routing
1 parent f21647e commit 6dd747e

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

astro.config.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import react from '@astrojs/react';
88
// https://astro.build/config
99
export default defineConfig({
1010
site: 'https://zhongyangxun.github.io',
11-
base: '/',
11+
// can access this value via `import.meta.env.BASE_URL`
12+
base: '/blog/',
1213

1314
vite: {
1415
plugins: [tailwindcss()],

src/components/Navigation.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@ import {
55
NavigationMenuLink,
66
} from './ui/navigation-menu';
77

8+
const { BASE_URL } = import.meta.env;
9+
810
type NavigationProps = {
911
pathname: string;
1012
};
1113

1214
const Navigation = ({ pathname }: NavigationProps) => {
1315
const links = [
1416
{
15-
href: '/',
17+
href: BASE_URL,
1618
label: 'Home',
1719
},
1820
{
19-
href: '/about',
21+
href: `${BASE_URL}about`,
2022
label: 'About',
2123
},
2224
];

src/components/PostItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const PostItem = ({ id, title, pubDate, description }: PostItemProps) => {
99
<div className="flex-col mb-4">
1010
<div>
1111
<a
12-
href={`/posts/${id}`}
12+
href={`${import.meta.env.BASE_URL}posts/${id}`}
1313
className="font-semibold text-sm hover:underline line-clamp-2"
1414
>
1515
{title}

0 commit comments

Comments
 (0)