Skip to content

Commit 5c35f36

Browse files
authored
Prepare @gitbook/icons package and use it as a replacement of geist/icons (#2404)
1 parent d7ec2b5 commit 5c35f36

File tree

85 files changed

+865
-548
lines changed

Some content is hidden

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

85 files changed

+865
-548
lines changed

.changeset/healthy-spoons-itch.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+
Replace all icons, previously imported from Geist, by new package `@gitbook/icons`

.changeset/lovely-donkeys-deny.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/icons': minor
3+
---
4+
5+
Initial release for `@gitbook/icons`, a package of content icons to be used for pages, documents, etc.

.changeset/violet-beers-matter.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/react-math': minor
3+
---
4+
5+
Export binary `gitbook-math` to copy assets to a directory

.github/actions/setup-playwright/action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ runs:
77
- name: 🏗 Prepare Playwright env
88
shell: bash
99
run: |
10-
PLAYWRIGHT_VERSION=$(npm ls --json @playwright/test | jq --raw-output '.dependencies["@playwright/test"].version')
10+
PLAYWRIGHT_VERSION=$(npm ls --json @playwright/test | jq --raw-output '.dependencies["gitbook"].dependencies["@playwright/test"].version')
1111
echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
1212
1313
# Cache browser binaries, cache key is based on Playwright version and OS
@@ -24,12 +24,14 @@ runs:
2424
- name: 🏗 Install Playwright browser binaries & OS dependencies
2525
if: steps.playwright-cache.outputs.cache-hit != 'true'
2626
shell: bash
27+
working-directory: packages/gitbook
2728
run: |
2829
bun x playwright install --with-deps chromium
2930
3031
# Install only the OS dependencies if cache hit
3132
- name: 🏗 Install Playwright OS dependencies
3233
if: steps.playwright-cache.outputs.cache-hit == 'true'
3334
shell: bash
35+
working-directory: packages/gitbook
3436
run: |
3537
bun x playwright install-deps

.github/workflows/ci.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ on:
44
push:
55
branches:
66
- main
7-
7+
env:
8+
NPMRC_FONT_AWESOME_TOKEN: ${{ secrets.NPMRC_FONT_AWESOME_TOKEN }}
89
jobs:
910
deploy:
1011
name: Deploy to Cloudflare Pages

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ yarn-error.log*
2020
# Vercel
2121
.vercel
2222

23+
# Env files
24+
.env.local

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@
44
# Generated
55
packages/emoji-codepoints/index.ts
66
packages/gitbook/public/~gitbook/static/
7+
packages/icons/src/data/*.json
8+
9+
# Build files
10+
dist/

bun.lockb

89.8 KB
Binary file not shown.

bunfig.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[install.scopes]
2+
"awesome.me" = { token = "$NPMRC_FONT_AWESOME_TOKEN", url = "https://npm.fontawesome.com/" }

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
"build": "turbo run build",
99
"build:cloudflare": "turbo run build:cloudflare",
1010
"lint": "turbo run lint",
11+
"lint:fix": "turbo run lint -- --fix",
1112
"typecheck": "turbo run typecheck",
1213
"format": "prettier ./ --ignore-unknown --write",
1314
"format:check": "prettier ./ --ignore-unknown --list-different",
1415
"unit": "turbo run unit",
1516
"e2e": "turbo run e2e",
1617
"changeset": "changeset",
17-
"release": "turbo run build && changeset publish"
18+
"release": "turbo run release && changeset publish"
1819
},
1920
"workspaces": [
2021
"packages/*"
@@ -25,6 +26,6 @@
2526
"turbo": "^2.0.9"
2627
},
2728
"patchedDependencies": {
28-
"@vercel/next@4.0.15": "patches/@vercel%2Fnext@4.0.15.patch"
29+
"@vercel/next@4.3.6": "patches/@vercel%2Fnext@4.3.6.patch"
2930
}
3031
}

packages/emoji-codepoints/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
index.ts
1+
dist/

packages/emoji-codepoints/build.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import fs from 'fs';
1+
import fs from 'node:fs';
2+
import path from 'node:path';
23
import emojisRaws from 'emoji-assets/emoji.json';
34

45
interface EmojiData {
@@ -20,7 +21,8 @@ Object.entries(emojis).forEach(([key, value]) => {
2021
}
2122
});
2223

24+
fs.mkdirSync(path.resolve(__dirname, 'dist'), { recursive: true });
2325
fs.writeFileSync(
24-
'index.ts',
26+
path.resolve(__dirname, 'dist/index.ts'),
2527
`export const emojiCodepoints: Record<string, string> = ${JSON.stringify(output, null, 4)};`,
2628
);

packages/emoji-codepoints/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
"description": "Optimized mapping of codepoints to the fully qualified emoji codepoints",
44
"version": "0.2.0",
55
"private": true,
6-
"exports": "./index.ts",
6+
"exports": "./dist/index.ts",
77
"dependencies": {},
88
"devDependencies": {
99
"emoji-assets": "^8.0.0"
1010
},
1111
"scripts": {
12-
"postinstall": "bun ./build.ts"
12+
"generate": "bun ./build.ts"
1313
}
1414
}

packages/gitbook/e2e/pages.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,11 @@ const testCases: TestsCase[] = [
349349
url: 'blocks/embeds',
350350
fullPage: true,
351351
},
352+
{
353+
name: 'Page links',
354+
url: 'blocks/page-links',
355+
fullPage: true,
356+
},
352357
{
353358
name: 'Annotations',
354359
url: 'blocks/annotations',
@@ -408,7 +413,6 @@ const testCases: TestsCase[] = [
408413
{
409414
name: 'Valid link',
410415
url: 'TGs8PkF4GWVtbmPnWhYL/',
411-
run: waitForCookiesDialog,
412416
},
413417
{
414418
name: 'Invalid link',

packages/gitbook/next.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ module.exports = withSentryConfig(
77
SENTRY_DSN: process.env.SENTRY_DSN ?? '',
88
SENTRY_ENVIRONMENT: process.env.SENTRY_ENVIRONMENT ?? 'development',
99
GITBOOK_ASSETS_PREFIX: process.env.GITBOOK_ASSETS_PREFIX,
10+
GITBOOK_ICONS_URL: process.env.GITBOOK_ICONS_URL,
11+
GITBOOK_ICONS_TOKEN: process.env.GITBOOK_ICONS_TOKEN,
1012
},
1113

1214
webpack(config, { dev, webpack }) {

packages/gitbook/package.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@
33
"version": "0.3.0",
44
"private": true,
55
"scripts": {
6-
"dev": "next dev",
6+
"dev": "env-cmd -f ../../.env.local next dev",
77
"build": "next build",
88
"build:cloudflare": "next-on-pages",
99
"start": "next start",
1010
"lint": "next lint",
1111
"typecheck": "tsc --noEmit",
1212
"e2e": "playwright test",
1313
"unit": "bun test {src,packages}",
14-
"postinstall": "rm -rf ./public/~gitbook/static/[email protected] && mkdir -p ./public/~gitbook/static/ && cp -R ../../node_modules/mathjax/es5 ./public/~gitbook/static/[email protected]"
14+
"generate": "gitbook-icons ./public/~gitbook/static/icons custom-icons && gitbook-math ./public/~gitbook/static/math",
15+
"copy:icons": "gitbook-icons ./public/~gitbook/static/icons"
1516
},
1617
"dependencies": {
17-
"@geist-ui/icons": "^1.0.2",
1818
"@gitbook/api": "^0.58.0",
19+
"@gitbook/icons": "workspace:*",
1920
"@gitbook/react-math": "workspace:*",
2021
"@gitbook/react-openapi": "workspace:*",
2122
"@gitbook/react-contentkit": "workspace:*",
23+
"@gitbook/emoji-codepoints": "workspace:*",
2224
"@radix-ui/react-checkbox": "^1.0.4",
2325
"@radix-ui/react-popover": "^1.0.7",
2426
"@sentry/nextjs": "^7.94.1",
@@ -37,7 +39,7 @@
3739
"katex": "^0.16.9",
3840
"mathjax": "^3.2.2",
3941
"memoizee": "^0.4.15",
40-
"next": "^14.1.3",
42+
"next": "^14.2.5",
4143
"next-themes": "^0.2.1",
4244
"nuqs": "^1.17.4",
4345
"object-hash": "^3.0.0",
@@ -64,8 +66,8 @@
6466
"devDependencies": {
6567
"@argos-ci/playwright": "^2.0.0",
6668
"@playwright/test": "^1.42.1",
67-
"@cloudflare/next-on-pages": "^1.11.3",
68-
"@cloudflare/workers-types": "^4.20231218.0",
69+
"@cloudflare/next-on-pages": "^1.12.1",
70+
"@cloudflare/workers-types": "^4.20240725.0",
6971
"@types/js-cookie": "^3.0.6",
7072
"@types/jsontoxml": "^1.0.5",
7173
"@types/jsonwebtoken": "^9.0.6",
@@ -84,6 +86,7 @@
8486
"postcss": "^8",
8587
"psi": "^4.1.0",
8688
"tailwindcss": "^3.4.0",
87-
"typescript": "^5.5.3"
89+
"typescript": "^5.5.3",
90+
"env-cmd": "^10.1.0"
8891
}
8992
}

packages/gitbook/src/app/(space)/(core)/~gitbook/pdf/PageControlButtons.tsx

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

3-
import { AlertTriangle } from '@geist-ui/icons';
3+
import { Icon } from '@gitbook/icons';
44
import React from 'react';
55

66
import { useScrollActiveId } from '@/components/hooks';
@@ -105,7 +105,10 @@ export function PageControlButtons(props: {
105105
'max-w-sm',
106106
)}
107107
>
108-
<AlertTriangle className={tcls('size-6', 'mr-3', 'mt-1')} />{' '}
108+
<Icon
109+
icon="triangle-exclamation"
110+
className={tcls('size-6', 'mr-3', 'mt-1')}
111+
/>{' '}
109112
<div>
110113
<div>{t(language, 'pdf_limit_reached', total, pageIds.length)}</div>
111114
<div>

packages/gitbook/src/app/(space)/(core)/~gitbook/pdf/page.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { ArrowLeft, Printer } from '@geist-ui/icons';
21
import {
32
CustomizationSettings,
43
Revision,
54
RevisionPageDocument,
65
RevisionPageGroup,
7-
RevisionPageLink,
86
SiteCustomizationSettings,
97
Space,
108
} from '@gitbook/api';
9+
import { Icon } from '@gitbook/icons';
1110
import { Metadata } from 'next';
1211
import { notFound } from 'next/navigation';
1312
import * as React from 'react';
@@ -116,7 +115,7 @@ export default async function PDFHTMLOutput(props: { searchParams: { [key: strin
116115
'border',
117116
)}
118117
>
119-
<ArrowLeft className={tcls('size-6')} />
118+
<Icon icon="arrow-left" className={tcls('size-6')} />
120119
</a>
121120
</div>
122121
) : null}
@@ -142,7 +141,7 @@ export default async function PDFHTMLOutput(props: { searchParams: { [key: strin
142141
'border',
143142
)}
144143
>
145-
<Printer className={tcls('size-6')} />
144+
<Icon icon="print" className={tcls('size-6')} />
146145
</PrintButton>
147146
</div>
148147

packages/gitbook/src/app/(space)/layout.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@ import {
55
CustomizationSettings,
66
SiteCustomizationSettings,
77
} from '@gitbook/api';
8+
import { IconsProvider, IconStyle } from '@gitbook/icons';
89
import assertNever from 'assert-never';
910
import colors from 'tailwindcss/colors';
1011

1112
import { emojiFontClassName } from '@/components/primitives';
1213
import { fonts, ibmPlexMono } from '@/fonts';
1314
import { getSpaceLanguage } from '@/intl/server';
1415
import { getCurrentSiteLayoutData, getSpaceLayoutData } from '@/lib/api';
16+
import { getStaticFileURL } from '@/lib/assets';
1517
import { hexToRgb, shadesOfColor } from '@/lib/colors';
1618
import { tcls } from '@/lib/tailwind';
1719

1820
import { ClientContexts } from './ClientContexts';
1921
import './globals.css';
22+
import '@gitbook/icons/style.css';
2023
import { getContentPointer } from './fetch';
2124

2225
/**
@@ -105,7 +108,18 @@ export default async function SpaceRootLayout(props: { children: React.ReactNode
105108
'dark:bg-dark',
106109
)}
107110
>
108-
<ClientContexts language={language}>{children}</ClientContexts>
111+
<IconsProvider
112+
assetsURL={process.env.GITBOOK_ICONS_URL ?? getStaticFileURL('icons')}
113+
assetsURLToken={process.env.GITBOOK_ICONS_TOKEN}
114+
assetsByStyles={{
115+
'custom-icons': {
116+
assetsURL: getStaticFileURL('icons'),
117+
},
118+
}}
119+
iconStyle={IconStyle.Light}
120+
>
121+
<ClientContexts language={language}>{children}</ClientContexts>
122+
</IconsProvider>
109123
</body>
110124
</html>
111125
);

packages/gitbook/src/components/Ads/Ad.tsx

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

3-
import IconHeart from '@geist-ui/icons/heart';
3+
import { Icon } from '@gitbook/icons';
44
import * as React from 'react';
55

66
import { ClassValue, tcls } from '@/lib/tailwind';
@@ -188,7 +188,7 @@ function AdBlockerPlaceholder() {
188188
)}
189189
>
190190
<div className={tcls('flex', 'flex-row', 'gap-2', 'items-center')}>
191-
<IconHeart className={tcls('w-4', 'h-4', 'text-primary-500')} />
191+
<Icon icon="heart" className={tcls('size-4', 'text-primary-500')} />
192192
<p className={tcls('text-xs', 'font-semibold')}>Ad disabled</p>
193193
</div>
194194
<p className={tcls('text-xs')}>

packages/gitbook/src/components/Cookies/CookiesToast.tsx

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

3-
import IconX from '@geist-ui/icons/x';
3+
import { Icon } from '@gitbook/icons';
44
import * as React from 'react';
55

66
import { Button } from '@/components/primitives';
@@ -92,7 +92,7 @@ export function CookiesToast(props: { privacyPolicy?: string }) {
9292
)}
9393
title={tString(language, 'cookies_close')}
9494
>
95-
<IconX className={tcls('w-4')} />
95+
<Icon icon="xmark" className={tcls('size-4')} />
9696
</button>
9797
<div className={tcls('mt-3', 'flex', 'flex-row', 'gap-2')}>
9898
<Button

packages/gitbook/src/components/DocumentView/BlockContentRef.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { DocumentBlockContentRef } from '@gitbook/api';
22

3-
import { LogoIcon } from '@/components/icons';
43
import { Card, Emoji } from '@/components/primitives';
54
import { getSpaceCustomization, ignoreAPIError } from '@/lib/api';
65
import { ResolvedContentRef } from '@/lib/references';
76

87
import { BlockProps } from './Block';
8+
import { SpaceIcon } from '../Space/SpaceIcon';
99

1010
export async function BlockContentRef(props: BlockProps<DocumentBlockContentRef>) {
1111
const { block, context, style } = props;
@@ -55,7 +55,7 @@ async function SpaceRefCard(
5555
return (
5656
<Card
5757
leadingIcon={
58-
<LogoIcon
58+
<SpaceIcon
5959
icon={customIcon}
6060
emoji={customEmoji}
6161
alt=""

0 commit comments

Comments
 (0)