update references
This commit is contained in:
@@ -26,7 +26,7 @@
|
|||||||
<div id="current-product" class="d-flex flex-items-center flex-justify-between" style="padding-top: 2px;">
|
<div id="current-product" class="d-flex flex-items-center flex-justify-between" style="padding-top: 2px;">
|
||||||
<!-- Product switcher - GitHub.com, Enterprise Server, etc -->
|
<!-- 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 -->
|
<!-- 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>
|
<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>
|
</div>
|
||||||
</summary>
|
</summary>
|
||||||
|
|||||||
@@ -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)
|
.filter(product => !product.external)
|
||||||
.map(product => product.toc.replace('content/', ''))
|
.map(product => product.toc.replace('content/', ''))
|
||||||
|
|
||||||
|
|||||||
11
lib/page.js
11
lib/page.js
@@ -12,7 +12,7 @@ const Permalink = require('./permalink')
|
|||||||
const languages = require('./languages')
|
const languages = require('./languages')
|
||||||
const renderContent = require('./render-content')
|
const renderContent = require('./render-content')
|
||||||
const { renderReact } = require('./react/engine')
|
const { renderReact } = require('./react/engine')
|
||||||
const products = require('./all-products')
|
const { productMap } = require('./all-products')
|
||||||
const slash = require('slash')
|
const slash = require('slash')
|
||||||
const statsd = require('./statsd')
|
const statsd = require('./statsd')
|
||||||
const readFileContents = require('./read-file-contents')
|
const readFileContents = require('./read-file-contents')
|
||||||
@@ -76,8 +76,11 @@ class Page {
|
|||||||
this.introLinks.rawOverview = this.introLinks.overview
|
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
|
// 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
|
// only the homepage will not have this.parentProduct
|
||||||
.filter(availableVersion => this.parentProduct && !this.parentProduct.versions.includes(availableVersion))
|
.filter(availableVersion => this.parentProduct && !this.parentProduct.versions.includes(availableVersion))
|
||||||
|
|
||||||
@@ -124,7 +127,7 @@ class Page {
|
|||||||
// make sure the ID is valid
|
// make sure the ID is valid
|
||||||
if (process.env.NODE_ENV !== 'test') {
|
if (process.env.NODE_ENV !== 'test') {
|
||||||
assert(
|
assert(
|
||||||
Object.keys(products).includes(id),
|
Object.keys(productMap).includes(id),
|
||||||
`page ${this.fullPath} has an invalid product ID: ${id}`
|
`page ${this.fullPath} has an invalid product ID: ${id}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -133,7 +136,7 @@ class Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get parentProduct () {
|
get parentProduct () {
|
||||||
return products[this.parentProductId]
|
return productMap[this.parentProductId]
|
||||||
}
|
}
|
||||||
|
|
||||||
async renderTitle (context, opts = {}) {
|
async renderTitle (context, opts = {}) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const slash = require('slash')
|
|||||||
const path = require('path')
|
const path = require('path')
|
||||||
const patterns = require('./patterns')
|
const patterns = require('./patterns')
|
||||||
const { latest } = require('./enterprise-server-releases')
|
const { latest } = require('./enterprise-server-releases')
|
||||||
const allProducts = require('./all-products')
|
const { productIds } = require('./all-products')
|
||||||
const allVersions = require('./all-versions')
|
const allVersions = require('./all-versions')
|
||||||
const supportedVersions = new Set(Object.keys(allVersions))
|
const supportedVersions = new Set(Object.keys(allVersions))
|
||||||
const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
|
const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
|
||||||
@@ -43,7 +43,7 @@ function getVersionStringFromPath (href) {
|
|||||||
const versionFromPath = href.split('/')[1]
|
const versionFromPath = href.split('/')[1]
|
||||||
|
|
||||||
// If the first segment is a supported product, assume this is FPT
|
// If the first segment is a supported product, assume this is FPT
|
||||||
if (allProducts[versionFromPath]) {
|
if (productIds.includes(versionFromPath)) {
|
||||||
return nonEnterpriseDefaultVersion
|
return nonEnterpriseDefaultVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ function getProductStringFromPath (href) {
|
|||||||
|
|
||||||
if (pathParts.includes('early-access')) return 'early-access'
|
if (pathParts.includes('early-access')) return 'early-access'
|
||||||
|
|
||||||
return allProducts[pathParts[2]]
|
return productIds.includes(pathParts[2])
|
||||||
? pathParts[2]
|
? pathParts[2]
|
||||||
: pathParts[1]
|
: pathParts[1]
|
||||||
}
|
}
|
||||||
@@ -99,20 +99,13 @@ function getCategoryStringFromPath (href) {
|
|||||||
|
|
||||||
if (pathParts.includes('early-access')) return null
|
if (pathParts.includes('early-access')) return null
|
||||||
|
|
||||||
const productIndex = allProducts[pathParts[2]]
|
const productIndex = productIds.includes(pathParts[2])
|
||||||
? 2
|
? 2
|
||||||
: 1
|
: 1
|
||||||
|
|
||||||
return pathParts[productIndex + 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 = {
|
module.exports = {
|
||||||
getPathWithLanguage,
|
getPathWithLanguage,
|
||||||
getPathWithoutLanguage,
|
getPathWithoutLanguage,
|
||||||
@@ -120,6 +113,5 @@ module.exports = {
|
|||||||
getVersionStringFromPath,
|
getVersionStringFromPath,
|
||||||
getVersionObjectFromPath,
|
getVersionObjectFromPath,
|
||||||
getProductStringFromPath,
|
getProductStringFromPath,
|
||||||
getCategoryStringFromPath,
|
getCategoryStringFromPath
|
||||||
getProductObjectFromPath
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const path = require('path')
|
const path = require('path')
|
||||||
const products = Object.values(require('./all-products'))
|
const { productMap } = require('./all-products')
|
||||||
const languageCodes = Object.keys(require('./languages'))
|
const languageCodes = Object.keys(require('./languages'))
|
||||||
const addTitlesToTree = require('./site-tree-titles')
|
const addTitlesToTree = require('./site-tree-titles')
|
||||||
const allVersions = Object.keys(require('./all-versions'))
|
const allVersions = Object.keys(require('./all-versions'))
|
||||||
@@ -26,7 +26,7 @@ module.exports = async function buildSiteTree (pageMap, site, redirects) {
|
|||||||
siteTree[languageCode][version] = {}
|
siteTree[languageCode][version] = {}
|
||||||
const productTree = {}
|
const productTree = {}
|
||||||
|
|
||||||
products.forEach(item => {
|
Object.values(productMap).forEach(item => {
|
||||||
const product = { title: item.name }
|
const product = { title: item.name }
|
||||||
|
|
||||||
// return early if the product has external docs, like Atom
|
// return early if the product has external docs, like Atom
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const languages = require('../lib/languages')
|
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 { deprecated } = require('../lib/enterprise-server-releases.js')
|
||||||
|
|
||||||
const pathRegExps = [
|
const pathRegExps = [
|
||||||
@@ -9,7 +9,7 @@ const pathRegExps = [
|
|||||||
.map(language => new RegExp(`^/${language.code}(/.*)?$`, 'i')),
|
.map(language => new RegExp(`^/${language.code}(/.*)?$`, 'i')),
|
||||||
|
|
||||||
// Disallow indexing of WIP products
|
// Disallow indexing of WIP products
|
||||||
...Object.values(products)
|
...Object.values(productMap)
|
||||||
.filter(product => product.wip || product.hidden)
|
.filter(product => product.wip || product.hidden)
|
||||||
.map(product => [
|
.map(product => [
|
||||||
new RegExp(`^/.*?${product.href}`, 'i'),
|
new RegExp(`^/.*?${product.href}`, 'i'),
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const languages = require('../lib/languages')
|
const languages = require('../lib/languages')
|
||||||
const enterpriseServerReleases = require('../lib/enterprise-server-releases')
|
const enterpriseServerReleases = require('../lib/enterprise-server-releases')
|
||||||
const allVersions = require('../lib/all-versions')
|
const allVersions = require('../lib/all-versions')
|
||||||
const allProducts = require('../lib/all-products')
|
const { productMap } = require('../lib/all-products')
|
||||||
const activeProducts = Object.values(allProducts).filter(product => !product.wip && !product.hidden)
|
const activeProducts = Object.values(productMap).filter(product => !product.wip && !product.hidden)
|
||||||
const {
|
const {
|
||||||
getVersionStringFromPath,
|
getVersionStringFromPath,
|
||||||
getProductStringFromPath,
|
getProductStringFromPath,
|
||||||
@@ -37,7 +37,7 @@ module.exports = async function contextualize (req, res, next) {
|
|||||||
req.context.currentVersion = getVersionStringFromPath(req.path)
|
req.context.currentVersion = getVersionStringFromPath(req.path)
|
||||||
req.context.currentProduct = getProductStringFromPath(req.path)
|
req.context.currentProduct = getProductStringFromPath(req.path)
|
||||||
req.context.currentCategory = getCategoryStringFromPath(req.path)
|
req.context.currentCategory = getCategoryStringFromPath(req.path)
|
||||||
req.context.allProducts = allProducts
|
req.context.productMap = productMap
|
||||||
req.context.activeProducts = activeProducts
|
req.context.activeProducts = activeProducts
|
||||||
req.context.allVersions = allVersions
|
req.context.allVersions = allVersions
|
||||||
req.context.currentPathWithoutLanguage = getPathWithoutLanguage(req.path)
|
req.context.currentPathWithoutLanguage = getPathWithoutLanguage(req.path)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const { blockIndex } = require('../../middleware/block-robots')
|
const { blockIndex } = require('../../middleware/block-robots')
|
||||||
const languages = require('../../lib/languages')
|
const languages = require('../../lib/languages')
|
||||||
const products = require('../../lib/all-products')
|
const { productMap } = require('../../lib/all-products')
|
||||||
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
|
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
|
||||||
|
|
||||||
function allowIndex (path) {
|
function allowIndex (path) {
|
||||||
@@ -33,12 +33,12 @@ describe('block robots', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('disallows crawling of WIP products', async () => {
|
it('disallows crawling of WIP products', async () => {
|
||||||
const wipProductIds = Object.values(products)
|
const wipProductIds = Object.values(productMap)
|
||||||
.filter(product => product.wip)
|
.filter(product => product.wip)
|
||||||
.map(product => product.id)
|
.map(product => product.id)
|
||||||
|
|
||||||
wipProductIds.forEach(id => {
|
wipProductIds.forEach(id => {
|
||||||
const { href } = products[id]
|
const { href } = productMap[id]
|
||||||
const blockedPaths = [
|
const blockedPaths = [
|
||||||
// English
|
// English
|
||||||
`/en${href}`,
|
`/en${href}`,
|
||||||
@@ -62,12 +62,12 @@ describe('block robots', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('disallows crawling of early access "hidden" products', async () => {
|
it('disallows crawling of early access "hidden" products', async () => {
|
||||||
const hiddenProductIds = Object.values(products)
|
const hiddenProductIds = Object.values(productMap)
|
||||||
.filter(product => product.hidden)
|
.filter(product => product.hidden)
|
||||||
.map(product => product.id)
|
.map(product => product.id)
|
||||||
|
|
||||||
hiddenProductIds.forEach(id => {
|
hiddenProductIds.forEach(id => {
|
||||||
const { versions } = products[id]
|
const { versions } = productMap[id]
|
||||||
const blockedPaths = versions.map(version => {
|
const blockedPaths = versions.map(version => {
|
||||||
return [
|
return [
|
||||||
// English
|
// English
|
||||||
@@ -86,7 +86,7 @@ describe('block robots', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('allows crawling of non-WIP products', async () => {
|
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')).toBe(true)
|
||||||
expect(allowIndex('/en/actions/overview')).toBe(true)
|
expect(allowIndex('/en/actions/overview')).toBe(true)
|
||||||
expect(allowIndex('/en/actions/overview/intro')).toBe(true)
|
expect(allowIndex('/en/actions/overview/intro')).toBe(true)
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
const revalidator = require('revalidator')
|
const revalidator = require('revalidator')
|
||||||
const products = require('../../lib/all-products')
|
const { productMap } = require('../../lib/all-products')
|
||||||
const schema = require('../../lib/products-schema')
|
const schema = require('../../lib/products-schema')
|
||||||
const { getDOM, getJSON } = require('../helpers/supertest')
|
const { getDOM, getJSON } = require('../helpers/supertest')
|
||||||
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
|
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
|
||||||
|
|
||||||
describe('products module', () => {
|
describe('products module', () => {
|
||||||
test('is an object with product ids as keys', () => {
|
test('is an object with product ids as keys', () => {
|
||||||
expect('github' in products).toBe(true)
|
expect('github' in productMap).toBe(true)
|
||||||
expect('desktop' in products).toBe(true)
|
expect('desktop' in productMap).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('every product is valid', () => {
|
test('every product is valid', () => {
|
||||||
Object.values(products).forEach(product => {
|
Object.values(productMap).forEach(product => {
|
||||||
const { valid, errors } = revalidator.validate(product, schema)
|
const { valid, errors } = revalidator.validate(product, schema)
|
||||||
const expectation = JSON.stringify({ product, errors }, null, 2)
|
const expectation = JSON.stringify({ product, errors }, null, 2)
|
||||||
expect(valid, expectation).toBe(true)
|
expect(valid, expectation).toBe(true)
|
||||||
|
|||||||
Reference in New Issue
Block a user