Skip to content

Commit c7f647f

Browse files
committed
update references
1 parent 2295496 commit c7f647f

9 files changed

Lines changed: 32 additions & 36 deletions

File tree

includes/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ <h4 class="text-mono f5 text-normal text-gray d-md-none">{% data ui.homepage.exp
2626
<div id="current-product" class="d-flex flex-items-center flex-justify-between" style="padding-top: 2px;">
2727
<!-- Product switcher - GitHub.com, Enterprise Server, etc -->
2828
<!-- 404 and 500 error layouts are not real pages so we need to hardcode the name for those -->
29-
{{ allProducts[currentProduct].name }}
29+
{{ productMap[currentProduct].name }}
3030
<svg class="arrow ml-md-1" width="14px" height="8px" viewBox="0 0 14 8" xml:space="preserve" fill="none" stroke="#1277eb"><path d="M1,1l6.2,6L13,1"></path></svg>
3131
</div>
3232
</summary>

lib/get-toc-items.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const productTOCs = Object.values(require('./all-products'))
1+
const { productMap } = require('./all-products')
2+
const productTOCs = Object.values(productMap)
23
.filter(product => !product.external)
34
.map(product => product.toc.replace('content/', ''))
45

lib/page.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const Permalink = require('./permalink')
1212
const languages = require('./languages')
1313
const renderContent = require('./render-content')
1414
const { renderReact } = require('./react/engine')
15-
const products = require('./all-products')
15+
const { productMap } = require('./all-products')
1616
const slash = require('slash')
1717
const statsd = require('./statsd')
1818
const readFileContents = require('./read-file-contents')
@@ -76,8 +76,11 @@ class Page {
7676
this.introLinks.rawOverview = this.introLinks.overview
7777
}
7878

79+
// Get array of versions that the page is available in for fast lookup
80+
this.applicableVersions = getApplicableVersions(this.versions, this.fullPath)
81+
7982
// a page should only be available in versions that its parent product is available in
80-
const versionsParentProductIsNotAvailableIn = getApplicableVersions(this.versions, this.fullPath)
83+
const versionsParentProductIsNotAvailableIn = this.applicableVersions
8184
// only the homepage will not have this.parentProduct
8285
.filter(availableVersion => this.parentProduct && !this.parentProduct.versions.includes(availableVersion))
8386

@@ -124,7 +127,7 @@ class Page {
124127
// make sure the ID is valid
125128
if (process.env.NODE_ENV !== 'test') {
126129
assert(
127-
Object.keys(products).includes(id),
130+
Object.keys(productMap).includes(id),
128131
`page ${this.fullPath} has an invalid product ID: ${id}`
129132
)
130133
}
@@ -133,7 +136,7 @@ class Page {
133136
}
134137

135138
get parentProduct () {
136-
return products[this.parentProductId]
139+
return productMap[this.parentProductId]
137140
}
138141

139142
async renderTitle (context, opts = {}) {

lib/path-utils.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const slash = require('slash')
22
const path = require('path')
33
const patterns = require('./patterns')
44
const { latest } = require('./enterprise-server-releases')
5-
const allProducts = require('./all-products')
5+
const { productIds } = require('./all-products')
66
const allVersions = require('./all-versions')
77
const supportedVersions = new Set(Object.keys(allVersions))
88
const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
@@ -43,7 +43,7 @@ function getVersionStringFromPath (href) {
4343
const versionFromPath = href.split('/')[1]
4444

4545
// If the first segment is a supported product, assume this is FPT
46-
if (allProducts[versionFromPath]) {
46+
if (productIds.includes(versionFromPath)) {
4747
return nonEnterpriseDefaultVersion
4848
}
4949

@@ -85,7 +85,7 @@ function getProductStringFromPath (href) {
8585

8686
if (pathParts.includes('early-access')) return 'early-access'
8787

88-
return allProducts[pathParts[2]]
88+
return productIds.includes(pathParts[2])
8989
? pathParts[2]
9090
: pathParts[1]
9191
}
@@ -99,27 +99,19 @@ function getCategoryStringFromPath (href) {
9999

100100
if (pathParts.includes('early-access')) return null
101101

102-
const productIndex = allProducts[pathParts[2]]
102+
const productIndex = productIds.includes(pathParts[2])
103103
? 2
104104
: 1
105105

106106
return pathParts[productIndex + 1]
107107
}
108108

109-
// Return the corresponding object for the product segment in a path
110-
function getProductObjectFromPath (href) {
111-
const productFromPath = getProductStringFromPath(href)
112-
113-
return allProducts[productFromPath]
114-
}
115-
116109
module.exports = {
117110
getPathWithLanguage,
118111
getPathWithoutLanguage,
119112
getPathWithoutVersion,
120113
getVersionStringFromPath,
121114
getVersionObjectFromPath,
122115
getProductStringFromPath,
123-
getCategoryStringFromPath,
124-
getProductObjectFromPath
116+
getCategoryStringFromPath
125117
}

lib/site-tree.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const path = require('path')
2-
const products = Object.values(require('./all-products'))
2+
const { productMap } = require('./all-products')
33
const languageCodes = Object.keys(require('./languages'))
44
const addTitlesToTree = require('./site-tree-titles')
55
const allVersions = Object.keys(require('./all-versions'))
@@ -26,7 +26,7 @@ module.exports = async function buildSiteTree (pageMap, site, redirects) {
2626
siteTree[languageCode][version] = {}
2727
const productTree = {}
2828

29-
products.forEach(item => {
29+
Object.values(productMap).forEach(item => {
3030
const product = { title: item.name }
3131

3232
// return early if the product has external docs, like Atom

middleware/block-robots.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const languages = require('../lib/languages')
2-
const products = require('../lib/all-products')
2+
const { productMap } = require('../lib/all-products')
33
const { deprecated } = require('../lib/enterprise-server-releases.js')
44

55
const pathRegExps = [
@@ -9,7 +9,7 @@ const pathRegExps = [
99
.map(language => new RegExp(`^/${language.code}(/.*)?$`, 'i')),
1010

1111
// Disallow indexing of WIP products
12-
...Object.values(products)
12+
...Object.values(productMap)
1313
.filter(product => product.wip || product.hidden)
1414
.map(product => [
1515
new RegExp(`^/.*?${product.href}`, 'i'),

middleware/context.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const languages = require('../lib/languages')
22
const enterpriseServerReleases = require('../lib/enterprise-server-releases')
33
const allVersions = require('../lib/all-versions')
4-
const allProducts = require('../lib/all-products')
5-
const activeProducts = Object.values(allProducts).filter(product => !product.wip && !product.hidden)
4+
const { productMap } = require('../lib/all-products')
5+
const activeProducts = Object.values(productMap).filter(product => !product.wip && !product.hidden)
66
const {
77
getVersionStringFromPath,
88
getProductStringFromPath,
@@ -37,7 +37,7 @@ module.exports = async function contextualize (req, res, next) {
3737
req.context.currentVersion = getVersionStringFromPath(req.path)
3838
req.context.currentProduct = getProductStringFromPath(req.path)
3939
req.context.currentCategory = getCategoryStringFromPath(req.path)
40-
req.context.allProducts = allProducts
40+
req.context.productMap = productMap
4141
req.context.activeProducts = activeProducts
4242
req.context.allVersions = allVersions
4343
req.context.currentPathWithoutLanguage = getPathWithoutLanguage(req.path)

tests/rendering/block-robots.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { blockIndex } = require('../../middleware/block-robots')
22
const languages = require('../../lib/languages')
3-
const products = require('../../lib/all-products')
3+
const { productMap } = require('../../lib/all-products')
44
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
55

66
function allowIndex (path) {
@@ -33,12 +33,12 @@ describe('block robots', () => {
3333
})
3434

3535
it('disallows crawling of WIP products', async () => {
36-
const wipProductIds = Object.values(products)
36+
const wipProductIds = Object.values(productMap)
3737
.filter(product => product.wip)
3838
.map(product => product.id)
3939

4040
wipProductIds.forEach(id => {
41-
const { href } = products[id]
41+
const { href } = productMap[id]
4242
const blockedPaths = [
4343
// English
4444
`/en${href}`,
@@ -62,12 +62,12 @@ describe('block robots', () => {
6262
})
6363

6464
it('disallows crawling of early access "hidden" products', async () => {
65-
const hiddenProductIds = Object.values(products)
65+
const hiddenProductIds = Object.values(productMap)
6666
.filter(product => product.hidden)
6767
.map(product => product.id)
6868

6969
hiddenProductIds.forEach(id => {
70-
const { versions } = products[id]
70+
const { versions } = productMap[id]
7171
const blockedPaths = versions.map(version => {
7272
return [
7373
// English
@@ -86,7 +86,7 @@ describe('block robots', () => {
8686
})
8787

8888
it('allows crawling of non-WIP products', async () => {
89-
expect('actions' in products).toBe(true)
89+
expect('actions' in productMap).toBe(true)
9090
expect(allowIndex('/en/actions')).toBe(true)
9191
expect(allowIndex('/en/actions/overview')).toBe(true)
9292
expect(allowIndex('/en/actions/overview/intro')).toBe(true)

tests/unit/products.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
const revalidator = require('revalidator')
2-
const products = require('../../lib/all-products')
2+
const { productMap } = require('../../lib/all-products')
33
const schema = require('../../lib/products-schema')
44
const { getDOM, getJSON } = require('../helpers/supertest')
55
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
66

77
describe('products module', () => {
88
test('is an object with product ids as keys', () => {
9-
expect('github' in products).toBe(true)
10-
expect('desktop' in products).toBe(true)
9+
expect('github' in productMap).toBe(true)
10+
expect('desktop' in productMap).toBe(true)
1111
})
1212

1313
test('every product is valid', () => {
14-
Object.values(products).forEach(product => {
14+
Object.values(productMap).forEach(product => {
1515
const { valid, errors } = revalidator.validate(product, schema)
1616
const expectation = JSON.stringify({ product, errors }, null, 2)
1717
expect(valid, expectation).toBe(true)

0 commit comments

Comments
 (0)