File tree Expand file tree Collapse file tree 4 files changed +27
-21
lines changed Expand file tree Collapse file tree 4 files changed +27
-21
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import type { Response , NextFunction } from 'express'
2
+
3
+ import type { ExtendedRequest } from '@/types'
4
+
5
+ export default function layoutContext ( req : ExtendedRequest , res : Response , next : NextFunction ) {
6
+ if ( ! req . context ) throw new Error ( 'request is not contextualized' )
7
+ if ( ! req . context . page ) return next ( )
8
+
9
+ let layoutName = 'default'
10
+ if ( req . context . page . layout ) {
11
+ if ( typeof req . context . page . layout === 'boolean' ) {
12
+ // A `layout: false` value means use no layout.
13
+ layoutName = ''
14
+ } else if ( typeof req . context . page . layout === 'string' ) {
15
+ layoutName = req . context . page . layout
16
+ } else {
17
+ throw new Error ( `Invalid layout value type: ${ req . context . page . layout } ` )
18
+ }
19
+ }
20
+
21
+ req . context . currentLayoutName = layoutName
22
+
23
+ return next ( )
24
+ }
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ import triggerError from '@/observability/middleware/trigger-error'
39
39
import secretScanning from '@/secret-scanning/middleware/secret-scanning'
40
40
import ghesReleaseNotes from '@/release-notes/middleware/ghes-release-notes'
41
41
import whatsNewChangelog from './context/whats-new-changelog'
42
- import layout from './context/layout.js '
42
+ import layout from './context/layout'
43
43
import currentProductTree from './context/current-product-tree.js'
44
44
import genericToc from './context/generic-toc.js'
45
45
import breadcrumbs from './context/breadcrumbs.js'
Original file line number Diff line number Diff line change @@ -82,6 +82,7 @@ export type Context = {
82
82
autotitleLanguage ?: string
83
83
latestPatch ?: string
84
84
latestRelease ?: string
85
+ currentLayoutName ?: string
85
86
}
86
87
87
88
export type GHESRelease = {
@@ -185,6 +186,7 @@ export type Page = {
185
186
versions : FrontmatterVersions
186
187
applicableVersions : string [ ]
187
188
changelog ?: ChangeLog
189
+ layout ?: string | boolean
188
190
}
189
191
190
192
type ChangeLog = {
You can’t perform that action at this time.
0 commit comments