| 1 | export default function layoutContext(req, res, next) { |
| 2 | if (!req.context.page) return next() |
| 3 | |
| 4 | const layoutOptsByType = { |
| 5 | // Layouts can be specified with a `layout` frontmatter value. |
| 6 | // Any invalid layout values will be caught by frontmatter schema validation. |
| 7 | string: req.context.page.layout, |
| 8 | // A `layout: false` value means use no layout. |
| 9 | boolean: '', |
| 10 | // For all other files (like articles and the homepage), use the `default` layout. |
| 11 | undefined: 'default', |
| 12 | } |
| 13 | |
| 14 | const layoutName = layoutOptsByType[typeof req.context.page.layout] |
| 15 | |
| 16 | // Attach to the context object |
| 17 | req.context.currentLayoutName = layoutName |
| 18 | |
| 19 | return next() |
| 20 | } |