(
ctx: Parameters<MiddlewareResponseHandler>[0] & { routePattern?: string },
)
| 419 | } |
| 420 | |
| 421 | function getParametrizedRoute( |
| 422 | ctx: Parameters<MiddlewareResponseHandler>[0] & { routePattern?: string }, |
| 423 | ): string | undefined { |
| 424 | try { |
| 425 | // `routePattern` is available after Astro 5 |
| 426 | const contextWithRoutePattern = ctx; |
| 427 | const rawRoutePattern = contextWithRoutePattern.routePattern; |
| 428 | |
| 429 | const routesFromManifest = |
| 430 | // @ts-expect-error Implicit any on Symbol.for (This is available in Astro 5) |
| 431 | // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access |
| 432 | ctx?.[Symbol.for('context.routes')]?.manifest?.routes ?? |
| 433 | // @ts-expect-error Implicit any on Symbol.for (This is available in Astro 6) |
| 434 | // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access |
| 435 | ctx?.[Symbol.for('astro.pipeline')]?.manifest?.routes; |
| 436 | |
| 437 | // oxlint-disable-next-line typescript/no-unsafe-member-access |
| 438 | const matchedRouteSegmentsFromManifest = routesFromManifest?.find( |
| 439 | (route: { routeData?: { route?: string } }) => route?.routeData?.route === rawRoutePattern, |
| 440 | // oxlint-disable-next-line typescript/no-unsafe-member-access |
| 441 | )?.routeData?.segments; |
| 442 | |
| 443 | return ( |
| 444 | // Astro v5+ - Joining the segments to get the correct casing of the parametrized route |
| 445 | (matchedRouteSegmentsFromManifest && joinRouteSegments(matchedRouteSegmentsFromManifest)) || |
| 446 | // Fallback (Astro v4 and earlier) |
| 447 | interpolateRouteFromUrlAndParams(ctx.url.pathname, ctx.params) |
| 448 | ); |
| 449 | } catch { |
| 450 | return undefined; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | function injectMetaTagsInResponse(originalResponse: Response, metaTagsStr: string): Response { |
| 455 | try { |
no test coverage detected