MCPcopy Create free account
hub / github.com/fontsource/fontsource / getBreadcrumbs

Function getBreadcrumbs

website/app/utils/docs/navigation.ts:81–115  ·  view source on GitHub ↗
(
	tree: PageTree.Root,
	url: string,
)

Source from the content-addressed store, hash-verified

79};
80
81export const getBreadcrumbs = (
82 tree: PageTree.Root,
83 url: string,
84): Breadcrumb[] => {
85 const path: Breadcrumb[] = [];
86
87 const visit = (nodes: PageTree.Node[], parents: Breadcrumb[]): boolean => {
88 for (const node of nodes) {
89 if (isPage(node) && node.url === url) {
90 path.push(...parents, { name: nodeName(node), url: node.url });
91 return true;
92 }
93
94 if (isFolder(node)) {
95 const folderPath = [
96 ...parents,
97 { name: nodeName(node), url: firstInternalPageUrl(node) },
98 ];
99 if (node.index?.url === url) {
100 path.push(...folderPath, {
101 name: nodeName(node.index),
102 url: node.index.url,
103 });
104 return true;
105 }
106 if (visit(node.children, folderPath)) return true;
107 }
108 }
109
110 return false;
111 };
112
113 visit(tree.children, []);
114 return path;
115};

Callers 1

loaderFunction · 0.90

Calls 1

visitFunction · 0.85

Tested by

no test coverage detected