import { splitByCase, upperFirst } from 'scule' import type { NavItem, ParsedContent } from '@nuxt/content/dist/runtime/types' export function findPageHeadline(page: ParsedContent): string { return page._dir?.title ? page._dir.title : splitByCase(page._dir).map(p => upperFirst(p)).join(' ') } export function findPageBreadcrumb(menuItems: NavItem[], path: string): NavItem[] { if (!path) return [] const segments = path.split('/').filter(segment => segment !== '') // Split the path and remove empty segments segments.unshift('') // Add root const result: NavItem[] = [] let currentPath = '' let currentItems = menuItems for (const segment of segments) { currentPath += currentPath === '/' ? segment : `/${segment}` const matchingItem = currentItems.find(item => item._path === currentPath) if (matchingItem) { result.push(matchingItem) if (matchingItem.children) currentItems = matchingItem.children } else { // If no match found for the current segment, break the loop break } } return result }