@@ -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()
|
||||
}
|
||||
29
src/frame/middleware/context/render-product-name.ts
Normal file
29
src/frame/middleware/context/render-product-name.ts
Normal 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()
|
||||
}
|
||||
@@ -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'
|
||||
|
||||
@@ -92,6 +92,7 @@ export type Context = {
|
||||
genericTocNested?: ToC[]
|
||||
breadcrumbs?: Breadcrumb[]
|
||||
glossaries?: Glossary[]
|
||||
currentProductName?: string
|
||||
}
|
||||
|
||||
export type Glossary = {
|
||||
|
||||
Reference in New Issue
Block a user