feat(search): add separators option to queryCollectionSearchSections
Summary
- Sections split only on headings (h1-h6)
- Now users can customize which tags trigger new sections via
separatorsoption
Changes
- Add
separators?: string[]option with default['h1', 'h2', 'h3', 'h4', 'h5', 'h6'](backward compatibility) - Non-heading separators (e.g.
hr) get level 1 and don't affect heading hierarchy
Usage
queryCollectionSearchSections('docs', { separators: ['h2', 'hr'] })
queryCollectionSearchSections('docs', { separators: [] }) // no splitting
@onmax is attempting to deploy a commit to the Nuxt Team on Vercel.
A member of the Team first needs to authorize it.
I like the idea about separator but I'm not sure how useful it could be because by default other elements do not have id attribute. The only way to achieve it for hr is
Paragraph
::hr{#my-id}
::
Paragraph
Good point. In my personal needs, the main use case is customising which heading levels trigger a new section (e.g. 'h2' or 'h3' rather than all headings).
Adding support for any component, like hr, is just an added bonus, providing flexibility; users who want it can add IDs via MDC syntax.
Should I add a note about this in the documentation, or should we only allow headings in the separator option?
I think headers should be enough. Let’s face it: if you want to create a section, you need a title. What’s the purpose of a section without a title and proper link? In my view, if it doesn’t have a title, it’s most likely a continuation of the previous section.
So I'll go with headers only option.
updated the pr. changed api from separators: string[] to minHeading/maxHeading.
the array approach allowed weird combos like ['h2', 'h4'] skipping h3. range-based is cleaner and self-documenting - you know exactly what headings will split sections