1
0
mirror of synced 2025-12-22 03:16:52 -05:00
Files
docs/middleware/contextualizers/early-access-links.js
Peter Bengtsson 68400c52a8 don't test external early-access in unit tests (#26612)
* don't test external early-access in unit tests

* make the rendering tests less weird && gg push
2022-04-04 21:00:14 +00:00

34 lines
1011 B
JavaScript

import { uniq } from 'lodash-es'
export default function earlyAccessContext(req, res, next) {
if (process.env.NODE_ENV !== 'development') {
return next(404)
}
// Get a list of all hidden pages per version
const earlyAccessPageLinks = uniq(
Object.values(req.context.pages)
.filter(
(page) =>
page.hidden &&
page.relativePath.startsWith('early-access') &&
!page.relativePath.endsWith('index.md')
)
.map((page) => page.permalinks)
.flat()
)
// Get links for the current version
.filter((permalink) => req.context.currentVersion === permalink.pageVersion)
.sort()
// Create Markdown links
.map((permalink) => `- [${permalink.title}](${permalink.href})`)
// 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()
}