Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repo sync #33543

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/frame/middleware/context/layout.js

This file was deleted.

24 changes: 24 additions & 0 deletions src/frame/middleware/context/layout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Response, NextFunction } from 'express'

import type { ExtendedRequest } from '@/types'

export default function layoutContext(req: ExtendedRequest, res: Response, next: NextFunction) {
if (!req.context) throw new Error('request is not contextualized')
if (!req.context.page) return next()

let layoutName = 'default'
if (req.context.page.layout) {
if (typeof req.context.page.layout === 'boolean') {
// A `layout: false` value means use no layout.
layoutName = ''
} else if (typeof req.context.page.layout === 'string') {
layoutName = req.context.page.layout
} else {
throw new Error(`Invalid layout value type: ${req.context.page.layout}`)
}
}

req.context.currentLayoutName = layoutName

return next()
}
2 changes: 1 addition & 1 deletion src/frame/middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import triggerError from '@/observability/middleware/trigger-error'
import secretScanning from '@/secret-scanning/middleware/secret-scanning'
import ghesReleaseNotes from '@/release-notes/middleware/ghes-release-notes'
import whatsNewChangelog from './context/whats-new-changelog'
import layout from './context/layout.js'
import layout from './context/layout'
import currentProductTree from './context/current-product-tree.js'
import genericToc from './context/generic-toc.js'
import breadcrumbs from './context/breadcrumbs.js'
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export type Context = {
autotitleLanguage?: string
latestPatch?: string
latestRelease?: string
currentLayoutName?: string
}

export type GHESRelease = {
Expand Down Expand Up @@ -185,6 +186,7 @@ export type Page = {
versions: FrontmatterVersions
applicableVersions: string[]
changelog?: ChangeLog
layout?: string | boolean
}

type ChangeLog = {
Expand Down
Loading