(req, res, next)
| 3 | |
| 4 | // this middleware adds properties to the context object |
| 5 | export default async function featuredLinks(req, res, next) { |
| 6 | if (!req.context.page) return next() |
| 7 | |
| 8 | if ( |
| 9 | !( |
| 10 | req.context.page.relativePath.endsWith('index.md') || |
| 11 | req.context.page.layout === 'product-landing' |
| 12 | ) |
| 13 | ) |
| 14 | return next() |
| 15 | |
| 16 | if (!req.context.page.featuredLinks) return next() |
| 17 | |
| 18 | req.context.featuredLinks = {} |
| 19 | for (const key in req.context.page.featuredLinks) { |
| 20 | if (key === 'videos') { |
| 21 | // Videos are external URLs so don't run through getLinkData, they're |
| 22 | // objects with title and href properties. |
| 23 | // When the title contains Liquid versioning tags, it will be either |
| 24 | // the provided string title or an empty title. When the title is empty, |
| 25 | // it indicates the video is not versioned for the current version |
| 26 | req.context.featuredLinks[key] = [] |
| 27 | for (let i = 0; i < req.context.page.featuredLinks[key].length; i++) { |
| 28 | const title = await renderContent( |
| 29 | req.context.page.featuredLinks[key][i].title, |
| 30 | req.context, |
| 31 | { |
| 32 | textOnly: true, |
| 33 | } |
| 34 | ) |
| 35 | const item = { title, href: req.context.page.featuredLinks[key][i].href } |
| 36 | |
| 37 | if (item.title) { |
| 38 | req.context.featuredLinks[key].push(item) |
| 39 | } |
| 40 | } |
| 41 | } else { |
| 42 | req.context.featuredLinks[key] = await getLinkData( |
| 43 | req.context.page.featuredLinks[key], |
| 44 | req.context, |
| 45 | { title: true, intro: true, fullTitle: true } |
| 46 | ) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | return next() |
| 51 | } |
nothing calls this directly
no test coverage detected