File tree Expand file tree Collapse file tree 3 files changed +38
-4
lines changed
Expand file tree Collapse file tree 3 files changed +38
-4
lines changed Original file line number Diff line number Diff line change 11// @ts -check
2- import { defineConfig } from "astro/config" ;
2+ import { defineConfig , envField } from "astro/config" ;
33import starlight from "@astrojs/starlight" ;
44import tailwindcss from "@tailwindcss/vite" ;
55import starlightOpenAPI , { openAPISidebarGroups } from "starlight-openapi" ;
@@ -71,9 +71,7 @@ export default defineConfig({
7171 ...( hasAlgoliaConfig
7272 ? [
7373 starlightDocSearch ( {
74- appId : ALGOLIA_APP_ID ,
75- apiKey : ALGOLIA_SEARCH_API_KEY ,
76- indexName : ALGOLIA_INDEX_NAME ,
74+ clientOptionsModule : "./src/config/docsearch.ts" ,
7775 } ) ,
7876 ]
7977 : [ ] ) ,
@@ -128,4 +126,14 @@ export default defineConfig({
128126 remarkPlugins : [ remarkMath ] ,
129127 rehypePlugins : [ rehypeKatex ] ,
130128 } ,
129+ env : {
130+ schema : {
131+ ALGOLIA_APP_ID : envField . string ( { context : "client" , access : "public" } ) ,
132+ ALGOLIA_SEARCH_API_KEY : envField . string ( {
133+ context : "client" ,
134+ access : "public" ,
135+ } ) ,
136+ ALGOLIA_INDEX_NAME : envField . string ( { context : "client" , access : "public" } ) ,
137+ } ,
138+ } ,
131139} ) ;
Original file line number Diff line number Diff line change 1+ import type { DocSearchClientOptions } from "@astrojs/starlight-docsearch" ;
2+ import { ALGOLIA_APP_ID , ALGOLIA_SEARCH_API_KEY , ALGOLIA_INDEX_NAME } from "astro:env/client" ;
3+
4+ const getFacetFilters = ( ) : string [ ] =>
5+ typeof document !== "undefined" ? [ `lang:${ document . documentElement . lang } ` ] : [ ] ;
6+
7+ const getEnvVar = ( key : string , value : string | undefined ) : string => {
8+ if ( ! value ) {
9+ throw new Error ( `Missing environment variable: ${ key } ` ) ;
10+ }
11+ return value ;
12+ } ;
13+
14+ export default Object . freeze ( {
15+ appId : getEnvVar ( "ALGOLIA_APP_ID" , ALGOLIA_APP_ID as string | undefined ) ,
16+ apiKey : getEnvVar ( "ALGOLIA_SEARCH_API_KEY" , ALGOLIA_SEARCH_API_KEY as string | undefined ) ,
17+ indexName : getEnvVar ( "ALGOLIA_INDEX_NAME" , ALGOLIA_INDEX_NAME as string | undefined ) ,
18+ searchParameters : {
19+ get facetFilters ( ) {
20+ return getFacetFilters ( ) ;
21+ } ,
22+ } ,
23+ } satisfies DocSearchClientOptions ) ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import Default from "@astrojs/starlight/components/Head.astro";
44import AnalyticsComponent from " @vercel/analytics/astro" ;
55import type { AnalyticsProps } from " @vercel/analytics" ;
66import type { JSX } from " astro/jsx-runtime" ;
7+ const { lang } = Astro .props ;
78
89// This is workaround for wrongly typed Analytics component from @vercel/analytics/astro
910const Analytics = AnalyticsComponent as unknown as (
@@ -13,3 +14,5 @@ const Analytics = AnalyticsComponent as unknown as (
1314
1415<Default {... Astro .props }><slot /></Default >
1516<Analytics />
17+ <!-- Algolia docsearch language facet -->
18+ <meta name =" docsearch:language" content ={ lang } />
You can’t perform that action at this time.
0 commit comments