UNPKG

@barnabask/astro-minisearch

Version:

Utilities to add a static full text index to an Astro project

30 lines (29 loc) 1.6 kB
import MiniSearch from "minisearch"; import type { EndpointOutput } from "astro"; import { SearchDocument, SearchIndexOptions } from "./types.js"; /** * Represents all possible acceptable inputs for the search documents functions. * This includes an array or nested array of search documents, * as well as a promise or array of promises that resolve to an array of search documents. */ export type SearchDocumentsInput = SearchDocument[] | SearchDocument[][] | Promise<SearchDocument[]> | Promise<SearchDocument[]>[]; /** * Unravels all possible search inputs and resolve them to a simple array of search documents. * Also removes documents with duplicate or missing URLs and outputs a warning. */ export declare function getDocuments(input: SearchDocumentsInput): Promise<SearchDocument[]>; /** * Generate the MiniSearch object from a list of prepared search documents. * * @param documentsInput search documents or promises from other functions * @param options search index options * @returns a populated MiniSearch object */ export declare function generateIndex(documentsInput: SearchDocumentsInput, options?: SearchIndexOptions): Promise<MiniSearch>; /** Load a MiniSearch object from a string or JSON object. */ export declare function loadIndex(json: string | any, options?: SearchIndexOptions): MiniSearch<SearchDocument>; /** * Helper function to both generate an index and output a static endpoint. * @see [Astro docs on static endpoints]() */ export declare function getSearchIndex(documentsInput: SearchDocumentsInput, options?: SearchIndexOptions): Promise<EndpointOutput>;