1
0
mirror of synced 2025-12-21 19:06:49 -05:00
Files
docs/middleware/featured-links.js
James M. Greene c940dcd98b Middleware overhaul! (#18218)
* Middleware overhaul!

- Remove unnecessary 'async' keywords from middleware functions
- Ensure all middleware functions we create have names
- Wrap the method contents of all async middleware functions in a try-catch+next(error) pattern

* Use asyncMiddleware wrapper instead of try-catch+next(error) pattern

* Remove unnecessary try-catch+next(error) pattern from context middleware
2021-03-11 01:12:41 +00:00

18 lines
609 B
JavaScript

const getLinkData = require('../lib/get-link-data')
// this middleware adds properties to the context object
module.exports = async function featuredLinks (req, res, next) {
if (!req.context.page) return next()
if (!(req.context.page.relativePath.endsWith('index.md') || req.context.page.layout === 'product-landing')) return next()
if (!req.context.page.featuredLinks) return next()
req.context.featuredLinks = {}
for (const key in req.context.page.featuredLinks) {
req.context.featuredLinks[key] = await getLinkData(req.context.page.featuredLinks[key], req.context)
}
return next()
}