content icon indicating copy to clipboard operation
content copied to clipboard

feat(search): add separators option to queryCollectionSearchSections

Open onmax opened this issue 1 month ago • 4 comments

Summary

  • Sections split only on headings (h1-h6)
  • Now users can customize which tags trigger new sections via separators option

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 avatar Dec 09 '25 13:12 onmax

@onmax is attempting to deploy a commit to the Nuxt Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Dec 09 '25 13:12 vercel[bot]

npm i https://pkg.pr.new/@nuxt/content@3636

commit: af97701

pkg-pr-new[bot] avatar Dec 09 '25 13:12 pkg-pr-new[bot]

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

farnabaz avatar Dec 11 '25 12:12 farnabaz

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?

onmax avatar Dec 11 '25 14:12 onmax

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.

farnabaz avatar Dec 12 '25 09:12 farnabaz

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

onmax avatar Dec 12 '25 12:12 onmax