Skip to content

Commit 50183fe

Browse files
committed
made Pagefinder.svelt just use Base URL (passed from search.astro) instead of hardcoded check
1 parent f81b322 commit 50183fe

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

packages/astro-theme/components/search/Pagefind.svelte

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
export let productId: string | undefined;
66
export let placeholder: string;
77
export let locale: string;
8+
export let baseUrl: string;
89
910
let pagefind: Pagefind;
1011
let results: PagefindResult[] = [];
1112
let noResultsForQuery = false;
1213
1314
onMount(async () => {
14-
const url =
15-
productId === "cheerpj3"
16-
? new URL(window.origin + "/docs/pagefind/pagefind.js").href // Add /docs/ for CJ so search bar is able to link correctly
17-
: new URL(window.origin + "/pagefind/pagefind.js").href; // Can't use import.meta.url because Vite prefixes the module with /@fs.
15+
const url = new URL(window.origin + baseUrl + "pagefind/pagefind.js").href;
1816
// @ts-ignore
1917
const pf = await import(/* @vite-ignore */ url);
2018
await pf.init();
@@ -35,7 +33,7 @@
3533
3634
const response = await pagefind.debouncedSearch(query, {
3735
filters: { productId, language: locale },
38-
baseUrl: import.meta.env.BASE_URL,
36+
baseUrl,
3937
});
4038
if (response === null) {
4139
// Debounce.

packages/astro-theme/components/search/Search.astro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { t } from "../../lib/i18n";
88
interface Props {
99
filterProductId?: Product | "blog"; // data-pagefind-filter productId
1010
}
11+
12+
const baseUrl = import.meta.env.BASE_URL || "/";
1113
---
1214

1315
<site-search class="inline-block w-full h-10 max-w-full">
@@ -35,6 +37,7 @@ interface Props {
3537
productId={Astro.props.filterProductId}
3638
placeholder={t("Type to search...", Astro.currentLocale)}
3739
locale={Astro.currentLocale}
40+
baseUrl={baseUrl}
3841
>
3942
<div
4043
slot="no-results"

0 commit comments

Comments
 (0)