content.ts 519 B

123456789101112131415161718
  1. import type { ContentNavigationItem } from '@nuxt/content'
  2. export const navigationInjectionKey: InjectionKey<Ref<ContentNavigationItem[] | undefined>> = Symbol('navigation')
  3. export function navPageFromPath(path: string, tree: ContentNavigationItem[]): ContentNavigationItem | undefined {
  4. for (const file of tree) {
  5. if (file.path === path) {
  6. return file
  7. }
  8. if (file.children) {
  9. const result = navPageFromPath(path, file.children)
  10. if (result) {
  11. return result
  12. }
  13. }
  14. }
  15. }