forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
product-examples.js
22 lines (17 loc) · 1 KB
/
product-examples.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const getApplicableVersions = require('../../lib/get-applicable-versions')
module.exports = async function productExamples (req, res, next) {
if (!req.context.page) return next()
if (req.context.currentLayoutName !== 'product-landing') return next()
const productExamples = req.context.site.data['product-examples'][req.context.currentProduct]
if (!productExamples) return next()
req.context.productCommunityExamples = productExamples['community-examples']
req.context.productUserExamples = productExamples['user-examples']
// We currently only support versioning in code examples.
// TODO support versioning across all example types.
req.context.productCodeExamples = productExamples['code-examples'] && productExamples['code-examples']
.filter(example => {
// If an example block does NOT contain the versions prop, assume it's available in all versions
return !example.versions || getApplicableVersions(example.versions).includes(req.context.currentVersion)
})
return next()
}