MCPcopy Create free account
hub / github.com/github/docs / layoutContext

Function layoutContext

middleware/contextualizers/layout.js:1–20  ·  view source on GitHub ↗
(req, res, next)

Source from the content-addressed store, hash-verified

1export 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}

Callers

nothing calls this directly

Calls 1

nextFunction · 0.50

Tested by

no test coverage detected