Skip to content

Commit 8d95195

Browse files
committed
made Pagefinder.svelt just use Base URL
(passed from search.astro) instead of hardcoded check Added trailing slashed to base path in configs for BP and for consistent URL construction
1 parent f81b322 commit 8d95195

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
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}
3841
>
3942
<div
4043
slot="no-results"

sites/browserpod/astro.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { resolve } from "node:path";
66
// https://astro.build/config
77
export default defineConfig({
88
site: "https://browserpod.io",
9-
base: "/docs",
9+
base: "/docs/",
1010
integrations: [
1111
icon(),
1212
theme({

sites/cheerpj/astro.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { resolve } from "node:path";
66
// https://astro.build/config
77
export default defineConfig({
88
site: "https://cheerpj.com",
9-
base: "/docs",
9+
base: "/docs/",
1010
integrations: [
1111
icon(),
1212
theme({

0 commit comments

Comments
 (0)