From f84ae785fc3b56d05480d7d0011c64f784b19a84 Mon Sep 17 00:00:00 2001 From: Sarah Schneider Date: Mon, 22 Aug 2022 17:39:54 -0400 Subject: [PATCH] support earlyAccessToc frontmatter --- lib/frontmatter.js | 5 +++++ middleware/contextualizers/generic-toc.js | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/frontmatter.js b/lib/frontmatter.js index 8dd1df3ccdcc..86d6ce1e5025 100644 --- a/lib/frontmatter.js +++ b/lib/frontmatter.js @@ -62,6 +62,11 @@ export const schema = { noEarlyAccessBanner: { type: 'boolean', }, + // specify whether an Early Acccess product should have a table of contents + // (EA categories and map topics have them by default, but products don't) + earlyAccessToc: { + type: 'boolean', + }, layout: { type: ['string', 'boolean'], enum: layoutNames, diff --git a/middleware/contextualizers/generic-toc.js b/middleware/contextualizers/generic-toc.js index 595e04f1b801..fb64cbfd2646 100644 --- a/middleware/contextualizers/generic-toc.js +++ b/middleware/contextualizers/generic-toc.js @@ -24,8 +24,12 @@ export default async function genericToc(req, res, next) { mapTopic: 'flat', } + // Frontmatter can optionally be set on an Early Access product to show hidden child items. + // If so, this is a special case where we want to override the flat tocType and use a nested type. + const earlyAccessToc = req.context.page.earlyAccessToc + // Find the current TOC type based on the current document type. - const currentTocType = tocTypes[req.context.page.documentType] + const currentTocType = earlyAccessToc ? 'nested' : tocTypes[req.context.page.documentType] // Find the part of the site tree that corresponds to the current path. const treePage = findPageInSiteTree( @@ -34,7 +38,7 @@ export default async function genericToc(req, res, next) { req.pagePath ) - // Only include hidden child items on a TOC page if it's an Early Access category or + // By default, only include hidden child items on a TOC page if it's an Early Access category or // map topic page, not a product or 'articles' fake cagegory page (e.g., /early-access/github/articles). // This is because we don't want entire EA product TOCs to be publicly browseable, but anything at the category // or below level is fair game because that content is scoped to specific features. @@ -43,7 +47,8 @@ export default async function genericToc(req, res, next) { const isEarlyAccess = req.context.currentPath.includes('/early-access/') const isArticlesCategory = req.context.currentPath.endsWith('/articles') - req.context.showHiddenTocItems = isCategoryOrMapTopic && isEarlyAccess && !isArticlesCategory + req.context.showHiddenTocItems = + earlyAccessToc || (isCategoryOrMapTopic && isEarlyAccess && !isArticlesCategory) // Conditionally run getTocItems() recursively. let isRecursive