Skip to content

Commit

Permalink
support earlyAccessToc frontmatter
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahs committed Aug 22, 2022
1 parent ec302a6 commit f84ae78
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/frontmatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 8 additions & 3 deletions middleware/contextualizers/generic-toc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit f84ae78

Please sign in to comment.