Skip to content

Commit 0510b6f

Browse files
authored
Add section description (#2814)
1 parent 92b7668 commit 0510b6f

File tree

10 files changed

+64
-40
lines changed

10 files changed

+64
-40
lines changed

.changeset/healthy-grapes-refuse.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'gitbook': patch
3+
---
4+
5+
Add section description to SectionGroupTile

bun.lock

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"name": "gitbook",
3434
"version": "0.5.0",
3535
"dependencies": {
36-
"@gitbook/api": "^0.90.0",
36+
"@gitbook/api": "^0.92.0",
3737
"@gitbook/cache-do": "workspace:*",
3838
"@gitbook/emoji-codepoints": "workspace:*",
3939
"@gitbook/icons": "workspace:*",
@@ -4615,6 +4615,8 @@
46154615

46164616
"gaxios/https-proxy-agent": ["[email protected]", "", { "dependencies": { "agent-base": "6", "debug": "4" } }, "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA=="],
46174617

4618+
"gitbook/@gitbook/api": ["@gitbook/[email protected]", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-fZHECoW8k6oqMK66QlT0W8EMWQaSEULzqgkI+tZ/gmA/n7Ek5nQwT1TUenEq4JtXPtbKSYG7du0b1AfiOR+FOA=="],
4619+
46184620
"gitbook-v2/next": ["[email protected]", "", { "dependencies": { "@next/env": "15.2.0-canary.33", "@swc/counter": "0.1.3", "@swc/helpers": "0.5.15", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001579", "postcss": "8.4.31", "styled-jsx": "5.1.6" }, "optionalDependencies": { "@next/swc-darwin-arm64": "15.2.0-canary.33", "@next/swc-darwin-x64": "15.2.0-canary.33", "@next/swc-linux-arm64-gnu": "15.2.0-canary.33", "@next/swc-linux-arm64-musl": "15.2.0-canary.33", "@next/swc-linux-x64-gnu": "15.2.0-canary.33", "@next/swc-linux-x64-musl": "15.2.0-canary.33", "@next/swc-win32-arm64-msvc": "15.2.0-canary.33", "@next/swc-win32-x64-msvc": "15.2.0-canary.33", "sharp": "^0.33.5" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", "@playwright/test": "^1.41.2", "babel-plugin-react-compiler": "*", "react": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "react-dom": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "sass": "^1.3.0" }, "optionalPeers": ["@opentelemetry/api", "@playwright/test", "babel-plugin-react-compiler", "sass"], "bin": { "next": "dist/bin/next" } }, "sha512-WF8QLeYkakuYwksdWY/F+Bi8tNJfIbiSYk9hCmldn9sNp1lU3lqI1hrW1ynbcMSaXC+qQEr7yol2OdvVZ4nZYQ=="],
46194621

46204622
"glob/minimatch": ["[email protected]", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ=="],

packages/gitbook/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"clean": "rm -rf ./.next && rm -rf ./public/~gitbook/static"
1717
},
1818
"dependencies": {
19-
"@gitbook/api": "^0.90.0",
19+
"@gitbook/api": "^0.92.0",
2020
"@gitbook/cache-do": "workspace:*",
2121
"@gitbook/emoji-codepoints": "workspace:*",
2222
"@gitbook/icons": "workspace:*",

packages/gitbook/src/app/middleware/(site)/(core)/llms.txt/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SiteSection, SiteSpace, SiteStructure } from '@gitbook/api';
22
import assertNever from 'assert-never';
3-
import { Heading, ListItem, Paragraph, Root, RootContent } from 'mdast';
3+
import { ListItem, Paragraph, Root, RootContent } from 'mdast';
44
import { toMarkdown } from 'mdast-util-to-markdown';
55
import { NextRequest } from 'next/server';
66

@@ -10,6 +10,7 @@ import { getPagePath } from '@/lib/pages';
1010
import { joinPath } from '@/lib/paths';
1111
import { checkIsRootPointer, getSiteContentPointer } from '@/lib/pointer';
1212
import { getIndexablePages } from '@/lib/sitemap';
13+
import { getSiteStructureSections } from '@/lib/utils';
1314

1415
export const runtime = 'edge';
1516

@@ -59,7 +60,7 @@ export async function GET(req: NextRequest) {
5960
async function getNodesFromSiteStructure(siteStructure: SiteStructure): Promise<RootContent[]> {
6061
switch (siteStructure.type) {
6162
case 'sections':
62-
return getNodesFromSections(siteStructure.structure);
63+
return getNodesFromSections(getSiteStructureSections(siteStructure));
6364
case 'siteSpaces':
6465
return getNodesFromSiteSpaces(siteStructure.structure, { heading: true });
6566
default:

packages/gitbook/src/app/middleware/(site)/(core)/sitemap.xml/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { SiteSection, SiteSpace, SiteStructure } from '@gitbook/api';
22
import assertNever from 'assert-never';
33
import jsontoxml from 'jsontoxml';
44

5-
import { getPublishedContentSite, SiteContentPointer } from '@/lib/api';
6-
import { getAbsoluteHref } from '@/lib/links';
5+
import { getPublishedContentSite } from '@/lib/api';
76
import { joinPath } from '@/lib/paths';
87
import { checkIsRootPointer, getSiteContentPointer } from '@/lib/pointer';
98
import { filterOutNullable } from '@/lib/typescript';
9+
import { getSiteStructureSections } from '@/lib/utils';
1010

1111
export const runtime = 'edge';
1212

@@ -62,7 +62,7 @@ export async function GET() {
6262
async function getUrlsFromSiteStructure(siteStructure: SiteStructure): Promise<string[]> {
6363
switch (siteStructure.type) {
6464
case 'sections':
65-
return getUrlsFromSiteSections(siteStructure.structure);
65+
return getUrlsFromSiteSections(getSiteStructureSections(siteStructure));
6666
case 'siteSpaces':
6767
return getUrlsFromSiteSpaces(siteStructure.structure);
6868
default:

packages/gitbook/src/components/Search/server-actions.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use server';
22

33
import { RevisionPage, SearchAIAnswer, SearchPageResult, SiteSpace, Space } from '@gitbook/api';
4-
import { captureException } from '@sentry/nextjs';
54
import * as React from 'react';
65
import { assert } from 'ts-essentials';
76

@@ -10,6 +9,7 @@ import * as api from '@/lib/api';
109
import { getAbsoluteHref, getPageHref } from '@/lib/links';
1110
import { resolvePageId } from '@/lib/pages';
1211
import { filterOutNullable } from '@/lib/typescript';
12+
import { getSiteStructureSections } from '@/lib/utils';
1313

1414
import { DocumentView } from '../DocumentView';
1515

@@ -78,7 +78,7 @@ async function searchSiteContent(args: {
7878
const siteSpaces = siteStructure
7979
? siteStructure.type === 'siteSpaces'
8080
? siteStructure.structure
81-
: siteStructure.structure.reduce<SiteSpace[]>((prev, section) => {
81+
: getSiteStructureSections(siteStructure).reduce<SiteSpace[]>((prev, section) => {
8282
const sectionSiteSpaces = section.siteSpaces.map((siteSpace) => ({
8383
...siteSpace,
8484
space: {

packages/gitbook/src/components/SiteSections/SiteSectionTabs.tsx

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,30 +70,34 @@ export function SiteSectionTabs(props: { sections: SectionsList }) {
7070
return (
7171
<NavigationMenu.Item key={id} value={id}>
7272
{isGroup ? (
73-
<>
74-
<NavigationMenu.Trigger
75-
ref={(node) =>
76-
onNodeUpdate(
77-
node,
78-
id,
79-
sectionOrGroup.sections.length,
80-
)
81-
}
82-
asChild
83-
>
84-
<SectionGroupTab
85-
isActive={isActive}
86-
title={title}
87-
icon={icon as IconName}
88-
/>
89-
</NavigationMenu.Trigger>
90-
<NavigationMenu.Content className="absolute z-20 left-0 top-0 w-full md:w-max data-[motion=from-end]:motion-safe:animate-enterFromRight data-[motion=from-start]:motion-safe:animate-enterFromLeft data-[motion=to-end]:motion-safe:animate-exitToRight data-[motion=to-start]:motion-safe:animate-exitToLeft">
91-
<SectionGroupTileList
92-
sections={sectionOrGroup.sections as SiteSection[]}
93-
currentSection={currentSection}
94-
/>
95-
</NavigationMenu.Content>
96-
</>
73+
sectionOrGroup.sections.length > 0 ? (
74+
<>
75+
<NavigationMenu.Trigger
76+
ref={(node) =>
77+
onNodeUpdate(
78+
node,
79+
id,
80+
sectionOrGroup.sections.length,
81+
)
82+
}
83+
asChild
84+
>
85+
<SectionGroupTab
86+
isActive={isActive}
87+
title={title}
88+
icon={icon as IconName}
89+
/>
90+
</NavigationMenu.Trigger>
91+
<NavigationMenu.Content className="absolute z-20 left-0 top-0 w-full md:w-max data-[motion=from-end]:motion-safe:animate-enterFromRight data-[motion=from-start]:motion-safe:animate-enterFromLeft data-[motion=to-end]:motion-safe:animate-exitToRight data-[motion=to-start]:motion-safe:animate-exitToLeft">
92+
<SectionGroupTileList
93+
sections={
94+
sectionOrGroup.sections as SiteSection[]
95+
}
96+
currentSection={currentSection}
97+
/>
98+
</NavigationMenu.Content>
99+
</>
100+
) : null
97101
) : (
98102
<NavigationMenu.Link asChild>
99103
<SectionTab
@@ -250,7 +254,7 @@ function SectionGroupTile(props: { section: SiteSection; isActive: boolean }) {
250254
{icon ? <SectionIcon isActive={false} icon={icon as IconName} /> : null}
251255
<span className="truncate min-w-0">{title}</span>
252256
</div>
253-
<p className="text min-h-[2lh]">{/* TODO - add section description */}</p>
257+
<p className="text-tint-subtle min-h-[2lh]">{section.description}</p>
254258
</Link>
255259
</li>
256260
);

packages/gitbook/src/lib/pointer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { headers } from 'next/headers';
33
import { assert } from 'ts-essentials';
44

55
import { SiteContentPointer, SpaceContentPointer } from './api';
6+
import { getSiteStructureSections } from './utils';
67

78
/**
89
* Get the current site content pointer from the headers
@@ -52,7 +53,7 @@ export function checkIsRootPointer(
5253
): boolean {
5354
switch (siteStructure.type) {
5455
case 'sections': {
55-
return siteStructure.structure.some(
56+
return getSiteStructureSections(siteStructure).some(
5657
(structure) =>
5758
structure.default &&
5859
structure.id === pointer.siteSectionId &&

packages/gitbook/src/lib/references.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
ContentRef,
3-
ContentRefSpace,
43
Revision,
54
RevisionFile,
65
RevisionPageDocument,
@@ -31,6 +30,7 @@ import { getBlockById, getBlockTitle } from './document';
3130
import { getGitbookAppHref, getPageHref, PageHrefContext } from './links';
3231
import { getPagePath, resolvePageId } from './pages';
3332
import { ClassValue } from './tailwind';
33+
import { getSiteStructureSections } from './utils';
3434

3535
export interface ResolvedContentRef {
3636
/** Text to render in the content ref */
@@ -317,10 +317,13 @@ async function getBestTargetSpace(
317317
const siteSpaces =
318318
publishedContentSite.structure.type === 'siteSpaces'
319319
? publishedContentSite.structure.structure
320-
: publishedContentSite.structure.structure.reduce<SiteSpace[]>((acc, section) => {
321-
acc.push(...section.siteSpaces);
322-
return acc;
323-
}, []);
320+
: getSiteStructureSections(publishedContentSite.structure).reduce<SiteSpace[]>(
321+
(acc, section) => {
322+
acc.push(...section.siteSpaces);
323+
return acc;
324+
},
325+
[],
326+
);
324327
const spaces = parseSpacesFromSiteSpaces(siteSpaces);
325328
const foundSpace = spaces.find((space) => space.id === spaceId);
326329
if (foundSpace) {

packages/gitbook/src/lib/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,11 @@ export function defaultCustomizationForSpace(): api.CustomizationSettings {
7272
inherit: false,
7373
};
7474
}
75+
76+
export function getSiteStructureSections(siteStructure: api.SiteStructure) {
77+
return siteStructure.type === 'sections'
78+
? siteStructure.structure.flatMap((item) =>
79+
item.object === 'site-section-group' ? item.sections : item,
80+
)
81+
: [];
82+
}

0 commit comments

Comments
 (0)