import { standardSDKSlug , extrapolate , sentryAlgoliaIndexSettings , htmlToAlgoliaRecord , } from "@sentry-internal/global-search" ; import fs from "fs" ; import { resolve , join } from "path" ; const pageQuery = `{
    pages: allSitePage {
      nodes {
        id
        path
        context {
          draft
          title
          noindex
          keywords
          platform {
            name
          }
          guide {
            name
          }
        }
      }
    }
  }` ; const pub = resolve ( process . cwd ( ) , "public" ) ; const flatten = async ( pages ) => { const records = ( await Promise . all ( pages . filter ( ( { context } ) => context && ! context . draft && ! context . noindex && context . title ) . map ( async ( page ) => { const { context , path } = page ; const htmlFile = join ( pub , path , "index.html" ) ; const html = ( await fs . promises . readFile ( htmlFile ) ) . toString ( ) ; let platforms = [ ] ; if ( context . platform ) { const { slug } = standardSDKSlug ( context . platform . name ) ; let fullSlug = slug ; if ( context . guide ) { const { slug } = standardSDKSlug ( context . guide . name ) ; fullSlug += `.${ slug }` ; } platforms = extrapolate ( fullSlug , "." ) ; } const newRecords = htmlToAlgoliaRecord ( html , { title : context . title , url : path , platforms , pathSegments : extrapolate ( path , "/" ) . map ( x => `/${ x }/` ) , keywords : context . keywords || [ ] , legacy : context . legacy || false , } , "#main" ) ; return newRecords ; } ) ) ) . reduce ( ( a , x ) => { return [ ... a , ... x ] ; } , [ ] ) ; return records ; } ; const indexPrefix = process . env . GATSBY_ALGOLIA_INDEX_PREFIX ; if ( ! indexPrefix ) { throw new Error ( "`GATSBY_ALGOLIA_INDEX_PREFIX` must be configured!" ) ; } export default [ { query : pageQuery , transformer : ( { data } ) => flatten ( data . pages . nodes ) , indexName : `${ indexPrefix }docs` , settings : { ... sentryAlgoliaIndexSettings , } , } , ] ;