Skip to content

Commit 3ec045e

Browse files
committed
Fix search path in browser during deployment
1 parent 47d94ab commit 3ec045e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

catalog/components/search-bar.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ export default function SearchBar() {
2222
useEffect(() => {
2323
// Find the hero-search container and render Pagefind there
2424
const heroSearchContainer = document.getElementById("hero-search");
25-
const basePath = getBasePath();
25+
26+
// Detect base path from the current page URL
27+
// If we're on GitHub Pages, the path will be /implementation-catalog/...
28+
const currentPath = window.location.pathname;
29+
const basePath = currentPath.startsWith('/implementation-catalog') ? '/implementation-catalog' : '';
2630

2731
if (typeof window !== "undefined" && heroSearchContainer) {
2832
// Load Pagefind CSS dynamically

catalog/lib/utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
* Get the base path for the application
33
* Returns '/implementation-catalog' in production (GitHub Pages)
44
* Returns '' in development
5+
*
6+
* Note: This checks for the environment variable at build time.
7+
* Next.js replaces process.env.NEXT_PUBLIC_* at build time.
58
*/
69
export function getBasePath(): string {
7-
return process.env.NEXT_PUBLIC_BASE_PATH === 'true' ? '/implementation-catalog' : '';
10+
// Check if we're in production mode (GitHub Pages)
11+
// The NEXT_PUBLIC_BASE_PATH env var is set during build
12+
const isProduction = process.env.NEXT_PUBLIC_BASE_PATH === 'true';
13+
return isProduction ? '/implementation-catalog' : '';
814
}
915

1016
/**

0 commit comments

Comments
 (0)