The Node.js® Website
at main 932 B view raw
1import { Highlight } from '@orama/highlight'; 2import { OramaClient } from '@oramacloud/client'; 3 4import { 5 DEFAULT_ORAMA_QUERY_PARAMS, 6 ORAMA_CLOUD_ENDPOINT, 7 ORAMA_CLOUD_API_KEY, 8} from './next.constants.mjs'; 9 10// Provides a safe-wrapper that initialises the OramaClient 11// based on the presence of environmental variables 12const { search, getInitialFacets } = (() => { 13 if (ORAMA_CLOUD_ENDPOINT && ORAMA_CLOUD_API_KEY) { 14 const orama = new OramaClient({ 15 endpoint: ORAMA_CLOUD_ENDPOINT, 16 api_key: ORAMA_CLOUD_API_KEY, 17 }); 18 19 return { 20 search: orama.search.bind(orama), 21 getInitialFacets: async () => 22 orama.search({ term: '', ...DEFAULT_ORAMA_QUERY_PARAMS }).catch(), 23 }; 24 } 25 26 return { search: async () => null, getInitialFacets: async () => null }; 27})(); 28 29export { search, getInitialFacets }; 30 31export const highlighter = new Highlight({ 32 CSSClass: 'font-bold', 33 HTMLTag: 'span', 34});