Skip to content

Commit 94d19f9

Browse files
authored
[Docs Site] Always use current origin in search results (#19600)
1 parent 0852efc commit 94d19f9

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

astro.config.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,7 @@ export default defineConfig({
136136
]
137137
: []),
138138
starlightDocSearch({
139-
appId: "D32WIYFTUF",
140-
apiKey: "5cec275adc19dd3bc17617f7d9cf312a",
141-
indexName: "prod_devdocs",
142-
insights: true,
139+
clientOptionsModule: "./src/plugins/docsearch/index.ts",
143140
}),
144141
starlightImageZoom(),
145142
],

src/plugins/docsearch/index.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { DocSearchClientOptions } from "@astrojs/starlight-docsearch";
2+
3+
export default {
4+
appId: "D32WIYFTUF",
5+
apiKey: "5cec275adc19dd3bc17617f7d9cf312a",
6+
indexName: "prod_devdocs",
7+
insights: true,
8+
// Replace URL with the current origin so search
9+
// can be used in local development and previews.
10+
transformItems(items) {
11+
return items.map((item) => {
12+
const path = new URL(item.url).pathname;
13+
const url = new URL(path, window.origin);
14+
15+
return {
16+
...item,
17+
url: url.toString(),
18+
};
19+
});
20+
},
21+
} satisfies DocSearchClientOptions;

0 commit comments

Comments
 (0)