Skip to content

Commit 603ad36

Browse files
authored
Merge pull request #16783 from github/early-access-tweaks
Early Access followup work
2 parents 712dd75 + dd3fabb commit 603ad36

8 files changed

Lines changed: 102 additions & 6 deletions

File tree

data/ui.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ header:
1717
still in translation. For the most up-to-date and accurate information,
1818
please visit our
1919
<a id="to-english-doc" href="/en">English documentation</a>.
20-
early_access: 👋 This page contains content about an early access feature. Please do not share this URL publicly.
20+
early_access: 📣 Please <b>do not share</b> this URL publicly. This page contains content about an early access feature.
2121
search:
2222
need_help: Need help?
2323
placeholder: Search topics, products...

includes/breadcrumbs.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<nav class="breadcrumbs f5" aria-label="Breadcrumb">
22
{% for breadcrumb in breadcrumbs %}
3-
{% if page.hidden %}
4-
<span class="d-inline-block">{{breadcrumb[1].title}}</span>
3+
{% if breadcrumb[1].href == '' %}
4+
<span>{{breadcrumb[1].title}}</span>
55
{% else %}
66
<a title="{{ breadcrumb[0]}}: {{breadcrumb[1].title}}" href="/{{currentLanguage}}{{breadcrumb[1].href}}" class="d-inline-block {% if breadcrumb[1].href == currentPathWithoutLanguage %}text-gray-light{% endif %}">
77
{{breadcrumb[1].title}}</a>

includes/header-notification.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
{% endif %}
5050

5151
{% if early_access_notification_type %}
52-
<div class="header-notifications text-center f5 bg-blue-1 text-gray-dark py-4 px-6 early_access">
52+
<div class="header-notifications text-center f5 bg-red-1 text-gray-dark py-4 px-6 early_access">
5353
{{ early_access_notification }}
5454
</div>
5555
{% endif %}

middleware/breadcrumbs.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ const path = require('path')
22
const { getPathWithoutLanguage } = require('../lib/path-utils')
33

44
module.exports = async (req, res, next) => {
5+
if (!req.context.page) return next()
6+
if (req.context.page.hidden) return next()
7+
58
req.context.breadcrumbs = {}
69

7-
if (!req.context.page) return next()
10+
// Return an empty object on the landing page
811
if (req.context.page.relativePath === 'index.md') return next()
912

1013
const rawPath = getPathWithoutLanguage(req.path)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const path = require('path')
2+
const { getPathWithoutLanguage } = require('../lib/path-utils')
3+
4+
// Early Access content doesn't conform to the same structure as other products, so we
5+
// can't derive breadcrumbs from the siteTree in the same way. Hence, this separate middleware.
6+
module.exports = async (req, res, next) => {
7+
if (!req.context.page) return next()
8+
if (!req.context.page.hidden) return next()
9+
10+
req.context.breadcrumbs = {}
11+
12+
const earlyAccessProduct = req.context.siteTree[req.language][req.context.currentVersion].products[req.context.currentProduct]
13+
14+
req.context.breadcrumbs.earlyAccessProduct = {
15+
href: '', // no link for the EA product breadcrumb
16+
title: earlyAccessProduct.title
17+
}
18+
19+
const rawPath = getPathWithoutLanguage(req.path)
20+
const pathParts = rawPath.split('/')
21+
22+
// drop first '/'
23+
pathParts.shift()
24+
25+
// drop the version and early-accesss segments so pathParts now starts with /product
26+
pathParts.shift()
27+
pathParts.shift()
28+
29+
// Early Access products do not require an index.md, so look for a matching public product
30+
const product = req.context.siteTree[req.language][req.context.currentVersion].products[pathParts[0]]
31+
32+
if (!product) return next()
33+
34+
req.context.breadcrumbs.product = {
35+
href: '', // no link for the EA product breadcrumbs
36+
title: product.title
37+
}
38+
39+
if (!pathParts[1]) return next()
40+
41+
// get Early Access category path
42+
// e.g., `enforcing-best-practices-with-github-policies` in /free-pro-team@latest/early-access/github/enforcing-best-practices-with-github-policies
43+
const categoryPath = path.posix.join('/', req.context.currentVersion, 'early-access', pathParts[0], pathParts[1])
44+
const category = req.context.pages[path.posix.join('/en', categoryPath)]
45+
46+
if (!category) return next()
47+
48+
req.context.breadcrumbs.category = {
49+
href: categoryPath, // do include a link for EA category breadcrumbs
50+
title: category.shortTitle || category.title
51+
}
52+
53+
if (!pathParts[2]) return next()
54+
55+
// for Early Access purposes, we don't need to differentiate between map topics and articles breadcrumbs
56+
const mapTopicOrArticlePath = path.posix.join(categoryPath, pathParts[2])
57+
const mapTopicOrArticle = req.context.pages[path.posix.join('/en', mapTopicOrArticlePath)]
58+
59+
if (!mapTopicOrArticle) return next()
60+
61+
const mapTopicOrArticleTitle = await mapTopicOrArticle.renderProp('shortTitle', req.context, { textOnly: true, encodeEntities: true })
62+
63+
req.context.breadcrumbs.article = {
64+
href: mapTopicOrArticlePath, // do include a link for EA map topic/article breadcrumbs
65+
title: mapTopicOrArticleTitle
66+
}
67+
68+
return next()
69+
}

middleware/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ module.exports = function (app) {
7373
app.use(require('./contextualizers/rest'))
7474
app.use(require('./contextualizers/webhooks'))
7575
app.use(require('./breadcrumbs'))
76+
app.use(require('./early-access-breadcrumbs'))
7677
app.use(require('./dev-toc'))
7778
app.use(require('./featured-links'))
7879

stylesheets/article.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
/* Breadcrumbs
8888
------------------------------------------------------------------------------*/
8989

90-
.breadcrumbs a:not(:last-child)::after{
90+
.breadcrumbs a:not(:last-child)::after, .breadcrumbs span:not(:last-child)::after {
9191
content: '/';
9292
color: $gray-400;
9393
padding-right: $spacer-1;

tests/rendering/breadcrumbs.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const { getDOM, getJSON } = require('../helpers/supertest')
22
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
33

4+
const describeInternalOnly = process.env.GITHUB_REPOSITORY === 'github/docs-internal' ? describe : describe.skip
5+
46
describe('breadcrumbs', () => {
57
jest.setTimeout(300 * 1000)
68

@@ -60,6 +62,27 @@ describe('breadcrumbs', () => {
6062
})
6163
})
6264

65+
describeInternalOnly('early access rendering', () => {
66+
test('top-level product pages have breadcrumbs', async () => {
67+
const $ = await getDOM('/early-access/github/articles/using-gist-playground')
68+
expect($('.breadcrumbs')).toHaveLength(1)
69+
})
70+
71+
test('early access article pages have breadcrumbs with product, category, and article', async () => {
72+
const $ = await getDOM('/early-access/github/enforcing-best-practices-with-github-policies/about-github-policies')
73+
const $breadcrumbSpans = $('.breadcrumbs span')
74+
const $breadcrumbLinks = $('.breadcrumbs a')
75+
76+
expect($breadcrumbSpans).toHaveLength(2)
77+
expect($breadcrumbLinks).toHaveLength(2)
78+
expect($breadcrumbSpans.eq(0).text()).toBe('Early Access documentation')
79+
expect($breadcrumbSpans.eq(1).text()).toBe('GitHub.com')
80+
expect($breadcrumbLinks.eq(0).attr('title')).toBe('category: Enforcing best practices with GitHub Policies')
81+
expect($breadcrumbLinks.eq(1).attr('title')).toBe('article: About GitHub Policies')
82+
expect($breadcrumbLinks.eq(1).hasClass('text-gray-light')).toBe(true)
83+
})
84+
})
85+
6386
describe('context.breadcrumbs object', () => {
6487
test('works on product index pages', async () => {
6588
const breadcrumbs = await getJSON('/en/github?json=breadcrumbs')

0 commit comments

Comments
 (0)