File-based content management system for Nuxt.js applications with powerful querying and Vue component rendering in Markdown
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Helper functions for working with navigation trees, extracting breadcrumbs, children, siblings, and headlines from hierarchical content structures. These utilities are essential for building navigation components and understanding content relationships.
Generates a breadcrumb trail from the navigation tree to a specific page path.
/**
* Generates a breadcrumb trail from navigation tree to a specific path
* @param navigation - The navigation tree array
* @param path - The target path to find breadcrumbs for
* @param options - Configuration options for breadcrumb generation
* @returns Array of navigation items forming the breadcrumb trail
*/
function findPageBreadcrumb(
navigation?: ContentNavigationItem[],
path?: string | undefined | null,
options?: FindPageBreadcrumbOptions
): ContentNavigationItem[];
interface FindPageBreadcrumbOptions {
/** Include the current page in the breadcrumb trail */
current?: boolean;
/** Treat index pages as children rather than parents */
indexAsChild?: boolean;
}Usage Examples:
import { findPageBreadcrumb } from '@nuxt/content/utils';
// Generate breadcrumb trail
const breadcrumbs = findPageBreadcrumb(navigation, '/docs/guide/installation');
// Result: [{ title: 'Docs', path: '/docs' }, { title: 'Guide', path: '/docs/guide' }]
// Include current page in breadcrumbs
const fullBreadcrumbs = findPageBreadcrumb(
navigation,
'/docs/guide/installation',
{ current: true }
);
// Result: [{ title: 'Docs', path: '/docs' }, { title: 'Guide', path: '/docs/guide' }, { title: 'Installation', path: '/docs/guide/installation' }]Finds all direct children of a specific page in the navigation tree.
/**
* Finds all direct children of a specific page in navigation tree
* @param navigation - The navigation tree array
* @param path - The parent path to find children for
* @param options - Configuration options
* @returns Array of direct child navigation items
*/
function findPageChildren(
navigation?: ContentNavigationItem[],
path?: string | undefined | null,
options?: FindPageOptions
): ContentNavigationItem[];
interface FindPageOptions {
/** Treat index pages as children rather than parents */
indexAsChild?: boolean;
}Usage Examples:
import { findPageChildren } from '@nuxt/content/utils';
// Find all children of a section
const children = findPageChildren(navigation, '/docs/guide');
// Result: [{ title: 'Installation', path: '/docs/guide/installation' }, { title: 'Configuration', path: '/docs/guide/configuration' }]
// Handle index pages as children
const indexChildren = findPageChildren(
navigation,
'/docs/guide',
{ indexAsChild: true }
);Finds all sibling pages (pages at the same level) for a specific page path.
/**
* Finds all sibling pages at the same level as the specified path
* @param navigation - The navigation tree array
* @param path - The path to find siblings for
* @param options - Configuration options
* @returns Array of sibling navigation items (excludes the current page)
*/
function findPageSiblings(
navigation?: ContentNavigationItem[],
path?: string | undefined | null,
options?: FindPageOptions
): ContentNavigationItem[];Usage Examples:
import { findPageSiblings } from '@nuxt/content/utils';
// Find sibling pages
const siblings = findPageSiblings(navigation, '/docs/guide/installation');
// Result: [{ title: 'Configuration', path: '/docs/guide/configuration' }, { title: 'Usage', path: '/docs/guide/usage' }]
// Note: excludes '/docs/guide/installation' itselfExtracts the headline (parent section title) for a specific page path.
/**
* Extracts the headline/parent section title for a specific page
* @param navigation - The navigation tree array
* @param path - The path to find headline for
* @param options - Configuration options
* @returns The headline string or undefined if not found
*/
function findPageHeadline(
navigation?: ContentNavigationItem[],
path?: string | undefined | null,
options?: FindPageOptions
): string | undefined;Usage Examples:
import { findPageHeadline } from '@nuxt/content/utils';
// Get page headline
const headline = findPageHeadline(navigation, '/docs/guide/installation');
// Result: "Guide" (the parent section title)
// Handle index pages
const indexHeadline = findPageHeadline(
navigation,
'/docs/guide/index',
{ indexAsChild: true }
);interface ContentNavigationItem {
title: string;
path: string;
stem?: string;
children?: ContentNavigationItem[];
page?: false;
[key: string]: unknown;
}
interface FindPageBreadcrumbOptions {
current?: boolean;
indexAsChild?: boolean;
}
interface FindPageOptions {
indexAsChild?: boolean;
}Install with Tessl CLI
npx tessl i tessl/npm-nuxt--content