Skip to content

Commit dd470a1

Browse files
authored
Merge branch 'main' into keyboard-shortcuts-new-guidelines
2 parents 4b97a96 + 37b20ee commit dd470a1

4 files changed

Lines changed: 46 additions & 19 deletions

File tree

content/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ childGroups:
7575
octicon: ShieldLockIcon
7676
children:
7777
- code-security
78+
- code-security/supply-chain-security
79+
- code-security/dependabot
80+
- code-security/code-scanning
81+
- code-security/secret-scanning
7882
- name: Client apps
7983
octicon: DeviceMobileIcon
8084
children:

lib/all-products.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const homepage = path.posix.join(process.cwd(), 'content/index.md')
99
const { data } = frontmatter(await fs.readFile(homepage, 'utf8'))
1010

1111
export const productIds = data.children
12-
export const productGroups = []
1312

1413
const externalProducts = data.externalProducts
1514
const internalProducts = {}
@@ -45,17 +44,37 @@ for (const productId of productIds) {
4544

4645
export const productMap = Object.assign({}, internalProducts, externalProducts)
4746

48-
for (const group of data.childGroups) {
49-
productGroups.push({
50-
name: group.name,
51-
icon: group.icon || null,
52-
octicon: group.octicon || null,
53-
children: group.children.map((id) => productMap[id]),
47+
function getPage(id, lang, pageMap) {
48+
const productId = id.split('/')[0]
49+
const product = productMap[productId]
50+
const href = removeFPTFromPath(path.posix.join('/', lang, product.versions[0], id))
51+
const page = pageMap[href]
52+
if (!page) {
53+
throw new Error(`Unable to find a page by the href '${href}'. Review your 'childGroups' frontmatter maybe.`)
54+
}
55+
// Return only the props needed for the ProductSelectionCard, since
56+
// that's the only place this is ever used.
57+
return {
58+
id,
59+
name: page.shortTitle || page.title,
60+
href: href.replace(`/${lang}/`, '/'),
61+
versions: page.applicableVersions,
62+
}
63+
}
64+
65+
export function getProductGroups(pageMap, lang) {
66+
return data.childGroups.map((group) => {
67+
return {
68+
name: group.name,
69+
icon: group.icon || null,
70+
octicon: group.octicon || null,
71+
// Typically the children are product IDs, but we support deeper page paths too
72+
children: group.children.map((id) => productMap[id] || getPage(id, lang, pageMap)),
73+
}
5474
})
5575
}
5676

5777
export default {
5878
productIds,
5979
productMap,
60-
productGroups,
6180
}

middleware/context.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import languages from '../lib/languages.js'
22
import enterpriseServerReleases from '../lib/enterprise-server-releases.js'
33
import { allVersions } from '../lib/all-versions.js'
4-
import { productMap, productGroups } from '../lib/all-products.js'
4+
import { productMap, getProductGroups } from '../lib/all-products.js'
55
import pathUtils from '../lib/path-utils.js'
66
import productNames from '../lib/product-names.js'
77
import warmServer from '../lib/warm-server.js'
@@ -39,7 +39,7 @@ export default async function contextualize(req, res, next) {
3939
req.context.currentProduct = getProductStringFromPath(req.pagePath)
4040
req.context.currentCategory = getCategoryStringFromPath(req.pagePath)
4141
req.context.productMap = productMap
42-
req.context.productGroups = productGroups
42+
req.context.productGroups = getProductGroups(pageMap, req.language)
4343
req.context.activeProducts = activeProducts
4444
req.context.allVersions = allVersions
4545
req.context.currentPathWithoutLanguage = getPathWithoutLanguage(req.pagePath)

tests/rendering/server.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { loadPages } from '../../lib/page-data.js'
66
import CspParse from 'csp-parse'
77
import { productMap } from '../../lib/all-products.js'
88
import { SURROGATE_ENUMS } from '../../middleware/set-fastly-surrogate-key.js'
9+
import { getPathWithoutVersion } from '../../lib/path-utils.js'
910
import { describe, jest } from '@jest/globals'
1011

1112
const AZURE_STORAGE_URL = 'githubdocs.azureedge.net'
@@ -79,21 +80,24 @@ describe('server', () => {
7980

8081
test('renders the Enterprise homepages with links to expected products in both the sidebar and page body', async () => {
8182
const enterpriseProducts = [
82-
`/en/enterprise-server@${enterpriseServerReleases.latest}`,
83-
'/en/enterprise-cloud@latest',
83+
`enterprise-server@${enterpriseServerReleases.latest}`,
84+
'enterprise-cloud@latest',
8485
]
8586

86-
enterpriseProducts.forEach(async (ep) => {
87-
const $ = await getDOM(ep)
87+
for (const ep of enterpriseProducts) {
88+
const $ = await getDOM(`/en/${ep}`)
8889
const sidebarItems = $('[data-testid=sidebar] li a').get()
8990
const sidebarTitles = sidebarItems.map((el) => $(el).text().trim())
9091
const sidebarHrefs = sidebarItems.map((el) => $(el).attr('href'))
91-
const productItems = $('[data-testid=product] div a').get()
92-
const productTitles = productItems.map((el) => $(el).text().trim())
93-
const productHrefs = productItems.map((el) => $(el).attr('href'))
92+
const productItems = activeProducts.filter(
93+
(prod) => prod.external || prod.versions.includes(ep)
94+
)
95+
const productTitles = productItems.map((prod) => prod.name)
96+
const productHrefs = productItems.map((prod) =>
97+
prod.external ? prod.href : `/en/${ep}${getPathWithoutVersion(prod.href)}`
98+
)
9499

95100
const titlesInProductsButNotSidebar = lodash.difference(productTitles, sidebarTitles)
96-
97101
const hrefsInProductsButNotSidebar = lodash.difference(productHrefs, sidebarHrefs)
98102

99103
expect(
@@ -104,7 +108,7 @@ describe('server', () => {
104108
hrefsInProductsButNotSidebar.length,
105109
`Found hrefs missing from sidebar: ${hrefsInProductsButNotSidebar.join(', ')}`
106110
).toBe(0)
107-
})
111+
}
108112
})
109113

110114
test('sets Content Security Policy (CSP) headers', async () => {

0 commit comments

Comments
 (0)