(req, res, next)
| 6 | |
| 7 | // This module adds currentProductTree to the context object for use in layouts. |
| 8 | export default async function currentProductTree(req, res, next) { |
| 9 | if (!req.context.page) return next() |
| 10 | if (req.context.page.documentType === 'homepage') return next() |
| 11 | |
| 12 | // We need this so we can fall back to English if localized pages are out of sync. |
| 13 | req.context.currentEnglishTree = req.context.siteTree.en[req.context.currentVersion] |
| 14 | |
| 15 | const currentRootTree = |
| 16 | req.context.siteTree[req.context.currentLanguage][req.context.currentVersion] |
| 17 | const currentProductPath = removeFPTFromPath( |
| 18 | path.posix.join( |
| 19 | '/', |
| 20 | req.context.currentLanguage, |
| 21 | req.context.currentVersion, |
| 22 | req.context.currentProduct |
| 23 | ) |
| 24 | ) |
| 25 | req.context.currentProductTree = findPageInSiteTree( |
| 26 | currentRootTree, |
| 27 | req.context.currentEnglishTree, |
| 28 | currentProductPath |
| 29 | ) |
| 30 | |
| 31 | // First make a slim tree of just the 'href', 'title', 'shortTitle' |
| 32 | // 'documentType' and 'childPages' (which is recursive). |
| 33 | // This gets used for map topic and category pages. |
| 34 | req.context.currentProductTreeTitles = await getCurrentProductTreeTitles( |
| 35 | req.context.currentProductTree, |
| 36 | req.context |
| 37 | ) |
| 38 | // Now make an even slimmer version that excludes all hidden pages. |
| 39 | // This is i used for sidebars. |
| 40 | req.context.currentProductTreeTitlesExcludeHidden = excludeHidden( |
| 41 | req.context.currentProductTreeTitles |
| 42 | ) |
| 43 | |
| 44 | return next() |
| 45 | } |
| 46 | |
| 47 | // Return a nested object that contains the bits and pieces we need |
| 48 | // for the tree which is used for sidebars and listing |
nothing calls this directly
no test coverage detected