* Add new video properties frontmatter * Handle video links in the middleware * Video links don't have intros, authors, or full titles * Make videos available from context * Add default video heading * Add basic tests for videos * tmp videos test * Remove stray test debugging * more tmp videos testing * Add videos test fixture * Revert "more tmp videos testing" This reverts commit 382946a5603ff217014797f77f37216bb8bb6c9c. * Revert "tmp videos test" This reverts commit 8767d0eaf08bd4ca04e2dacd12d476a2506c0367.
34 lines
962 B
JavaScript
34 lines
962 B
JavaScript
import getLinkData from '../lib/get-link-data.js'
|
|
|
|
// this middleware adds properties to the context object
|
|
export default 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) {
|
|
if (key === 'videos') {
|
|
// Videos are external URLs so don't run through getLinkData, they're
|
|
// objects with title and href properties.
|
|
req.context.featuredLinks[key] = req.context.page.featuredLinks[key]
|
|
} else {
|
|
req.context.featuredLinks[key] = await getLinkData(
|
|
req.context.page.featuredLinks[key],
|
|
req.context,
|
|
{ title: true, intro: true, fullTitle: true }
|
|
)
|
|
}
|
|
}
|
|
|
|
return next()
|
|
}
|