#queryCollectionNavigation and Nuxt UI's ContentSearch

4 messages · Page 1 of 1 (latest)

solar zodiac
#

I am using this scriptts const { data: navigation } = await useAsyncData('navigation', () => queryCollectionNavigation('docs'))
To generate docs navigation data to LazyUContentSearch Nuxt UI component.

After opening the search menu and not typing anything yet, there are already duplicates of docs pages.
One link is /docs/features/duties and the second one is /docs/features/duties#duties as they use the first anchor link for some reason.

How can I get rid of these duplicates? I just want to display the links without anchors for a first view.

upper gyroBOT
#

Hi @solar zodiac. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The knowledge sources don’t explicitly describe how queryCollectionNavigation('docs') is transformed into the items used by UContentSearch, nor how anchor links like /docs/features/duties#duties are introduced, so I can’t give a definitive, code-level fix. But there are two documented levers that can help reduce or avoid anchor-based duplicates:

  1. Control heading anchor generation (global)
    Nuxt Content can be configured to not generate anchor links for headings at all. That would prevent #duties-style anchors from being created in the first place, so ContentSearch would only see plain page paths like /docs/features/duties. You can disable anchor links in nuxt.config.ts:

    export default defineNuxtConfig({
      content: {
        renderer: {
          anchorLinks: false
        }
      }
    })
    

    [Headers & text]

    This is a broad change (affects all rendered content and TOC anchors), but it guarantees that #heading URLs won’t appear in search/navigation.

  2. Post-process navigation data before passing to ContentSearch (conceptual)
    The docs show that navigation data from queryCollectionNavigation('content') is passed directly into UContentSearch via the navigation prop. [ContentSearch] Since the exact shape of that data and how anchors are added is not detailed in the sources, they don’t show a built‑in option to “hide anchors on first view”.

    However, you can conceptually insert a transformation step before passing navigation to LazyUContentSearch that:

    • Strips any #... fragment from path/to fields, or
    • Filters out items whose path includes #.
#

The docs don’t provide a concrete example of such a transform for ContentSearch, so I can’t show a fully accurate snippet, only note that this is where you’d do it.

Because the sources don’t document a dedicated ContentSearch option to “ignore anchors” or “dedupe by base path”, the only documented, reliable way to avoid #heading duplicates is disabling anchor generation via content.renderer.anchorLinks: false as shown above.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: