jpmorganchase / mosaic

https://mosaic-mosaic-dev-team.vercel.app
https://mosaic-mosaic-dev-team.vercel.app
Apache License 2.0
23 stars 20 forks source link

Enable page heading searchable via `SearchIndexPlugin` #660

Open origami-z opened 2 months ago

origami-z commented 2 months ago

Currently the plugin produces a search index with all content on a page as string for a route.

https://github.com/jpmorganchase/mosaic/blob/73799275cb0e57fdc4e161a2a7676f6427e78724/packages/store/src/types/searchIndex.ts#L1-L5

This doesn't allow the use case to search for specific page section heading and navigate to it.

Potential solution - it may mean a similar data like below

type SearchDataPage = {
  title: string;
  sections: {
    heading?: string;
    id?: string;
    content: string[];
  }[];
  route: string;
};

This likely means 2 different parts of change, first when indexing content, it will need to differentiate heading (e.g. AST type: "element" andtagName: "h1") vs other content

https://github.com/jpmorganchase/mosaic/blob/73799275cb0e57fdc4e161a2a7676f6427e78724/packages/plugins/src/SearchIndexPlugin.ts#L114-L127

I'm not sure how to deal with getting correct id, given computing id from heading is not enough given potential collision. This could mean a different lifecycle method is needed for this to work?