Skip to content

Commit 641d1ac

Browse files
authored
repo sync
2 parents 9f38de4 + 095410d commit 641d1ac

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

content/insights/installing-and-configuring-github-insights/updating-github-insights.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ redirect_from:
66
- /github/installing-and-configuring-github-insights/updating-github-insights
77
permissions: 'People with read permissions to the `github/insights-releases` repository and administrative access to the application server can update {% data variables.product.prodname_insights %}.'
88
versions:
9-
free-pro-team: '*'
109
enterprise-server: '*'
1110
---
1211

lib/page.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const patterns = require('./patterns')
66
const getMapTopicContent = require('./get-map-topic-content')
77
const rewriteAssetPathsToS3 = require('./rewrite-asset-paths-to-s3')
88
const rewriteLocalLinks = require('./rewrite-local-links')
9+
const getApplicableVersions = require('./get-applicable-versions')
910
const encodeBracketedParentheticals = require('./encode-bracketed-parentheticals')
1011
const generateRedirectsForPermalinks = require('./redirects/permalinks')
1112
const getEnglishHeadings = require('./get-english-headings')
@@ -67,6 +68,15 @@ class Page {
6768
delete this.popularLinks
6869
delete this.guideLinks
6970

71+
// a page should only be available in versions that its parent product is available in
72+
const versionsParentProductIsNotAvailableIn = getApplicableVersions(this.versions, this.fullPath)
73+
// only the homepage will not have this.parentProduct
74+
.filter(availableVersion => this.parentProduct && !this.parentProduct.versions.includes(availableVersion))
75+
76+
if (versionsParentProductIsNotAvailableIn.length && this.languageCode === 'en') {
77+
throw new Error(`\`versions\` frontmatter in ${this.fullPath} contains ${versionsParentProductIsNotAvailableIn}, which ${this.parentProduct.id} product is not available in!`)
78+
}
79+
7080
// derive array of Permalink objects
7181
this.permalinks = Permalink.derive(this.languageCode, this.relativePath, this.title, this.versions)
7282

@@ -95,10 +105,12 @@ class Page {
95105
if (id === 'index.md') return null
96106

97107
// make sure the ID is valid
98-
assert(
99-
Object.keys(products).includes(id),
100-
`page ${this.fullPath} has an invalid product ID: ${id}`
101-
)
108+
if (process.env.NODE_ENV !== 'test') {
109+
assert(
110+
Object.keys(products).includes(id),
111+
`page ${this.fullPath} has an invalid product ID: ${id}`
112+
)
113+
}
102114

103115
return id
104116
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: Some GitHub article
3+
versions:
4+
free-pro-team: '*'
5+
enterprise-server: '*'
6+
---

tests/unit/page.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,16 @@ describe('catches errors thrown in Page class', () => {
365365

366366
expect(getPage).toThrowError('versions')
367367
})
368+
369+
test('page with a version in frontmatter that its parent product is not available in', () => {
370+
function getPage () {
371+
return new Page({
372+
relativePath: 'admin/some-category/some-article-with-mismatched-versions-frontmatter.md',
373+
basePath: path.join(__dirname, '../fixtures/products'),
374+
languageCode: 'en'
375+
})
376+
}
377+
378+
expect(getPage).toThrowError(/`versions` frontmatter.*? product is not available in/)
379+
})
368380
})

0 commit comments

Comments
 (0)