1
0
mirror of synced 2025-12-21 10:57:10 -05:00
Files
docs/middleware/products.js
Vanessa Yuen 3df90fc9b8 Hello git history spelunker!
Are you looking for something? Here is all of the GitHub Docs history in one single commit. Enjoy! 🎉
2020-09-27 14:10:11 +02:00

21 lines
807 B
JavaScript

const products = require('../lib/all-products')
const activeProducts = Object.values(products).filter(product => !product.wip)
const patterns = require('../lib/patterns')
module.exports = async (req, res, next) => {
req.context.activeProducts = activeProducts
if (req.path.match(patterns.admin)) {
// special case for enterprise URLs which take many forms...
req.context.currentProduct = products.enterpriseServer
} else if (req.context.page) {
// find current product by matching up starting file paths
req.context.currentProduct = Object.values(products).find(product => `content/${req.context.page.relativePath}`.startsWith(product.dir))
}
// fall back to the GitHub.com product
req.context.currentProduct = req.context.currentProduct || products.github
return next()
}