From c9389d9ad9bbe56679aeaad1a7003e3094b5719a Mon Sep 17 00:00:00 2001 From: Kian Newman-Hazel Date: Fri, 31 Jan 2025 11:18:52 +0000 Subject: [PATCH] [Docs Site] Always use current origin in search results --- astro.config.ts | 5 +---- src/plugins/docsearch/index.ts | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 src/plugins/docsearch/index.ts diff --git a/astro.config.ts b/astro.config.ts index 5e8b1322136834..d7099a81d7f5ff 100644 --- a/astro.config.ts +++ b/astro.config.ts @@ -136,10 +136,7 @@ export default defineConfig({ ] : []), starlightDocSearch({ - appId: "D32WIYFTUF", - apiKey: "5cec275adc19dd3bc17617f7d9cf312a", - indexName: "prod_devdocs", - insights: true, + clientOptionsModule: "./src/plugins/docsearch/index.ts", }), starlightImageZoom(), ], diff --git a/src/plugins/docsearch/index.ts b/src/plugins/docsearch/index.ts new file mode 100644 index 00000000000000..3c7fccb3839d90 --- /dev/null +++ b/src/plugins/docsearch/index.ts @@ -0,0 +1,21 @@ +import type { DocSearchClientOptions } from "@astrojs/starlight-docsearch"; + +export default { + appId: "D32WIYFTUF", + apiKey: "5cec275adc19dd3bc17617f7d9cf312a", + indexName: "prod_devdocs", + insights: true, + // Replace URL with the current origin so search + // can be used in local development and previews. + transformItems(items) { + return items.map((item) => { + const path = new URL(item.url).pathname; + const url = new URL(path, window.origin); + + return { + ...item, + url: url.toString(), + }; + }); + }, +} satisfies DocSearchClientOptions;