diff --git a/astro.config.mjs b/astro.config.mjs index 0580c7b9..89a16158 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -198,12 +198,7 @@ export default defineConfig({ }, }), starlightDocSearch({ - appId: 'XBW1JU7CW5', - apiKey: '6b0341e2f50196d328d088dbb5cd6166', - indexName: 'localstack', - searchParameters: { - facets: ['lvl0'], - }, + clientOptionsModule: './src/config/docsearch.ts', }), ], sidebar: [ diff --git a/src/config/docsearch.ts b/src/config/docsearch.ts new file mode 100644 index 00000000..f93ee99e --- /dev/null +++ b/src/config/docsearch.ts @@ -0,0 +1,46 @@ +import type { DocSearchClientOptions } from '@astrojs/starlight-docsearch'; + +export default { + appId: 'XBW1JU7CW5', + apiKey: '6b0341e2f50196d328d088dbb5cd6166', + indexName: 'localstack', + searchParameters: { + facets: ['lvl0'], + }, + transformSearchClient(searchClient) { + return { + ...searchClient, + search(requests: any) { + // Get the current pathname at runtime + const pathname = typeof window !== 'undefined' ? window.location.pathname : ''; + + // Determine the boost filter based on pathname + let boostFilter: string | null = null; + if (pathname.startsWith('/aws/')) { + boostFilter = "hierarchy.lvl0:LocalStack for AWS"; + } else if (pathname.startsWith('/snowflake/')) { + boostFilter = "hierarchy.lvl0:LocalStack for Snowflake"; + } + + if (!boostFilter) { + return searchClient.search(requests); + } + + if (!requests || typeof requests !== 'object' || !Array.isArray(requests.requests)) { + return searchClient.search(requests); + } + + const transformedRequests = { + ...requests, + requests: requests.requests.map((request: any) => ({ + ...request, + optionalFilters: [boostFilter], + sumOrFiltersScores: true, + })), + }; + + return searchClient.search(transformedRequests); + }, + }; + }, +} satisfies DocSearchClientOptions; \ No newline at end of file