MCPcopy Create free account
hub / github.com/github/docs / traverseTreeTitles

Function traverseTreeTitles

middleware/contextualizers/breadcrumbs.js:65–82  ·  view source on GitHub ↗
(currentPath, tree)

Source from the content-addressed store, hash-verified

63// ]
64//
65function traverseTreeTitles(currentPath, tree) {
66 const { href, title, shortTitle } = tree
67 const crumbs = [
68 {
69 href,
70 title: shortTitle || title,
71 },
72 ]
73 const currentPathSplit = Array.isArray(currentPath) ? currentPath : currentPath.split('/')
74 for (const child of tree.childPages) {
75 if (isParentOrEqualArray(child.href.split('/'), currentPathSplit)) {
76 crumbs.push(...traverseTreeTitles(currentPathSplit, child))
77 // Only ever going down 1 of the children
78 break
79 }
80 }
81 return crumbs
82}
83
84// Return true if an array is part of another array or equal.
85// Like `/foo/bar` is part of `/foo/bar/buzz`.

Callers 1

getBreadcrumbsFunction · 0.85

Calls 1

isParentOrEqualArrayFunction · 0.85

Tested by

no test coverage detected