forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathearly-access-links.js
27 lines (24 loc) · 914 Bytes
/
early-access-links.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
module.exports = function earlyAccessContext (req, res, next) {
if (process.env.NODE_ENV === 'production') {
return next(404)
}
// Get a list of all hidden pages per version
const earlyAccessPageLinks = req.context.pages
.filter(page => page.hidden)
// Do not include early access landing page
.filter(page => page.relativePath !== 'early-access/index.md')
// Create Markdown links
.map(page => {
return page.permalinks.map(permalink => `- [${permalink.title}](${permalink.href})`)
})
.flat()
// Get links for the current version
.filter(link => link.includes(req.context.currentVersion))
.sort()
// Add to the rendering context
// This is only used in the separate EA repo on local development
req.context.earlyAccessPageLinks = earlyAccessPageLinks.length
? earlyAccessPageLinks.join('\n')
: '_None for this version!_'
return next()
}