Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

current-product-tree.js 1.0 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  1. const path = require('path')
  2. const findPageInSiteTree = require('../../lib/find-page-in-site-tree')
  3. const removeFPTFromPath = require('../../lib/remove-fpt-from-path')
  4. // This module adds currentProductTree to the context object for use in layouts.
  5. module.exports = function currentProductTree (req, res, next) {
  6. if (!req.context.page) return next()
  7. if (req.context.page.documentType === 'homepage') return next()
  8. // We need this so we can fall back to English if localized pages are out of sync.
  9. req.context.currentEnglishTree = req.context.siteTree.en[req.context.currentVersion]
  10. const currentRootTree = req.context.siteTree[req.context.currentLanguage][req.context.currentVersion]
  11. const currentProductPath = removeFPTFromPath(path.posix.join('/', req.context.currentLanguage, req.context.currentVersion, req.context.currentProduct))
  12. const currentProductTree = findPageInSiteTree(currentRootTree, req.context.currentEnglishTree, currentProductPath)
  13. req.context.currentProductTree = currentProductTree
  14. return next()
  15. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...