-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for custom fonts #2981
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 58996a4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
eb1d10b
to
e7e88bc
Compare
Summary of the deployments: Version 1 (production)
Version 2 (experimental)
Test content |
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
e7e88bc
to
90d7ca2
Compare
736c95e
to
ea6f29d
Compare
ea6f29d
to
c0e5d0e
Compare
c0e5d0e
to
f0666a9
Compare
f0666a9
to
540feae
Compare
0273e66
to
e33ac2d
Compare
e33ac2d
to
34bfd22
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, I'm not sure about the use of ReactDOM.preload
in SSR though
|
||
// Preconnect and preload custom fonts if needed | ||
if (fontData.type === 'custom') { | ||
ReactDOM.preconnect(GITBOOK_FONTS_URL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this work on the server? Preloading in Nextjs seems to have different recommendations: https://nextjs.org/docs/app/building-your-application/data-fetching/fetching#preloading-data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. The next preload mechanism appears to be more geared toward preloading next data rather than external resources like fonts. I haven't seen any examples in the wild using this pattern to preload custom fonts.
packages/gitbook/src/fonts/custom.ts
Outdated
}) | ||
.join(', '); | ||
|
||
// We could use the font-family name here, but to avoid extra normalization we're using 'CustomFont' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I wonder if this will have a wider impact as the underlying font data might have a different name. Should be fine for now though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deliberately hardcoded the font family to “CustomFont” to avoid the complexity of normalizing the user input. I'm not sure it matters about the underlying font data names, as we always reference the custom font via our standardized CSS variable and class. Unless I'm missing something, lemme know.
94a9735
to
58996a4
Compare
Adds support for custom fonts in GitBook by dynamically generating
@font-face
rules from user-defined font configurations and preloading the key font sources. It integrates these custom fonts into the layout and OG image generation