1
0
mirror of synced 2026-01-09 06:03:09 -05:00
Files
docs/middleware/contextualizers/layout.js
Kevin Heis 8a56437c93 Pretty format (#20352)
* Update prettier flow to include JS

* Run prettier

* ...run prettier
2021-07-14 14:35:01 -07:00

24 lines
761 B
JavaScript

import layouts from '../../lib/layouts.js'
export default function layoutContext(req, res, next) {
if (!req.context.page) return next()
const layoutOptsByType = {
// Layouts can be specified with a `layout` frontmatter value.
// Any invalid layout values will be caught by frontmatter schema validation.
string: req.context.page.layout,
// A `layout: false` value means use no layout.
boolean: '',
// For all other files (like articles and the homepage), use the `default` layout.
undefined: 'default',
}
const layoutName = layoutOptsByType[typeof req.context.page.layout]
// Attach to the context object
req.context.currentLayoutName = layoutName
req.context.currentLayout = layouts[layoutName]
return next()
}