From 2f66d02034bc2404a738d5e71de15882c1b359bd Mon Sep 17 00:00:00 2001 From: Jefferson Rafael Kozerski Date: Fri, 22 Mar 2024 11:13:04 -0300 Subject: [PATCH] Refactor title generation in Route component and add tag to PathItemOperation --- .../components/Route.astro | 13 +++++++++++-- .../starlight-openapi-rapidoc/libs/operation.ts | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/starlight-openapi-rapidoc/components/Route.astro b/packages/starlight-openapi-rapidoc/components/Route.astro index a512157..251ff7b 100644 --- a/packages/starlight-openapi-rapidoc/components/Route.astro +++ b/packages/starlight-openapi-rapidoc/components/Route.astro @@ -62,8 +62,17 @@ if (schema.documentDereferenced !== true) { } const isOverview = type === 'overview' - -const title = `${schema.config.label} - ${isOverview ? 'Overview' : Astro.props.operation.title}` +const SEPARATOR = '/' +let title = `${schema.config.label}` + +if (isOverview) { + title = `${title} ${SEPARATOR} Overview` +} else { + if (Astro.props.operation?.tag) { + title = `${title} ${SEPARATOR} ${Astro.props.operation.tag}` + } + title = `${title} ${SEPARATOR} ${Astro.props.operation.title}` +} const frontmatter = { ...Astro.props?.frontmatter, diff --git a/packages/starlight-openapi-rapidoc/libs/operation.ts b/packages/starlight-openapi-rapidoc/libs/operation.ts index 074633c..a5a89c6 100644 --- a/packages/starlight-openapi-rapidoc/libs/operation.ts +++ b/packages/starlight-openapi-rapidoc/libs/operation.ts @@ -35,6 +35,7 @@ export function getOperationsByTag(document: Schema['document']) { pathItem, slug: `operations/${slug(operationId)}`, title: (summary ?? operationId) || pathItemPath || `${description}`.slice(100) || '', + tag, }) operationsByTag.set(tag, operations) @@ -146,6 +147,7 @@ export interface PathItemOperation { pathItem: PathItem slug: string title: string + tag?: string } export type Operation = OpenAPI.Operation