forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotices.js
38 lines (30 loc) · 1.07 KB
/
notices.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const { set } = require('lodash')
const patterns = require('../lib/patterns')
const languages = require('../lib/languages')
module.exports = (req, res, next) => {
// Skip asset paths
if (patterns.assetPaths.test(req.path)) return next()
const language = languages[req.language]
// Set flag that enables `localization_complete` message for no-longer-WIP languages
set(
req.context,
'site.data.ui.header.notices.flags.localization_complete',
language.code !== 'en' && !language.wip
)
// Set flag that enables `localization_in_progress` message for WIP languages
set(
req.context,
'site.data.ui.header.notices.flags.localization_in_progress',
language.wip
)
const currentProduct = req.context.allProducts[req.context.currentProduct]
// if this is the homepage and no product is chosen yet, return early
if (!currentProduct) return next()
// Set flag that enables `product_in_progress` message for WIP products
set(
req.context,
'site.data.ui.header.notices.flags.product_in_progress',
currentProduct.wip
)
return next()
}