@@ -86,6 +86,7 @@ type EnterpriseServerReleases = {
86
86
}
87
87
88
88
export type MainContextT = {
89
+ allVersions : Record < string , VersionItem >
89
90
breadcrumbs : {
90
91
product : BreadcrumbT
91
92
category ?: BreadcrumbT
@@ -96,21 +97,21 @@ export type MainContextT = {
96
97
name : string
97
98
href : string
98
99
}
100
+ currentCategory ?: string
101
+ currentPathWithoutLanguage : string
99
102
currentProduct ?: ProductT
100
103
currentProductName : string
104
+ currentProductTree ?: ProductTreeNode | null
101
105
currentLayoutName ?: string
102
- isHomepageVersion : boolean
106
+ currentVersion ?: string
103
107
data : DataT
104
- error : string
105
- currentCategory ?: string
106
- relativePath ?: string
107
108
enterpriseServerReleases : EnterpriseServerReleases
108
- currentPathWithoutLanguage : string
109
- allVersions : Record < string , VersionItem >
110
- currentVersion ?: string
111
- currentProductTree ?: ProductTreeNode | null
112
- sidebarTree ?: ProductTreeNode | null
109
+ enterpriseServerVersions : Array < string >
110
+ error : string
113
111
featureFlags : FeatureFlags
112
+ fullUrl : string
113
+ isHomepageVersion : boolean
114
+ nonEnterpriseDefaultVersion : string
114
115
page : {
115
116
documentType : string
116
117
type ?: string
@@ -122,13 +123,10 @@ export type MainContextT = {
122
123
noEarlyAccessBanner : boolean
123
124
applicableVersions : string [ ]
124
125
} | null
125
-
126
- enterpriseServerVersions : Array < string >
127
-
128
- nonEnterpriseDefaultVersion : string
129
-
126
+ relativePath ?: string
127
+ sidebarTree ?: ProductTreeNode | null
130
128
status : number
131
- fullUrl : string
129
+ xHost ? : string
132
130
}
133
131
134
132
// Write down the namespaces from `data/ui.yml` that are used on all pages,
@@ -231,58 +229,53 @@ export const getMainContext = async (req: any, res: any): Promise<MainContextT>
231
229
const currentProductName : string = req . context . currentProductName || ''
232
230
233
231
const props : MainContextT = {
232
+ allVersions : minimalAllVersions ( req . context . allVersions ) ,
234
233
breadcrumbs : req . context . breadcrumbs || { } ,
235
234
communityRedirect : req . context . page ?. communityRedirect || { } ,
235
+ currentCategory : req . context . currentCategory || '' ,
236
+ currentLayoutName : req . context . currentLayoutName || null ,
237
+ currentPathWithoutLanguage : req . context . currentPathWithoutLanguage ,
236
238
currentProduct,
237
239
currentProductName,
238
- isHomepageVersion : req . context . page ?. documentType === 'homepage' ,
239
- error : req . context . error ? req . context . error . toString ( ) : '' ,
240
+ // This is a slimmed down version of `req.context.currentProductTree`
241
+ // that only has the minimal titles stuff needed for sidebars and
242
+ // any page that is hidden is omitted.
243
+ // However, it's not needed on most pages. For example, on article pages,
244
+ // you don't need it. It's similar to the minimal product tree but,
245
+ // has the full length titles and not just the short titles.
246
+ currentProductTree :
247
+ ( includeFullProductTree && req . context . currentProductTreeTitlesExcludeHidden ) || null ,
248
+ currentVersion : req . context . currentVersion ,
240
249
data : {
241
250
ui,
242
-
243
251
reusables,
244
-
245
252
variables : {
246
253
release_candidate : {
247
254
version : releaseCandidateVersion ,
248
255
} ,
249
256
} ,
250
257
} ,
251
- currentCategory : req . context . currentCategory || '' ,
252
- currentPathWithoutLanguage : req . context . currentPathWithoutLanguage ,
253
- page : pageInfo ,
254
258
enterpriseServerReleases : pick ( req . context . enterpriseServerReleases , [
255
259
'isOldestReleaseDeprecated' ,
256
260
'oldestSupported' ,
257
261
'nextDeprecationDate' ,
258
262
'supported' ,
259
263
] ) ,
260
264
enterpriseServerVersions : req . context . enterpriseServerVersions ,
261
- allVersions : minimalAllVersions ( req . context . allVersions ) ,
262
- currentVersion : req . context . currentVersion ,
263
- // This is a slimmed down version of `req.context.currentProductTree`
264
- // that only has the minimal titles stuff needed for sidebars and
265
- // any page that is hidden is omitted.
266
- // However, it's not needed on most pages. For example, on article pages,
267
- // you don't need it. It's similar to the minimal product tree but,
268
- // has the full length titles and not just the short titles.
269
- currentProductTree :
270
- ( includeFullProductTree && req . context . currentProductTreeTitlesExcludeHidden ) || null ,
265
+ error : req . context . error ? req . context . error . toString ( ) : '' ,
266
+ featureFlags : { } ,
267
+ fullUrl : req . protocol + '://' + req . hostname + req . originalUrl , // does not include port for localhost
268
+ isHomepageVersion : req . context . page ?. documentType === 'homepage' ,
269
+ nonEnterpriseDefaultVersion : req . context . nonEnterpriseDefaultVersion ,
270
+ page : pageInfo ,
271
+ relativePath : req . context . page ?. relativePath || null ,
271
272
// The minimal product tree is needed on all pages that depend on
272
273
// the product sidebar or the rest sidebar.
273
274
sidebarTree : ( includeSidebarTree && req . context . sidebarTree ) || null ,
274
- featureFlags : { } ,
275
- nonEnterpriseDefaultVersion : req . context . nonEnterpriseDefaultVersion ,
276
275
status : res . statusCode ,
277
- fullUrl : req . protocol + '://' + req . hostname + req . originalUrl , // does not include port for localhost
276
+ xHost : req . get ( 'x-host' ) || '' ,
278
277
}
279
278
280
- if ( req . context . currentLayoutName ) {
281
- props . currentLayoutName = req . context . currentLayoutName
282
- }
283
- if ( req . context . page ?. relativePath ) {
284
- props . relativePath = req . context . page . relativePath
285
- }
286
279
return props
287
280
}
288
281
0 commit comments