forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayout.js
23 lines (18 loc) · 767 Bytes
/
layout.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const layouts = require('../../lib/layouts')
module.exports = 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()
}