(req, res, next)
| 16 | } |
| 17 | |
| 18 | export default async function productExamples(req, res, next) { |
| 19 | if (!req.context.page) return next() |
| 20 | if (req.context.currentLayoutName !== 'product-landing') return next() |
| 21 | |
| 22 | const { currentProduct, currentLanguage } = req.context |
| 23 | if (currentProduct.includes('.')) |
| 24 | throw new Error(`currentProduct can not contain a . (${currentProduct})`) |
| 25 | |
| 26 | req.context.productCommunityExamples = getProductExampleData( |
| 27 | currentProduct, |
| 28 | 'community-examples', |
| 29 | currentLanguage |
| 30 | ) |
| 31 | req.context.productUserExamples = getProductExampleData( |
| 32 | currentProduct, |
| 33 | 'user-examples', |
| 34 | currentLanguage |
| 35 | ) |
| 36 | |
| 37 | const productCodeExamples = getProductExampleData( |
| 38 | currentProduct, |
| 39 | 'code-examples', |
| 40 | currentLanguage |
| 41 | ) |
| 42 | |
| 43 | // We currently only support versioning in code examples. |
| 44 | // TODO support versioning across all example types. |
| 45 | req.context.productCodeExamples = |
| 46 | productCodeExamples && |
| 47 | productCodeExamples.filter((example) => { |
| 48 | // If an example block does NOT contain the versions prop, assume it's available in all versions |
| 49 | return ( |
| 50 | !example.versions || |
| 51 | getApplicableVersions(example.versions).includes(req.context.currentVersion) |
| 52 | ) |
| 53 | }) |
| 54 | |
| 55 | return next() |
| 56 | } |
nothing calls this directly
no test coverage detected