Skip to content

Move findPageBreadcrumb utility from @nuxt/ui-pro to @nuxt/content and add findPageChildren / findPageSiblings #3313

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

Open
maximepvrt opened this issue Apr 16, 2025 · 4 comments
Labels
enhancement New feature or request

Comments

@maximepvrt
Copy link
Contributor

I’d like to propose moving the [findPageBreadcrumb](https://ui.nuxt.com/getting-started/content#findpagebreadcrumb) function, currently implemented in @nuxt/ui-pro to the @nuxt/content module. Since it relies solely on content data, it could be useful beyond Nuxt UI and benefit a broader range of projects using Nuxt Content.

Following a conversation with @atinux in DMs, he mentioned this move could indeed make sense and be worth considering within the scope of @nuxt/content.

In addition, I’d like to propose the creation of two complementary utilities:

  • findPageChildren
  • findPageSiblings

🧠 Proposal

1. Generic utilities

All three functions (findPageBreadcrumb, findPageChildren, and findPageSiblings) could:

  • Accept a route string (e.g. /foo/bar) rather than a full page object.
  • Support an optional strategy parameter to control how index.md files are interpreted.
findPageBreadcrumb(navigation?: ContentNavigationItem[], route?: string, options?: {current: boolean, strategy?: 'index-as-root' | 'index-as-child'})

findPageChildren(navigation?: ContentNavigationItem[], route?: string, options?: {strategy?: 'index-as-root' | 'index-as-child'})

findPageSiblings(navigation?: ContentNavigationItem[], route?: string, options?: {strategy?: 'index-as-root' | 'index-as-child'})

2. Strategy behavior

The strategy option would define whether an index.md file should be:

  • considered a child page within its directory (index-as-child, current behavior)
  • considered the root page of its directory (index-as-root)

It would also be convenient to define this behavior globally through the module configuration, e.g.:

export default defineNuxtConfig({
  content: {
    navigation: {
      strategy: 'index-as-root' // or 'index-as-child'
    }
  }
})

📎 Context

Related PRs in @nuxt/ui-pro:

@maximepvrt maximepvrt added the enhancement New feature or request label Apr 16, 2025
@maximepvrt
Copy link
Contributor Author

@farnabaz @atinux @benjamincanac @HugoRCD I’d be happy to help with a PR if this proposal makes sense.

Copy link
Member

I like it. These utilities can be used by all users.

However I'm not fan of introducing module option for utilities. For me the default behavior should be index-as-root and utilities can accept option indexAsChild option to change the behavior.

Looking forward to your PR :)

@maximepvrt
Copy link
Contributor Author

Thanks for the quick reply!

I totally agree that having index-as-root as the default behavior makes a lot of sense.

That said, I just wanted to point out that the current implementation of findPageBreadcrumb in Nuxt UI is actually an index-as-child behavior. Which is what allows pages like https://ui.nuxt.com/getting-started to appear to appear in both the breadcrumb and the navigation menu as a child.

The idea behind introducing a strategy option was precisely to allow both behaviors to coexist cleanly:

  • index-as-root is what I personally use in my apps.
  • index-as-child is something @benjamincanac seems to want to keep using on Nuxt UI.

So this proposal was mainly meant to bring flexibility and consistency across use cases without enforcing one specific interpretation globally.

Anyway, I’ll let you discuss it internally before diving into the actual implementation 😊
Let me know what direction you'd prefer!

@maximepvrt
Copy link
Contributor Author

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

2 participants