Skip to content

Commit 540feae

Browse files
committed
move google fonts to default
1 parent efce4e3 commit 540feae

File tree

6 files changed

+392
-269
lines changed

6 files changed

+392
-269
lines changed

bun.lock

+154-29
Large diffs are not rendered by default.

packages/gitbook/src/components/RootLayout/CustomizationRootLayout.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
} from '@gitbook/colors';
2323
import { IconStyle, IconsProvider } from '@gitbook/icons';
2424

25-
import { fontNotoColorEmoji, getFontData, renderFontPreloads, renderFontStyles } from '@/fonts';
25+
import { fontNotoColorEmoji, getFontData } from '@/fonts';
2626
import { getSpaceLanguage } from '@/intl/server';
2727
import { getAssetURL } from '@/lib/assets';
2828
import { tcls } from '@/lib/tailwind';

packages/gitbook/src/fonts/customFont.test.ts packages/gitbook/src/fonts/custom.test.ts

+23-25
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
type CustomizationFontDefinition,
55
generateFontFacesCSS,
66
getFontSourcesToPreload,
7-
} from './customFonts';
7+
} from './custom';
88

99
const TEST_FONTS = {
1010
basic: {
@@ -15,7 +15,7 @@ const TEST_FONTS = {
1515
weight: 400,
1616
sources: [
1717
{
18-
url: new URL('https://example.com/fonts/opensans-regular.woff2'),
18+
url: 'https://example.com/fonts/opensans-regular.woff2',
1919
format: 'woff2',
2020
},
2121
],
@@ -24,7 +24,7 @@ const TEST_FONTS = {
2424
weight: 700,
2525
sources: [
2626
{
27-
url: new URL('https://example.com/fonts/opensans-bold.woff2'),
27+
url: 'https://example.com/fonts/opensans-bold.woff2',
2828
format: 'woff2',
2929
},
3030
],
@@ -40,7 +40,7 @@ const TEST_FONTS = {
4040
weight: 300,
4141
sources: [
4242
{
43-
url: new URL('https://example.com/fonts/roboto-light.woff2'),
43+
url: 'https://example.com/fonts/roboto-light.woff2',
4444
format: 'woff2',
4545
},
4646
],
@@ -49,7 +49,7 @@ const TEST_FONTS = {
4949
weight: 400,
5050
sources: [
5151
{
52-
url: new URL('https://example.com/fonts/roboto-regular.woff2'),
52+
url: 'https://example.com/fonts/roboto-regular.woff2',
5353
format: 'woff2',
5454
},
5555
],
@@ -58,7 +58,7 @@ const TEST_FONTS = {
5858
weight: 500,
5959
sources: [
6060
{
61-
url: new URL('https://example.com/fonts/roboto-medium.woff2'),
61+
url: 'https://example.com/fonts/roboto-medium.woff2',
6262
format: 'woff2',
6363
},
6464
],
@@ -67,7 +67,7 @@ const TEST_FONTS = {
6767
weight: 700,
6868
sources: [
6969
{
70-
url: new URL('https://example.com/fonts/roboto-bold.woff2'),
70+
url: 'https://example.com/fonts/roboto-bold.woff2',
7171
format: 'woff2',
7272
},
7373
],
@@ -76,7 +76,7 @@ const TEST_FONTS = {
7676
weight: 900,
7777
sources: [
7878
{
79-
url: new URL('https://example.com/fonts/roboto-black.woff2'),
79+
url: 'https://example.com/fonts/roboto-black.woff2',
8080
format: 'woff2',
8181
},
8282
],
@@ -92,10 +92,10 @@ const TEST_FONTS = {
9292
weight: 400,
9393
sources: [
9494
{
95-
url: new URL('https://example.com/fonts/lato-regular.woff2'),
95+
url: 'https://example.com/fonts/lato-regular.woff2',
9696
format: 'woff2',
9797
},
98-
{ url: new URL('https://example.com/fonts/lato-regular.woff'), format: 'woff' },
98+
{ url: 'https://example.com/fonts/lato-regular.woff', format: 'woff' },
9999
],
100100
},
101101
],
@@ -108,9 +108,9 @@ const TEST_FONTS = {
108108
{
109109
weight: 400,
110110
sources: [
111-
{ url: new URL('https://example.com/fonts/sourcesans-regular.woff2') },
111+
{ url: 'https://example.com/fonts/sourcesans-regular.woff2' },
112112
{
113-
url: new URL('https://example.com/fonts/sourcesans-regular.woff'),
113+
url: 'https://example.com/fonts/sourcesans-regular.woff',
114114
format: 'woff',
115115
},
116116
],
@@ -130,9 +130,7 @@ const TEST_FONTS = {
130130
fontFaces: [
131131
{
132132
weight: 400,
133-
sources: [
134-
{ url: new URL('https://example.com/fonts/special.woff2'), format: 'woff2' },
135-
],
133+
sources: [{ url: 'https://example.com/fonts/special.woff2', format: 'woff2' }],
136134
},
137135
],
138136
} as CustomizationFontDefinition,
@@ -144,15 +142,15 @@ const TEST_FONTS = {
144142
{
145143
weight: 400,
146144
sources: [
147-
{ url: new URL('https://example.com/fonts/regular.woff2') },
148-
{ url: new URL('https://example.com/fonts/regular.woff') },
145+
{ url: 'https://example.com/fonts/regular.woff2' },
146+
{ url: 'https://example.com/fonts/regular.woff' },
149147
],
150148
},
151149
{
152150
weight: 700,
153151
sources: [
154-
{ url: new URL('https://example.com/fonts/bold.woff2') },
155-
{ url: new URL('https://example.com/fonts/bold.woff') },
152+
{ url: 'https://example.com/fonts/bold.woff2' },
153+
{ url: 'https://example.com/fonts/bold.woff' },
156154
],
157155
},
158156
],
@@ -165,9 +163,9 @@ const TEST_FONTS = {
165163
{
166164
weight: 400,
167165
sources: [
168-
{ url: new URL('https://example.com/fonts/absolute.woff2') },
169-
{ url: new URL('/fonts/relative.woff2', 'https://example.com') },
170-
{ url: new URL('./fonts/path-relative.woff2', 'https://example.com') },
166+
{ url: 'https://example.com/fonts/1.woff2' },
167+
{ url: 'https://example.com/fonts/2.woff2' },
168+
{ url: 'https://example.com/fonts/3.woff2' },
171169
],
172170
},
173171
],
@@ -292,8 +290,8 @@ describe('getCustomFontPreloadLinks', () => {
292290

293291
expect(result).toBeArray();
294292
expect(result.length).toBe(3);
295-
expect(result).toContain('https://example.com/fonts/absolute.woff2');
296-
expect(result).toContain('https://example.com/fonts/relative.woff2');
297-
expect(result).toContain('https://example.com/fonts/path-relative.woff2');
293+
expect(result).toContain('https://example.com/fonts/1.woff2');
294+
expect(result).toContain('https://example.com/fonts/2.woff2');
295+
expect(result).toContain('https://example.com/fonts/3.woff2');
298296
});
299297
});

packages/gitbook/src/fonts/customFonts.ts packages/gitbook/src/fonts/custom.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { CustomizationDefaultFont } from '@gitbook/api';
2-
import { fonts } from './index';
2+
import { fonts } from './default';
33

44
/**
55
* The human-readable font-family name used in CSS (e.g., "Open Sans", "Playfair Display").
@@ -60,7 +60,7 @@ export type CustomizationFont = CustomizationDefaultFont | CustomizationFontDefi
6060
* Define the custom font faces and set the --font-content to the custom font name
6161
*/
6262
export function generateFontFacesCSS(customFont: CustomizationFontDefinition): string {
63-
const { fontFamily, fontFaces } = customFont;
63+
const { fontFaces } = customFont;
6464

6565
// Generate font face declarations for all weights
6666
const fontFaceDeclarations = fontFaces
@@ -77,9 +77,10 @@ export function generateFontFacesCSS(customFont: CustomizationFontDefinition): s
7777
})
7878
.join(', ');
7979

80+
// We could use the font-family name here, but to avoid extra normalization we're using CustomFont
8081
return `
8182
@font-face {
82-
font-family: ${fontFamily};
83+
font-family: CustomFont;
8384
font-style: normal;
8485
font-weight: ${face.weight};
8586
font-display: swap;
@@ -92,7 +93,7 @@ export function generateFontFacesCSS(customFont: CustomizationFontDefinition): s
9293
return `
9394
${fontFaceDeclarations}
9495
:root {
95-
--font-custom: ${fontFamily};
96+
--font-custom: CustomFont;
9697
}
9798
`;
9899
}
@@ -140,7 +141,6 @@ interface CustomFontData {
140141

141142
/**
142143
* Get the appropriate font data for a given font configuration
143-
* @param font Either a predefined font name or a custom font configuration
144144
*/
145145
export function getFontData(font: CustomizationFont): FontData {
146146
if (typeof font === 'string') {

0 commit comments

Comments
 (0)