Skip to content

Commit e43c9ad

Browse files
committed
Merge branch 'main' into claire/RND-10337-display-update-blocks-headings-in-page-outline
* main: Make ToC groups collapsible and other styles fixes/improvements (#4177) Fix HTML lang attribute not reflecting language variants (#4186) Docs Embed: Better support light/dark mode overrides (#4181) Translations dropdown should show language spaces that best matches the current space title (#4184) Fix llms.txt and llms-full.txt language variants filtering (#4179) Hide empty sidebar on OpenAPI pages (#4180) Rework page layout (#4013) Version Packages (#4163) Fix toolbar design (#4175) Extend gitbook/expr std lib with some additional methods (#4173) Prepare for step.content to be optional (#4174) Refactor test setup for improved mock restoration (#4176) Reduce search debounce (#4170) Exclude language variants from llms.txt and llms-full.txt (#4165) Fix MCP getPage tool returning page not found (#4166) Expose a ~gitbook/mcp/auth endpoint for non-VA adaptive content sites (#4155) Improve AI agent detection and readability by outputting 200 for page not found (#4164) Respect locale to format date in update block (#4160) Fix HTML lang attribute not reflecting site language variants (#4161) Improve Assistant form controls, i18n, and UX (#4159)
2 parents 160241b + bda9fe2 commit e43c9ad

109 files changed

Lines changed: 2145 additions & 595 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/fruity-queens-jog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"gitbook": patch
3+
"@gitbook/embed": patch
4+
---
5+
6+
Docs Embed: Better support light/dark mode overrides

.changeset/honest-aliens-trade.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+
Hide empty sidebar on OpenAPI pages

.changeset/metal-ghosts-move.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": minor
3+
---
4+
5+
Rework page layout

.changeset/upset-comics-accept.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+
Translations dropdown should show language spaces that best matches the current space title

.github/workflows/publish.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ jobs:
2626
with:
2727
node-version: 22
2828
registry-url: 'https://registry.npmjs.org'
29-
# Ensure npm 11.5.1 or later is installed
3029
- name: Update npm
31-
run: npm install -g npm@latest
30+
run: |
31+
corepack enable npm
32+
corepack install -g npm@latest
3233
- name: Setup Bun
3334
uses: ./.github/composite/setup-bun
3435
- name: Install dependencies
@@ -45,4 +46,3 @@ jobs:
4546
# Using a PAT instead of GITHUB_TOKEN because we need to run workflows when releases are created
4647
# https://github.com/orgs/community/discussions/26875#discussioncomment-3253761
4748
GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_TOKEN }}
48-

bun.lock

Lines changed: 22 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"devDependencies": {
88
"@biomejs/biome": "^1.9.4",
99
"@changesets/cli": "^2.30.0",
10-
"turbo": "^2.9.2",
10+
"turbo": "^2.9.6",
1111
"vercel": "50.37.3"
1212
},
1313
"packageManager": "bun@1.3.7",

packages/embed/README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const gitbook = createGitBook({
7272
// Create an iframe and get its URL
7373
const iframe = document.createElement('iframe');
7474
iframe.src = gitbook.getFrameURL({
75+
colorScheme: 'dark', // Optional: force the embed to render in dark mode
7576
visitor: {
7677
token: 'your-jwt-token', // Optional: for Adaptive Content or Authenticated Access
7778
unsignedClaims: { // Optional: custom claims for dynamic expressions
@@ -122,6 +123,7 @@ import { GitBookProvider, GitBookFrame } from '@gitbook/embed/react';
122123

123124
<GitBookProvider siteURL="https://docs.company.com">
124125
<GitBookFrame
126+
colorScheme="dark"
125127
visitor={{
126128
token: 'your-jwt-token', // Optional: for Adaptive Content or Authenticated Access
127129
unsignedClaims: { userId: '123' } // Optional: custom claims for dynamic expressions
@@ -150,7 +152,7 @@ import { useGitBook } from '@gitbook/embed/react';
150152

151153
function MyComponent() {
152154
const gitbook = useGitBook();
153-
const frameURL = gitbook.getFrameURL({ visitor: { token: '...' } });
155+
const frameURL = gitbook.getFrameURL({ colorScheme: 'dark', visitor: { token: '...' } });
154156
// ...
155157
}
156158
```
@@ -178,7 +180,7 @@ function MyComponent() {
178180

179181
### Standalone Script
180182

181-
- `GitBook('init', options: { siteURL: string }, frameOptions?: { visitor?: {...} })` - Initialize widget
183+
- `GitBook('init', options: { siteURL: string }, frameOptions?: { colorScheme?: 'light' | 'dark', visitor?: {...} })` - Initialize widget
182184
- `GitBook('show')` - Show widget button
183185
- `GitBook('hide')` - Hide widget button
184186
- `GitBook('open')` - Open widget window
@@ -195,7 +197,7 @@ function MyComponent() {
195197

196198
**Client Factory:**
197199
- `createGitBook(options: { siteURL: string })``GitBookClient`
198-
- `client.getFrameURL(options?: { visitor?: {...} })``string`
200+
- `client.getFrameURL(options?: { colorScheme?: 'light' | 'dark', visitor?: {...} })``string`
199201
- `client.createFrame(iframe: HTMLIFrameElement)``GitBookFrameClient`
200202

201203
**Frame Client:**
@@ -457,6 +459,24 @@ visitor: {
457459
}
458460
```
459461

462+
### `colorScheme`
463+
464+
Available in: Standalone script (via `init`), NPM package (via `getFrameURL()`), React components (as prop)
465+
466+
Override the embed's color scheme. When omitted, the embed follows the iframe's CSS `color-scheme`, which lets it inherit the parent page or browser preference.
467+
468+
**Note**: This is not a configuration option but rather a parameter when initializing the frame or creating the frame URL.
469+
470+
**Standalone script**: Pass as the second argument to `GitBook('init', options, frameOptions)`
471+
**NPM package**: Pass to `getFrameURL({ colorScheme: 'dark' })`
472+
**React components**: Pass as the `colorScheme` prop on `<GitBookFrame>`
473+
474+
- **Type**: `'light' | 'dark'`
475+
476+
```javascript
477+
colorScheme: 'dark'
478+
```
479+
460480
### `button`
461481

462482
Available in: Standalone script only

packages/embed/src/client/createGitBook.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,17 @@ describe('createGitBook.getFrameURL', () => {
3535
expect(url.searchParams.get('visitor.count')).toBe('3');
3636
expect(url.searchParams.get('visitor.enabled')).toBe('false');
3737
});
38+
39+
it('adds an explicit color scheme override when requested', () => {
40+
const client = createGitBook({ siteURL: 'https://example.com/docs/' });
41+
42+
const url = new URL(
43+
client.getFrameURL({
44+
colorScheme: 'dark',
45+
})
46+
);
47+
48+
expect(url.pathname).toBe('/docs/~gitbook/embed');
49+
expect(url.searchParams.get('theme')).toBe('dark');
50+
});
3851
});

packages/embed/src/client/createGitBook.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ export type CreateGitBookOptions = {
88
};
99

1010
export type GetFrameURLOptions = {
11+
/**
12+
* Override the color scheme used by the embedded docs.
13+
* When omitted, the embed follows the iframe's CSS `color-scheme`.
14+
*/
15+
colorScheme?: 'light' | 'dark';
16+
1117
/**
1218
* Authentication to use for the frame.
1319
*/
@@ -42,6 +48,10 @@ export function createGitBook(options: CreateGitBookOptions) {
4248
const url = new URL(options.siteURL);
4349
url.pathname = `${url.pathname.endsWith('/') ? url.pathname : `${url.pathname}/`}~gitbook/embed`;
4450

51+
if (frameOptions.colorScheme) {
52+
url.searchParams.set('theme', frameOptions.colorScheme);
53+
}
54+
4555
if (frameOptions.visitor?.token) {
4656
url.searchParams.set('jwt_token', frameOptions.visitor.token);
4757
}

0 commit comments

Comments
 (0)