1
0
mirror of synced 2025-12-25 02:17:36 -05:00

add feature flagged middleware

This commit is contained in:
Sarah Schneider
2021-04-15 14:46:16 -04:00
parent 2f7bfc15bb
commit d1524b16a5
4 changed files with 28 additions and 8 deletions

View File

@@ -7,7 +7,7 @@ module.exports = function earlyAccessContext (req, res, next) {
// 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 !== 'early-access/index.md')
.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

View File

@@ -5,16 +5,25 @@ module.exports = function layoutContext (req, res, next) {
let layoutName
// If this is an index.md that is not the homepage and does not have a defined layout, use `generic-toc`.
const usesGenericToc = req.context.page.relativePath.endsWith('index.md') &&
req.context.page.documentType !== 'homepage' &&
!req.context.page.hidden
if (req.context.page.layout) {
// Layouts can be specified with a `layout` frontmatter value.
// Any invalid layout values will be caught by frontmatter schema validation.
layoutName = req.context.page.layout
// A `layout: false` value means use no layout.
} else if (req.context.page.layout === false) {
// A `layout: false` value means use no layout.
layoutName = ''
// If undefined, use either the default layout or the generic-toc layout.
} else if (req.context.page.layout === undefined) {
layoutName = 'default'
// For all other files (like articles and the homepage), use the `default` layout.
if (process.env.FEATURE_NEW_SITETREE) {
layoutName = usesGenericToc ? 'generic-toc' : 'default'
} else {
layoutName = 'default'
}
}
// Attach to the context object