1
0
mirror of synced 2025-12-19 18:10:59 -05:00
Files
docs/src/frame/middleware/context/layout.js
2023-11-06 20:05:48 +00:00

21 lines
667 B
JavaScript

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
return next()
}