Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions packages/astro-theme/components/search/Pagefind.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
export let productId: string | undefined;
export let placeholder: string;
export let locale: string;
export let baseUrl: string;

let pagefind: Pagefind;
let results: PagefindResult[] = [];
let noResultsForQuery = false;

onMount(async () => {
const url =
productId === "cheerpj3"
? new URL(window.origin + "/docs/pagefind/pagefind.js").href // Add /docs/ for CJ so search bar is able to link correctly
: new URL(window.origin + "/pagefind/pagefind.js").href; // Can't use import.meta.url because Vite prefixes the module with /@fs.
const url = new URL(window.origin + baseUrl + "pagefind/pagefind.js").href;
// @ts-ignore
const pf = await import(/* @vite-ignore */ url);
await pf.init();
Expand All @@ -35,7 +33,7 @@

const response = await pagefind.debouncedSearch(query, {
filters: { productId, language: locale },
baseUrl: import.meta.env.BASE_URL,
baseUrl,
});
if (response === null) {
// Debounce.
Expand Down
3 changes: 3 additions & 0 deletions packages/astro-theme/components/search/Search.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { t } from "../../lib/i18n";
interface Props {
filterProductId?: Product | "blog"; // data-pagefind-filter productId
}

const baseUrl = import.meta.env.BASE_URL || "/";
---

<site-search class="inline-block w-full h-10 max-w-full">
Expand Down Expand Up @@ -35,6 +37,7 @@ interface Props {
productId={Astro.props.filterProductId}
placeholder={t("Type to search...", Astro.currentLocale)}
locale={Astro.currentLocale}
{baseUrl}
>
<div
slot="no-results"
Expand Down
2 changes: 1 addition & 1 deletion sites/browserpod/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { resolve } from "node:path";
// https://astro.build/config
export default defineConfig({
site: "https://browserpod.io",
base: "/docs",
base: "/docs/",
integrations: [
icon(),
theme({
Expand Down
2 changes: 1 addition & 1 deletion sites/cheerpj/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { resolve } from "node:path";
// https://astro.build/config
export default defineConfig({
site: "https://cheerpj.com",
base: "/docs",
base: "/docs/",
integrations: [
icon(),
theme({
Expand Down