forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeatures.js
18 lines (14 loc) · 837 Bytes
/
features.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const getApplicableVersions = require('../../lib/get-applicable-versions')
module.exports = async function features (req, res, next) {
if (!req.context.page) return next()
// Determine whether the currentVersion belongs to the list of versions the feature is available in.
Object.keys(req.context.site.data.features).forEach(featureName => {
const { versions } = req.context.site.data.features[featureName]
const applicableVersions = getApplicableVersions(versions, req.path)
// Adding the resulting boolean to the context object gives us the ability to use
// `{% if featureName ... %}` conditionals in content files.
const isFeatureAvailableInCurrentVersion = applicableVersions.includes(req.context.currentVersion)
req.context[featureName] = isFeatureAvailableInCurrentVersion
})
return next()
}