1
0
mirror of synced 2026-01-09 06:03:09 -05:00

Merge pull request #33668 from github/repo-sync

Repo sync
This commit is contained in:
docs-bot
2024-06-24 06:36:25 -07:00
committed by GitHub
4 changed files with 31 additions and 17 deletions

View File

@@ -1,16 +0,0 @@
import { renderContent } from '#src/content-render/index.js'
export default async function renderProductName(req, res, next) {
const { productMap, currentProduct } = req.context
const productObject = productMap[currentProduct]
if (!productObject) {
// If the "currentProduct" isn't recognized, there's no point trying
// to render its name. Skip this middleware.
return next()
}
req.context.currentProductName = await renderContent(productObject.name, req.context, {
textOnly: true,
cache: true,
})
return next()
}

View File

@@ -0,0 +1,29 @@
import type { Response, NextFunction } from 'express'
import type { ExtendedRequest } from '@/types'
import { renderContent } from '@/content-render/index.js'
export default async function renderProductName(
req: ExtendedRequest,
res: Response,
next: NextFunction,
) {
if (!req.context) throw new Error('request is not contextualized')
const { productMap, currentProduct } = req.context
if (!productMap) throw new Error('request is not contextualized')
// `currentProduct` might be an empty string, which is a valid value.
if (currentProduct === undefined) throw new Error('currentProduct is not contextualized')
const productObject = productMap[currentProduct]
if (!productObject) {
// If the "currentProduct" isn't recognized, there's no point trying
// to render its name. Skip this middleware.
return next()
}
req.context.currentProductName = await renderContent(productObject.name, req.context, {
textOnly: true,
cache: true,
})
return next()
}

View File

@@ -44,7 +44,7 @@ import currentProductTree from './context/current-product-tree'
import genericToc from './context/generic-toc'
import breadcrumbs from './context/breadcrumbs'
import glossaries from './context/glossaries'
import renderProductName from './context/render-product-name.js'
import renderProductName from './context/render-product-name'
import features from '@/versions/middleware/features.js'
import productExamples from './context/product-examples.js'
import productGroups from './context/product-groups.js'

View File

@@ -92,6 +92,7 @@ export type Context = {
genericTocNested?: ToC[]
breadcrumbs?: Breadcrumb[]
glossaries?: Glossary[]
currentProductName?: string
}
export type Glossary = {