Skip to content

Commit e037591

Browse files
committed
fix: relative paths in different environments
1 parent 4894f11 commit e037591

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

astro.config.mjs

+5
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ export default defineConfig({
1212
defaultLocale: 'en',
1313
locales: ['en', 'zh'],
1414
},
15+
...(process.env.NODE_ENV === 'production' ? {
16+
site: 'https://openbuildxyz.github.io/',
17+
base: 'eco',
18+
trailingSlash: 'never',
19+
} : undefined),
1520
});

src/components/Header.astro

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,22 @@ interface Props {
1010
const { hideNavs = false } = Astro.props;
1111
const locale = (Astro.currentLocale || 'en') as 'en' | 'zh';
1212
const i18n = I18N_CONFIG[locale];
13-
const getLocaleUrl = getRelativeLocaleUrl.bind(null, locale);
13+
const baseUrl = import.meta.env.BASE_URL;
14+
const getLocaleUrl = (path: string) => getRelativeLocaleUrl(locale, path, baseUrl ? { prependWith: baseUrl } : undefined);
1415
---
1516

1617
<header>
1718
<nav>
1819
<h2><a href={getLocaleUrl('/')}>{i18n.site.title}</a></h2>
19-
{hideNavs !== true && (
20+
{hideNavs !== true ? (
2021
<div class="internal-links">
2122
<HeaderLink href={getLocaleUrl('/')}>{i18n.navs.home}</HeaderLink>
2223
<HeaderLink href={getLocaleUrl('/projects')}>{i18n.navs.projects}</HeaderLink>
2324
<HeaderLink href={getLocaleUrl('/contributing')}>{i18n.navs.contributing}</HeaderLink>
2425
<HeaderLink href={getLocaleUrl('/about')}>{i18n.navs.about}</HeaderLink>
2526
</div>
27+
) : (
28+
<div style="min-height: 78px;"></div>
2629
)}
2730
</nav>
2831
</header>

0 commit comments

Comments
 (0)