List the operations of an OpenAPI tag page after its description (#4852)

This commit is contained in:
Nolann B.
2026-11-26 13:43:20 +01:00
committed by GitHub
parent 22f37783db
commit 43df49cdca
5 changed files with 54 additions and 12 deletions
@@ -0,0 +1,5 @@
---
"gitbook": patch
---
List the operations of an OpenAPI tag page after its description.
@@ -10,6 +10,11 @@
@apply m-0 px-2.5 py-1 h-6 text-[0.813rem];
}
/* The uppercase label renders 1px above center in page cards. */
.page-card-method .openapi-method-medium {
@apply pt-[5px] pb-[3px];
}
.toclink .openapi-method {
@apply text-[0.625rem] flex items-center justify-center;
}
@@ -24,6 +24,7 @@ import { getSpaceLanguage } from '@/intl/server';
import { t } from '@/intl/translate';
import type { GitBookSiteContext } from '@/lib/context';
import { hasAPIBlock, hasFullWidthBlock, hasTopLevelBlock, isNodeEmpty } from '@/lib/document';
import { isOpenAPITagPage } from '@/lib/openapi/computedSourceProps';
import type { AncestorRevisionPage } from '@/lib/pages';
import { tcls } from '@/lib/tailwind';
import { getPageRSSURL } from '@/routes/rss';
@@ -151,6 +152,9 @@ export async function PageBody(props: {
asEmbeddable={insightsDisplayContext === SiteInsightsDisplayContext.Embed}
/>
{content}
{isOpenAPITagPage(page) && document && !isNodeEmpty(document) ? (
<PageBodyBlankslate page={page} context={context} className="mt-8" />
) : null}
</div>
{page.layout.pagination && customization.pagination.enabled ? (
@@ -3,11 +3,13 @@ import {
RevisionPageType,
SiteInsightsLinkPosition,
} from '@gitbook/api';
import { OpenAPIMethodBadge } from '@gitbook/react-openapi';
import { CONTENT_STYLE } from '../layout';
import { PageIcon } from '../PageIcon';
import { Card } from '@/components/primitives';
import type { GitBookAnyContext } from '@/lib/context';
import { getOpenAPIOperationPageProps } from '@/lib/openapi/computedSourceProps';
import { resolveContentRef } from '@/lib/references';
import { tcls } from '@/lib/tailwind';
@@ -17,8 +19,9 @@ import { tcls } from '@/lib/tailwind';
export async function PageBodyBlankslate(props: {
page: RevisionPageDocument;
context: GitBookAnyContext;
className?: string;
}) {
const { page, context } = props;
const { page, context, className } = props;
const pages = page.pages.filter((child) =>
child.type === RevisionPageType.Document ? !child.hidden : true
@@ -62,11 +65,24 @@ export async function PageBodyBlankslate(props: {
pages: context.revision.pages,
page: child,
});
const openAPIOperation = getOpenAPIOperationPageProps(child);
return (
<Card
key={child.id}
title={child.linkTitle || child.title}
leadingIcon={icon}
leadingIcon={
openAPIOperation ? (
<span className="page-card-method min-w-13 flex shrink-0">
<OpenAPIMethodBadge
method={openAPIOperation.method}
short
className="w-full"
/>
</span>
) : (
icon
)
}
href={href}
/>
);
@@ -81,7 +97,8 @@ export async function PageBodyBlankslate(props: {
'gap-4',
'grid-cols-1',
'sm:grid-cols-2',
'md:layout-wide:grid-cols-3'
'md:layout-wide:grid-cols-3',
className
)}
>
{pageElements}
@@ -7,6 +7,25 @@ import type { ComputedContentSourceDocumentOpenAPI, RevisionPageDocument } from
export function getOpenAPIOperationPageProps(
page: RevisionPageDocument
): { method: string; deprecated: boolean } | undefined {
const props = getOpenAPIComputedProps(page);
if (props?.doc !== 'operation') {
return;
}
return {
method: props.method,
deprecated: props.deprecated === true,
};
}
/** Whether the page is an OpenAPI tag page in one-operation-per-page mode. */
export function isOpenAPITagPage(page: RevisionPageDocument): boolean {
return getOpenAPIComputedProps(page)?.doc === 'tag';
}
function getOpenAPIComputedProps(
page: RevisionPageDocument
): ComputedContentSourceDocumentOpenAPI['props'] | undefined {
if (!('computed' in page)) {
return;
}
@@ -16,13 +35,5 @@ export function getOpenAPIOperationPageProps(
return;
}
const { props } = source as ComputedContentSourceDocumentOpenAPI;
if (props.doc !== 'operation') {
return;
}
return {
method: props.method,
deprecated: props.deprecated === true,
};
return (source as ComputedContentSourceDocumentOpenAPI).props;
}