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

Function getBreadcrumbs

middleware/contextualizers/breadcrumbs.js:20–47  ·  view source on GitHub ↗
(req, isEarlyAccess)

Source from the content-addressed store, hash-verified

18const earlyAccessExceptions = ['insights', 'enterprise-importer']
19
20function getBreadcrumbs(req, isEarlyAccess) {
21 let cutoff = 0
22 // When in Early access docs consider the "root" be much higher.
23 // E.g. /en/early-access/github/migrating/understanding/about
24 // we only want it start at /migrating/understanding/about
25 // Essentially, we're skipping "/early-access" and its first
26 // top-level like "/github"
27 if (isEarlyAccess) {
28 const split = req.context.currentPath.split('/')
29 // There are a few exceptions to this rule for the
30 // /{version}/early-access/<product-name>/... URLs because they're a
31 // bit different.
32 // If there are more known exceptions, add them to the array above.
33 if (earlyAccessExceptions.some((product) => split.includes(product))) {
34 cutoff = 1
35 } else {
36 cutoff = 2
37 }
38 }
39
40 const breadcrumbs = traverseTreeTitles(
41 req.context.currentPath,
42 req.context.currentProductTreeTitles
43 )
44 ;[...Array(cutoff)].forEach(() => breadcrumbs.shift())
45
46 return breadcrumbs
47}
48
49// Return an array as if you'd traverse down a tree. Imagine a tree like
50//

Callers 1

breadcrumbsFunction · 0.85

Calls 1

traverseTreeTitlesFunction · 0.85

Tested by

no test coverage detected