-
Notifications
You must be signed in to change notification settings - Fork 18
Description
Currently the plugin produces a search index with all content on a page as string for a route.
mosaic/packages/store/src/types/searchIndex.ts
Lines 1 to 5 in 7379927
| type SearchDataPage = { | |
| title: string; | |
| content: string[]; | |
| route: string; | |
| }; |
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
mosaic/packages/plugins/src/SearchIndexPlugin.ts
Lines 114 to 127 in 7379927
| visit( | |
| tree, | |
| (node: Node) => node.type === 'text' || node.type === 'code', | |
| (node: LeafNode) => { | |
| const segments = [...segmenter.segment(node.value)].map(segment => segment.segment); | |
| segments.forEach(segment => { | |
| if (maxLineLength) { | |
| sentences.push(segment.slice(0, maxLineLength)); | |
| } else { | |
| sentences.push(segment); | |
| } | |
| }); | |
| } | |
| ); |
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?