import escapeHTML from "escape-html" ; import { SearchIndexDocument } from "../_" ; /**
 * Search document
 */ export interface SearchDocument extends SearchIndexDocument { parent ? : SearchIndexDocument ; } /**
 * Search document mapping
 */ export type SearchDocumentMap = Map < string , SearchDocument > ; param docs returns export function setupSearchDocumentMap ( docs ) { const documents = new Map < string , SearchDocument > ( ) ; const parents = new Set < SearchDocument > ( ) ; for ( const doc of docs ) { const [ path , hash ] = doc . location . split ( "#" ) ; const location = doc . location ; const title = doc . title ; const text = escapeHTML ( doc . text ) . replace ( /\s+(?=[,.:;!?])/g , "" ) . replace ( /\s+/g , " " ) ; if ( hash ) { const parent = documents . get ( path ) ! ; if ( ! parents . has ( parent ) ) { parent . title = doc . title ; parent . text = text ; parents . add ( parent ) ; } else { documents . set ( location , { location , title , text , parent } ) ; } } else { documents . set ( location , { location , title , text } ) ; } } return documents ; }