Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable page heading searchable via SearchIndexPlugin #660

Open
origami-z opened this issue Sep 13, 2024 · 0 comments
Open

Enable page heading searchable via SearchIndexPlugin #660

origami-z opened this issue Sep 13, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@origami-z
Copy link
Contributor

origami-z commented Sep 13, 2024

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

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

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?

@origami-z origami-z added the enhancement New feature or request label Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant