1
0
mirror of synced 2025-12-22 03:16:52 -05:00
Files
docs/middleware/contextualizers/current-product-tree.js
Sarah Schneider 2a72558592 lint
2021-05-19 12:05:05 -04:00

15 lines
564 B
JavaScript

module.exports = function currentProductTree (req, res, next) {
if (!req.context.page) return next()
if (req.context.page.documentType === 'homepage') return next()
const currentSiteTree = req.context.siteTree[req.context.currentLanguage][req.context.currentVersion]
req.context.currentProductTree = currentSiteTree.childPages.find(page => {
// Find a product path that matches at least an initial part of the current path
const regex = new RegExp(`^${page.href}($|/)`, 'm')
return regex.test(req.context.currentPath)
})
return next()
}