Skip to content

Commit d4692b2

Browse files
authored
put the full plan name in the page titles (#28450)
* put the full plan name in the page titles * fix tests
1 parent c5cdf96 commit d4692b2

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

middleware/render-page.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import patterns from '../lib/patterns.js'
44
import getMiniTocItems from '../lib/get-mini-toc-items.js'
55
import Page from '../lib/page.js'
66
import statsd from '../lib/statsd.js'
7+
import { allVersions } from '../lib/all-versions.js'
78
import { isConnectionDropped } from './halt-on-dropped-connection.js'
89
import { nextApp, nextHandleRequest } from './next.js'
910

@@ -92,7 +93,22 @@ export default async function renderPage(req, res, next) {
9293

9394
// add localized ` - GitHub Docs` suffix to <title> tag (except for the homepage)
9495
if (!patterns.homepagePath.test(path)) {
95-
page.fullTitle = page.fullTitle + ' - ' + context.site.data.ui.header.github_docs
96+
if (
97+
req.context.currentVersion === 'free-pro-team@latest' ||
98+
!allVersions[req.context.currentVersion]
99+
) {
100+
page.fullTitle += ' - ' + context.site.data.ui.header.github_docs
101+
} else {
102+
const { versionTitle } = allVersions[req.context.currentVersion]
103+
page.fullTitle += ' - '
104+
// Some plans don't have the word "GitHub" in them.
105+
// E.g. "Enterprise Server 3.5"
106+
// In those cases manually prefix the word "GitHub" before it.
107+
if (!versionTitle.includes('GitHub')) {
108+
page.fullTitle += 'GitHub '
109+
}
110+
page.fullTitle += versionTitle + ' Docs'
111+
}
96112
}
97113

98114
// Is the request for JSON debugging info?

tests/rendering/page-titles.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ describe('page titles', () => {
2020
const $ = await getDOM(
2121
`/en/enterprise/${enterpriseServerReleases.latest}/user/github/authenticating-to-github/authorizing-oauth-apps`
2222
)
23-
expect($('title').text()).toBe('Authorizing OAuth Apps - GitHub Docs')
23+
expect($('title').text()).toBe(
24+
`Authorizing OAuth Apps - GitHub Enterprise Server ${enterpriseServerReleases.latest} Docs`
25+
)
2426
})
2527

2628
test('dotcom English map topic page', async () => {
@@ -35,13 +37,19 @@ describe('page titles', () => {
3537

3638
test('dynamically parses liquid in page titles (even on subsequent requests)', async () => {
3739
let $ = await getDOM(`/en/enterprise/${enterpriseServerReleases.latest}`)
38-
expect($('title').text()).toBe('GitHub Enterprise Server Help Documentation - GitHub Docs')
40+
expect($('title').text()).toBe(
41+
`GitHub Enterprise Server Help Documentation - GitHub Enterprise Server ${enterpriseServerReleases.latest} Docs`
42+
)
3943

4044
$ = await getDOM(`/en/enterprise/${enterpriseServerReleases.oldestSupported}`)
41-
expect($('title').text()).toBe('GitHub Enterprise Server Help Documentation - GitHub Docs')
45+
expect($('title').text()).toBe(
46+
`GitHub Enterprise Server Help Documentation - GitHub Enterprise Server ${enterpriseServerReleases.oldestSupported} Docs`
47+
)
4248

4349
$ = await getDOM(`/en/enterprise/${enterpriseServerReleases.latest}`)
44-
expect($('title').text()).toBe('GitHub Enterprise Server Help Documentation - GitHub Docs')
50+
expect($('title').text()).toBe(
51+
`GitHub Enterprise Server Help Documentation - GitHub Enterprise Server ${enterpriseServerReleases.latest} Docs`
52+
)
4553
})
4654

4755
// TODO enable this once translated content has synced with the versioning changes

0 commit comments

Comments
 (0)