Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repo sync #754

Merged
merged 2 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ redirect_from:
- /github/installing-and-configuring-github-insights/updating-github-insights
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 %}.'
versions:
free-pro-team: '*'
enterprise-server: '*'
---

Expand Down
20 changes: 16 additions & 4 deletions lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const patterns = require('./patterns')
const getMapTopicContent = require('./get-map-topic-content')
const rewriteAssetPathsToS3 = require('./rewrite-asset-paths-to-s3')
const rewriteLocalLinks = require('./rewrite-local-links')
const getApplicableVersions = require('./get-applicable-versions')
const encodeBracketedParentheticals = require('./encode-bracketed-parentheticals')
const generateRedirectsForPermalinks = require('./redirects/permalinks')
const getEnglishHeadings = require('./get-english-headings')
Expand Down Expand Up @@ -67,6 +68,15 @@ class Page {
delete this.popularLinks
delete this.guideLinks

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

if (versionsParentProductIsNotAvailableIn.length && this.languageCode === 'en') {
throw new Error(`\`versions\` frontmatter in ${this.fullPath} contains ${versionsParentProductIsNotAvailableIn}, which ${this.parentProduct.id} product is not available in!`)
}

// derive array of Permalink objects
this.permalinks = Permalink.derive(this.languageCode, this.relativePath, this.title, this.versions)

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

// make sure the ID is valid
assert(
Object.keys(products).includes(id),
`page ${this.fullPath} has an invalid product ID: ${id}`
)
if (process.env.NODE_ENV !== 'test') {
assert(
Object.keys(products).includes(id),
`page ${this.fullPath} has an invalid product ID: ${id}`
)
}

return id
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Some GitHub article
versions:
free-pro-team: '*'
enterprise-server: '*'
---
12 changes: 12 additions & 0 deletions tests/unit/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,16 @@ describe('catches errors thrown in Page class', () => {

expect(getPage).toThrowError('versions')
})

test('page with a version in frontmatter that its parent product is not available in', () => {
function getPage () {
return new Page({
relativePath: 'admin/some-category/some-article-with-mismatched-versions-frontmatter.md',
basePath: path.join(__dirname, '../fixtures/products'),
languageCode: 'en'
})
}

expect(getPage).toThrowError(/`versions` frontmatter.*? product is not available in/)
})
})