Skip to content

Commit 0a0c83d

Browse files
peterbeaisgbnokmchammer01skedwards88actions-user
authored
refactor early access breadcrumbs (#26558)
* refactor early access breadcrumbs * Update permissions metadata to include users and teams with explicit access * Inform users of permission requirement for dependabot alerts * Apply suggestions from code review * version previews (github#26571) * update search indexes * New translation batch for pt (github#26591) * Add crowdin translations * Run script/i18n/homogenize-frontmatter.js * Run script/i18n/fix-translation-errors.js * Run script/i18n/lint-translation-files.js --check rendering * run script/i18n/reset-files-with-broken-liquid-tags.js --language=pt * run script/i18n/reset-known-broken-translation-files.js * Update subcategories for Codespaces (github#25812) * Version actions for GHES, use reusables (github#26004) Co-authored-by: Kevin Heis <[email protected]> Co-authored-by: Sarah Edwards <[email protected]> * New translation batch for ja (github#26599) * Add crowdin translations * Run script/i18n/homogenize-frontmatter.js * Run script/i18n/lint-translation-files.js --check rendering * run script/i18n/reset-files-with-broken-liquid-tags.js --language=ja * run script/i18n/reset-known-broken-translation-files.js * Check in ja CSV report Co-authored-by: Grace Park <[email protected]> * New translation batch for cn (github#26598) * Add crowdin translations * Run script/i18n/homogenize-frontmatter.js * Run script/i18n/lint-translation-files.js --check rendering * run script/i18n/reset-files-with-broken-liquid-tags.js --language=cn * run script/i18n/reset-known-broken-translation-files.js * Check in cn CSV report Co-authored-by: Grace Park <[email protected]> * New translation batch for es (github#26597) * Add crowdin translations * Run script/i18n/homogenize-frontmatter.js * Run script/i18n/fix-translation-errors.js * Run script/i18n/lint-translation-files.js --check rendering * run script/i18n/reset-files-with-broken-liquid-tags.js --language=es * run script/i18n/reset-known-broken-translation-files.js * Check in es CSV report Co-authored-by: Grace Park <[email protected]> * update search indexes * Rename xxtest-devcontainer.json to devcontainer.json * Delete .devcontainer/java-environment directory * Delete .devcontainer/ruby-environment directory * Update development.md * Update CONTRIBUTING.md * Add link to troubleshooting (github#26514) * update search indexes * fix old tests Co-authored-by: Anthony Swierkosz <[email protected]> Co-authored-by: mc <[email protected]> Co-authored-by: Sarah Edwards <[email protected]> Co-authored-by: GitHub Actions <[email protected]> Co-authored-by: docubot <[email protected]> Co-authored-by: Brian McManus <[email protected]> Co-authored-by: Lucas Costi <[email protected]> Co-authored-by: Kevin Heis <[email protected]> Co-authored-by: Grace Park <[email protected]> Co-authored-by: hubwriter <[email protected]>
1 parent 60ea6cd commit 0a0c83d

File tree

4 files changed

+30
-69
lines changed

4 files changed

+30
-69
lines changed

middleware/contextualizers/breadcrumbs.js

+29-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import liquid from '../../lib/render-content/liquid.js'
22

33
export default async function breadcrumbs(req, res, next) {
44
if (!req.context.page) return next()
5-
if (req.context.page.hidden) return next()
5+
const isEarlyAccess = req.context.page.relativePath.startsWith('early-access')
6+
if (req.context.page.hidden && !isEarlyAccess) return next()
67

78
req.context.breadcrumbs = []
89

@@ -11,16 +12,40 @@ export default async function breadcrumbs(req, res, next) {
1112
return next()
1213
}
1314

14-
req.context.breadcrumbs = await getBreadcrumbs(req)
15+
req.context.breadcrumbs = await getBreadcrumbs(req, isEarlyAccess)
1516

1617
return next()
1718
}
1819

19-
async function getBreadcrumbs(req) {
20+
async function getBreadcrumbs(req, isEarlyAccess = false) {
2021
const crumbs = []
2122
const { currentPath, currentVersion } = req.context
2223
const split = currentPath.split('/')
23-
while (split.length > 2 && split[split.length - 1] !== currentVersion) {
24+
let cutoff = 2
25+
if (isEarlyAccess) {
26+
// When in Early access docs consider the "root" be much higher.
27+
// E.g. /en/early-access/github/migrating/understanding/about
28+
// we only want it start at /migrating/understanding/about
29+
// Essentially, we're skipping "/early-access" and its first
30+
// top-level like "/github"
31+
cutoff++
32+
33+
// The only exception to this rule is for the
34+
// /{version}/early-access/insights/... URLs because they're a
35+
// bit different.
36+
// If there are more known exceptions, extend this conditional.
37+
if (!split.includes('insights')) {
38+
cutoff++
39+
}
40+
41+
// If the URL is early access AND has a version in it, go even further
42+
// E.g. /en/[email protected]/early-access/admin/hosting/mysql
43+
// should start at /hosting/mysql.
44+
if (currentVersion !== 'free-pro-team@latest') {
45+
cutoff++
46+
}
47+
}
48+
while (split.length > cutoff && split[split.length - 1] !== currentVersion) {
2449
const href = split.join('/')
2550
const page = req.context.pages[href]
2651
if (page) {

middleware/contextualizers/early-access-breadcrumbs.js

-56
This file was deleted.

middleware/index.js

-6
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import layout from './contextualizers/layout.js'
5252
import currentProductTree from './contextualizers/current-product-tree.js'
5353
import genericToc from './contextualizers/generic-toc.js'
5454
import breadcrumbs from './contextualizers/breadcrumbs.js'
55-
import earlyAccessBreadcrumbs from './contextualizers/early-access-breadcrumbs.js'
5655
import features from './contextualizers/features.js'
5756
import productExamples from './contextualizers/product-examples.js'
5857
import featuredLinks from './featured-links.js'
@@ -297,11 +296,6 @@ export default function (app) {
297296
app.use(instrument(currentProductTree, './contextualizers/current-product-tree'))
298297
app.use(asyncMiddleware(instrument(genericToc, './contextualizers/generic-toc')))
299298
app.use(asyncMiddleware(instrument(breadcrumbs, './contextualizers/breadcrumbs')))
300-
app.use(
301-
asyncMiddleware(
302-
instrument(earlyAccessBreadcrumbs, './contextualizers/early-access-breadcrumbs')
303-
)
304-
)
305299
app.use(asyncMiddleware(instrument(features, './contextualizers/features')))
306300
app.use(asyncMiddleware(instrument(productExamples, './contextualizers/product-examples')))
307301

tests/rendering/breadcrumbs.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,8 @@ describe('breadcrumbs', () => {
104104
const $breadcrumbTitles = $('[data-testid=breadcrumbs] [data-testid=breadcrumb-title]')
105105
const $breadcrumbLinks = $('[data-testid=breadcrumbs] a')
106106

107-
expect($breadcrumbTitles).toHaveLength(4)
107+
expect($breadcrumbTitles).toHaveLength(0)
108108
expect($breadcrumbLinks).toHaveLength(4)
109-
expect($breadcrumbTitles[0].children[0].data).toBe('Early Access documentation')
110-
expect($breadcrumbTitles[1].children[0].data).toBe('GitHub')
111109
expect($breadcrumbLinks[0].attribs.title).toBe(
112110
'Enforcing best practices with GitHub Policies'
113111
)

0 commit comments

Comments
 (0)