-
Notifications
You must be signed in to change notification settings - Fork 60.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33668 from github/repo-sync
Repo sync
- Loading branch information
Showing
4 changed files
with
31 additions
and
17 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters