Skip to content

Commit

Permalink
update references
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahs committed Apr 1, 2021
1 parent 2295496 commit c7f647f
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 36 deletions.
2 changes: 1 addition & 1 deletion includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h4 class="text-mono f5 text-normal text-gray d-md-none">{% data ui.homepage.exp
<div id="current-product" class="d-flex flex-items-center flex-justify-between" style="padding-top: 2px;">
<!-- Product switcher - GitHub.com, Enterprise Server, etc -->
<!-- 404 and 500 error layouts are not real pages so we need to hardcode the name for those -->
{{ allProducts[currentProduct].name }}
{{ productMap[currentProduct].name }}
<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>
</div>
</summary>
Expand Down
3 changes: 2 additions & 1 deletion lib/get-toc-items.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const productTOCs = Object.values(require('./all-products'))
const { productMap } = require('./all-products')
const productTOCs = Object.values(productMap)
.filter(product => !product.external)
.map(product => product.toc.replace('content/', ''))

Expand Down
11 changes: 7 additions & 4 deletions lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Permalink = require('./permalink')
const languages = require('./languages')
const renderContent = require('./render-content')
const { renderReact } = require('./react/engine')
const products = require('./all-products')
const { productMap } = require('./all-products')
const slash = require('slash')
const statsd = require('./statsd')
const readFileContents = require('./read-file-contents')
Expand Down Expand Up @@ -76,8 +76,11 @@ class Page {
this.introLinks.rawOverview = this.introLinks.overview
}

// Get array of versions that the page is available in for fast lookup
this.applicableVersions = getApplicableVersions(this.versions, this.fullPath)

// a page should only be available in versions that its parent product is available in
const versionsParentProductIsNotAvailableIn = getApplicableVersions(this.versions, this.fullPath)
const versionsParentProductIsNotAvailableIn = this.applicableVersions
// only the homepage will not have this.parentProduct
.filter(availableVersion => this.parentProduct && !this.parentProduct.versions.includes(availableVersion))

Expand Down Expand Up @@ -124,7 +127,7 @@ class Page {
// make sure the ID is valid
if (process.env.NODE_ENV !== 'test') {
assert(
Object.keys(products).includes(id),
Object.keys(productMap).includes(id),
`page ${this.fullPath} has an invalid product ID: ${id}`
)
}
Expand All @@ -133,7 +136,7 @@ class Page {
}

get parentProduct () {
return products[this.parentProductId]
return productMap[this.parentProductId]
}

async renderTitle (context, opts = {}) {
Expand Down
18 changes: 5 additions & 13 deletions lib/path-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const slash = require('slash')
const path = require('path')
const patterns = require('./patterns')
const { latest } = require('./enterprise-server-releases')
const allProducts = require('./all-products')
const { productIds } = require('./all-products')
const allVersions = require('./all-versions')
const supportedVersions = new Set(Object.keys(allVersions))
const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
Expand Down Expand Up @@ -43,7 +43,7 @@ function getVersionStringFromPath (href) {
const versionFromPath = href.split('/')[1]

// If the first segment is a supported product, assume this is FPT
if (allProducts[versionFromPath]) {
if (productIds.includes(versionFromPath)) {
return nonEnterpriseDefaultVersion
}

Expand Down Expand Up @@ -85,7 +85,7 @@ function getProductStringFromPath (href) {

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

return allProducts[pathParts[2]]
return productIds.includes(pathParts[2])
? pathParts[2]
: pathParts[1]
}
Expand All @@ -99,27 +99,19 @@ function getCategoryStringFromPath (href) {

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

const productIndex = allProducts[pathParts[2]]
const productIndex = productIds.includes(pathParts[2])
? 2
: 1

return pathParts[productIndex + 1]
}

// Return the corresponding object for the product segment in a path
function getProductObjectFromPath (href) {
const productFromPath = getProductStringFromPath(href)

return allProducts[productFromPath]
}

module.exports = {
getPathWithLanguage,
getPathWithoutLanguage,
getPathWithoutVersion,
getVersionStringFromPath,
getVersionObjectFromPath,
getProductStringFromPath,
getCategoryStringFromPath,
getProductObjectFromPath
getCategoryStringFromPath
}
4 changes: 2 additions & 2 deletions lib/site-tree.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path')
const products = Object.values(require('./all-products'))
const { productMap } = require('./all-products')
const languageCodes = Object.keys(require('./languages'))
const addTitlesToTree = require('./site-tree-titles')
const allVersions = Object.keys(require('./all-versions'))
Expand All @@ -26,7 +26,7 @@ module.exports = async function buildSiteTree (pageMap, site, redirects) {
siteTree[languageCode][version] = {}
const productTree = {}

products.forEach(item => {
Object.values(productMap).forEach(item => {
const product = { title: item.name }

// return early if the product has external docs, like Atom
Expand Down
4 changes: 2 additions & 2 deletions middleware/block-robots.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const languages = require('../lib/languages')
const products = require('../lib/all-products')
const { productMap } = require('../lib/all-products')
const { deprecated } = require('../lib/enterprise-server-releases.js')

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

// Disallow indexing of WIP products
...Object.values(products)
...Object.values(productMap)
.filter(product => product.wip || product.hidden)
.map(product => [
new RegExp(`^/.*?${product.href}`, 'i'),
Expand Down
6 changes: 3 additions & 3 deletions middleware/context.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const languages = require('../lib/languages')
const enterpriseServerReleases = require('../lib/enterprise-server-releases')
const allVersions = require('../lib/all-versions')
const allProducts = require('../lib/all-products')
const activeProducts = Object.values(allProducts).filter(product => !product.wip && !product.hidden)
const { productMap } = require('../lib/all-products')
const activeProducts = Object.values(productMap).filter(product => !product.wip && !product.hidden)
const {
getVersionStringFromPath,
getProductStringFromPath,
Expand Down Expand Up @@ -37,7 +37,7 @@ module.exports = async function contextualize (req, res, next) {
req.context.currentVersion = getVersionStringFromPath(req.path)
req.context.currentProduct = getProductStringFromPath(req.path)
req.context.currentCategory = getCategoryStringFromPath(req.path)
req.context.allProducts = allProducts
req.context.productMap = productMap
req.context.activeProducts = activeProducts
req.context.allVersions = allVersions
req.context.currentPathWithoutLanguage = getPathWithoutLanguage(req.path)
Expand Down
12 changes: 6 additions & 6 deletions tests/rendering/block-robots.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { blockIndex } = require('../../middleware/block-robots')
const languages = require('../../lib/languages')
const products = require('../../lib/all-products')
const { productMap } = require('../../lib/all-products')
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')

function allowIndex (path) {
Expand Down Expand Up @@ -33,12 +33,12 @@ describe('block robots', () => {
})

it('disallows crawling of WIP products', async () => {
const wipProductIds = Object.values(products)
const wipProductIds = Object.values(productMap)
.filter(product => product.wip)
.map(product => product.id)

wipProductIds.forEach(id => {
const { href } = products[id]
const { href } = productMap[id]
const blockedPaths = [
// English
`/en${href}`,
Expand All @@ -62,12 +62,12 @@ describe('block robots', () => {
})

it('disallows crawling of early access "hidden" products', async () => {
const hiddenProductIds = Object.values(products)
const hiddenProductIds = Object.values(productMap)
.filter(product => product.hidden)
.map(product => product.id)

hiddenProductIds.forEach(id => {
const { versions } = products[id]
const { versions } = productMap[id]
const blockedPaths = versions.map(version => {
return [
// English
Expand All @@ -86,7 +86,7 @@ describe('block robots', () => {
})

it('allows crawling of non-WIP products', async () => {
expect('actions' in products).toBe(true)
expect('actions' in productMap).toBe(true)
expect(allowIndex('/en/actions')).toBe(true)
expect(allowIndex('/en/actions/overview')).toBe(true)
expect(allowIndex('/en/actions/overview/intro')).toBe(true)
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/products.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const revalidator = require('revalidator')
const products = require('../../lib/all-products')
const { productMap } = require('../../lib/all-products')
const schema = require('../../lib/products-schema')
const { getDOM, getJSON } = require('../helpers/supertest')
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')

describe('products module', () => {
test('is an object with product ids as keys', () => {
expect('github' in products).toBe(true)
expect('desktop' in products).toBe(true)
expect('github' in productMap).toBe(true)
expect('desktop' in productMap).toBe(true)
})

test('every product is valid', () => {
Object.values(products).forEach(product => {
Object.values(productMap).forEach(product => {
const { valid, errors } = revalidator.validate(product, schema)
const expectation = JSON.stringify({ product, errors }, null, 2)
expect(valid, expectation).toBe(true)
Expand Down

0 comments on commit c7f647f

Please sign in to comment.