🍞 Add breadcrumbs to /article/meta endpoint (#54779)
This commit is contained in:
@@ -5,6 +5,8 @@ import type { ExtendedRequest, Page, Context, Permalink } from '@/types'
|
|||||||
import shortVersions from '@/versions/middleware/short-versions.js'
|
import shortVersions from '@/versions/middleware/short-versions.js'
|
||||||
import contextualize from '@/frame/middleware/context/context'
|
import contextualize from '@/frame/middleware/context/context'
|
||||||
import features from '@/versions/middleware/features.js'
|
import features from '@/versions/middleware/features.js'
|
||||||
|
import breadcrumbs from '@/frame/middleware/context/breadcrumbs.js'
|
||||||
|
import currentProductTree from '@/frame/middleware/context/current-product-tree.js'
|
||||||
import { readCompressedJsonFile } from '@/frame/lib/read-json-file.js'
|
import { readCompressedJsonFile } from '@/frame/lib/read-json-file.js'
|
||||||
|
|
||||||
// If you have pre-computed page info into a JSON file on disk, this is
|
// If you have pre-computed page info into a JSON file on disk, this is
|
||||||
@@ -29,6 +31,7 @@ export async function getPageInfo(page: Page, pathname: string) {
|
|||||||
await contextualize(renderingReq as ExtendedRequest, res as Response, next)
|
await contextualize(renderingReq as ExtendedRequest, res as Response, next)
|
||||||
await shortVersions(renderingReq as ExtendedRequest, res as Response, next)
|
await shortVersions(renderingReq as ExtendedRequest, res as Response, next)
|
||||||
renderingReq.context.page = page
|
renderingReq.context.page = page
|
||||||
|
await currentProductTree(renderingReq as ExtendedRequest, res as Response, next)
|
||||||
features(renderingReq as ExtendedRequest, res as Response, next)
|
features(renderingReq as ExtendedRequest, res as Response, next)
|
||||||
const context = renderingReq.context
|
const context = renderingReq.context
|
||||||
|
|
||||||
@@ -50,7 +53,12 @@ export async function getPageInfo(page: Page, pathname: string) {
|
|||||||
}
|
}
|
||||||
const product = productPage ? await getProductPageInfo(productPage, context) : ''
|
const product = productPage ? await getProductPageInfo(productPage, context) : ''
|
||||||
|
|
||||||
return { title, intro, product }
|
// Call breadcrumbs middleware to populate renderingReq.context.breadcrumbs
|
||||||
|
breadcrumbs(renderingReq as ExtendedRequest, res as Response, next)
|
||||||
|
|
||||||
|
const { breadcrumbs: pageBreadcrumbs } = renderingReq.context
|
||||||
|
|
||||||
|
return { title, intro, product, breadcrumbs: pageBreadcrumbs }
|
||||||
}
|
}
|
||||||
|
|
||||||
const _productPageCache: {
|
const _productPageCache: {
|
||||||
|
|||||||
@@ -9,11 +9,11 @@
|
|||||||
import type { ExtendedRequest } from '@/types.js'
|
import type { ExtendedRequest } from '@/types.js'
|
||||||
import type { Response, NextFunction } from 'express'
|
import type { Response, NextFunction } from 'express'
|
||||||
|
|
||||||
export default function shortVersions(
|
export default async function shortVersions(
|
||||||
req: ExtendedRequest,
|
req: ExtendedRequest,
|
||||||
res: Response | null,
|
res: Response | null,
|
||||||
next: NextFunction,
|
next: NextFunction,
|
||||||
): void {
|
): Promise<void> {
|
||||||
if (!req.context) throw new Error('No context on request')
|
if (!req.context) throw new Error('No context on request')
|
||||||
const { currentVersion, currentVersionObj } = req.context
|
const { currentVersion, currentVersionObj } = req.context
|
||||||
if (!currentVersionObj) {
|
if (!currentVersionObj) {
|
||||||
|
|||||||
Reference in New Issue
Block a user