Skip to content

Commit 6a4851e

Browse files
author
Kathy Korevec
authored
Merge branch 'main' into code-example-extravganza
2 parents e28ba93 + 01dcee9 commit 6a4851e

7 files changed

Lines changed: 47 additions & 1188 deletions

contributing/development.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ As an alternative, you can simply use [GitHub Codespaces](https://github.com/fea
3232

3333
In a matter of minutes, you will be ready to edit, preview and test your changes directly from the comfort of your browser.
3434

35+
### Viewing a top-level table of contents
36+
37+
While running the local server, you can visit [localhost:4000/dev-toc](http://localhost:4000/dev-toc) to view a top-level TOC of all the content in the site. This page is not available on https://docs.github.com. It was created for internal GitHub writers' use.
38+
39+
At the `/dev-toc` path, you'll see a list of available versions. Click a version, and a list of products will appear. Note that the TOC content is versioned. If you are viewing `free-pro-team@latest` and you click the `Enterprise Admin` product, it will be empty, because there isn't any Admin content available on that version.
40+
3541
## Site structure
3642

3743
This site was originally a Ruby on Rails web application. Some time later it was converted into a static site powered by [Jekyll](https://jekyllrb.com/). A few years after that it was migrated to [Nanoc](https://nanoc.ws/), another Ruby static site generator.

lib/enterprise-server-releases.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const dates = require('../lib/enterprise-dates.json')
77
const supported = [
88
'2.22',
99
'2.21',
10-
'2.20',
11-
'2.19'
10+
'2.20'
1211
]
1312
const deprecated = [
13+
'2.19',
1414
'2.18',
1515
'2.17',
1616
'2.16',

lib/is-archived-version.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const patterns = require('../lib/patterns')
2+
const { deprecated } = require('../lib/enterprise-server-releases')
3+
4+
module.exports = function isArchivedVersion (req) {
5+
// if this is an assets path, use the referrer
6+
// if this is a docs path, use the req.path
7+
const pathToCheck = patterns.assetPaths.test(req.path)
8+
? req.get('referrer')
9+
: req.path
10+
11+
// ignore paths that don't have an enterprise version number
12+
if (!(patterns.getEnterpriseVersionNumber.test(pathToCheck) || patterns.getEnterpriseServerNumber.test(pathToCheck))) {
13+
return {}
14+
}
15+
16+
// extract enterprise version from path, e.g. 2.16
17+
const requestedVersion = pathToCheck.includes('enterprise-server@')
18+
? pathToCheck.match(patterns.getEnterpriseServerNumber)[1]
19+
: pathToCheck.match(patterns.getEnterpriseVersionNumber)[1]
20+
21+
// bail if the request version is not deprecated
22+
if (!deprecated.includes(requestedVersion)) {
23+
return {}
24+
}
25+
26+
return { isArchived: true, requestedVersion }
27+
}

lib/redirects/static/developer-docs-routes-for-supported-versions.json

Lines changed: 0 additions & 1141 deletions
Large diffs are not rendered by default.

middleware/archived-enterprise-versions-assets.js

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
const path = require('path')
2-
const versionSatisfiesRange = require('../lib/version-satisfies-range')
3-
const enterpriseServerReleases = require('../lib/enterprise-server-releases')
42
const patterns = require('../lib/patterns')
5-
const firstVersionDeprecatedOnNewSite = '2.13'
3+
const isArchivedVersion = require('../lib/is-archived-version')
64
const got = require('got')
75

86
// This module handles requests for the CSS and JS assets for
@@ -12,33 +10,14 @@ const got = require('got')
1210
// See also ./archived-enterprise-versions.js for non-CSS/JS paths
1311

1412
module.exports = async (req, res, next) => {
13+
const { isArchived, requestedVersion } = isArchivedVersion(req)
14+
if (!isArchived) return next()
15+
1516
// Only match asset paths
1617
if (!patterns.assetPaths.test(req.path)) return next()
1718

18-
// Get the referrer, which may contain an enterprise version
19-
const referrer = req.get('referrer')
20-
21-
// ignore paths that don't have an enterprise version number
22-
if (!patterns.getEnterpriseVersionNumber.test(referrer)) return next()
23-
24-
// extract enterprise version from path, e.g. 2.16
25-
const requestedVersion = referrer.match(patterns.getEnterpriseVersionNumber)[1]
26-
27-
// bail if the request version is not deprecated
28-
if (!enterpriseServerReleases.deprecated.includes(requestedVersion)) return next()
29-
30-
// get /dist/index.js and /dist/index.css paths from enterprisified paths
3119
const assetPath = req.path.replace(`/enterprise/${requestedVersion}`, '')
32-
33-
// paths are slightly different depending on the enterprise version
34-
let proxyPath
35-
if (versionSatisfiesRange(requestedVersion, `>=${firstVersionDeprecatedOnNewSite}`)) {
36-
// routing for >=2.13
37-
proxyPath = path.join('/', requestedVersion, assetPath)
38-
} else if (versionSatisfiesRange(requestedVersion, `<${firstVersionDeprecatedOnNewSite}`)) {
39-
// routing for <2.13
40-
proxyPath = path.join('/', requestedVersion, 'assets', assetPath)
41-
}
20+
const proxyPath = path.join('/', requestedVersion, assetPath)
4221

4322
try {
4423
const r = await got(`https://github.github.com/help-docs-archived-enterprise-versions${proxyPath}`)

middleware/archived-enterprise-versions.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
const path = require('path')
22
const slash = require('slash')
3-
const { latest, deprecated, firstVersionDeprecatedOnNewSite, lastVersionWithoutStubbedRedirectFiles } = require('../lib/enterprise-server-releases')
3+
const { latest, firstVersionDeprecatedOnNewSite, lastVersionWithoutStubbedRedirectFiles } = require('../lib/enterprise-server-releases')
44
const patterns = require('../lib/patterns')
55
const versionSatisfiesRange = require('../lib/version-satisfies-range')
6+
const isArchivedVersion = require('../lib/is-archived-version')
67
const got = require('got')
78
const findPage = require('../lib/find-page')
89

@@ -11,20 +12,12 @@ const findPage = require('../lib/find-page')
1112
// https://github.com/github/help-docs-archived-enterprise-versions
1213

1314
module.exports = async (req, res, next) => {
15+
const { isArchived, requestedVersion } = isArchivedVersion(req)
16+
if (!isArchived) return next()
17+
1418
// Skip asset paths
1519
if (patterns.assetPaths.test(req.path)) return next()
1620

17-
if (req.context.page) return next()
18-
19-
// ignore paths that don't have an enterprise version number
20-
if (!patterns.getEnterpriseVersionNumber.test(req.path)) return next()
21-
22-
// extract enterprise version from path, e.g. 2.16
23-
const requestedVersion = req.path.match(patterns.getEnterpriseVersionNumber)[1]
24-
25-
// bail if the request version is not deprecated
26-
if (!deprecated.includes(requestedVersion)) return next()
27-
2821
// redirect language-prefixed URLs like /en/enterprise/2.10 -> /enterprise/2.10
2922
// (this only applies to versions <2.13)
3023
if (req.path.startsWith('/en/') && versionSatisfiesRange(requestedVersion, `<${firstVersionDeprecatedOnNewSite}`)) {

tests/routing/deprecated-enterprise-versions.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,13 @@ describe('deprecation banner', () => {
8585
expect($('.deprecation-banner b').text().endsWith('discontinued on .')).toBe(false)
8686
})
8787

88-
test('deprecation warning banner says "will be discontinued" when date is in future', async () => {
88+
test('deprecation warning banner includes the right text depending on the date', async () => {
8989
const $ = await getDOM(`/en/enterprise/${enterpriseServerReleases.oldestSupported}`)
9090
const expectedString = enterpriseServerReleases.isOldestReleaseDeprecated
9191
? 'was discontinued'
9292
: 'will be discontinued'
9393
expect($('.deprecation-banner b').text().includes(expectedString)).toBe(true)
9494
})
95-
96-
test('deprecation warning banner says "was discontinued" when date is in past', async () => {
97-
const $ = await getDOM(`/en/enterprise/${enterpriseServerReleases.deprecated[0]}`)
98-
expect($('.deprecation-banner b').text().includes('was discontinued')).toBe(true)
99-
})
10095
})
10196

10297
describe('does not render helpfulness prompt or contribution button', () => {
@@ -186,7 +181,7 @@ describe('JS and CSS assets', () => {
186181

187182
it('returns the expected CSS file ( <2.13 )', async () => {
188183
const result = await supertest(app)
189-
.get('/stylesheets/application.css')
184+
.get('/assets/stylesheets/application.css')
190185
.set('Referrer', '/en/enterprise/2.12')
191186

192187
expect(result.statusCode).toBe(200)

0 commit comments

Comments
 (0)