@@ -3,29 +3,18 @@ const layouts = require('../../lib/layouts')
33module . exports = function layoutContext ( req , res , next ) {
44 if ( ! req . context . page ) return next ( )
55
6- let layoutName
7-
8- // If this is an index.md that is not the homepage and does not have a defined layout, use `generic-toc`.
9- const usesGenericToc = req . context . page . relativePath . endsWith ( 'index.md' ) &&
10- req . context . page . documentType !== 'homepage' &&
11- ! req . context . page . hidden
12-
13- if ( req . context . page . layout ) {
6+ const layoutOptsByType = {
147 // Layouts can be specified with a `layout` frontmatter value.
158 // Any invalid layout values will be caught by frontmatter schema validation.
16- layoutName = req . context . page . layout
17- } else if ( req . context . page . layout === false ) {
9+ string : req . context . page . layout ,
1810 // A `layout: false` value means use no layout.
19- layoutName = ''
20- } else if ( req . context . page . layout === undefined ) {
11+ boolean : '' ,
2112 // For all other files (like articles and the homepage), use the `default` layout.
22- if ( process . env . FEATURE_NEW_SITETREE ) {
23- layoutName = usesGenericToc ? 'generic-toc' : 'default'
24- } else {
25- layoutName = 'default'
26- }
13+ undefined : 'default'
2714 }
2815
16+ const layoutName = layoutOptsByType [ typeof ( req . context . page . layout ) ]
17+
2918 // Attach to the context object
3019 req . context . currentLayoutName = layoutName
3120 req . context . currentLayout = layouts [ layoutName ]
0 commit comments