Skip to content

Commit 38983f1

Browse files
author
Adrian Bece
committed
Cleanup and README updates
1 parent 7edac1c commit 38983f1

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div align="center">
22
<img src="https://res.cloudinary.com/dazdt97d3/image/upload/c_scale,q_auto:best,w_200/v1606558223/omni-logo.jpg" alt="Omni font loader logo">
33
<br/><br/>
4-
<h1>Gatsby Omni Font Loader</h1>
4+
<h1>Gatsby Omni Font Loader v2</h1>
55
</div>
66

77
- Simple way to add webfonts or custom fonts to Gatsby project
@@ -106,12 +106,12 @@ Add the following snippet to `gatsby-config.js` plugins array.
106106
<td>false</td>
107107
</tr>
108108
<tr>
109-
<td>interval</td>
109+
<td>interval <strong>(V1 ONLY)</strong></td>
110110
<td>Works if <code>enableListener</code> is <code>true</code>. Font listener interval (in ms). Default is 300ms. Recommended: >=300ms. </td>
111111
<td>300</td>
112112
</tr>
113113
<tr>
114-
<td>timeout</td>
114+
<td>timeout <strong>(V1 ONLY)</strong></td>
115115
<td>Works if <code>enableListener</code> is <code>true</code>. Font listener timeout value (in ms). Default is 30s (30000ms). Listener will no longer check for loaded fonts after timeout, fonts will still be loaded and displayed, but without handling FOUT.</td>
116116
<td>30000</td>
117117
</tr>
@@ -164,20 +164,24 @@ To avoid this, we can use CSS to style the fallback font to closely match the fo
164164

165165
When `enableListener: true` is set in plugin config in `gatsby-config.js`, HTML classes are being added to `<body>` element as the fonts are being loaded.
166166

167-
HTML class name format will be in the following format `wf-[font-family-name]--loaded`.
167+
HTML class name format will be in the following format `wf-[font-family-name]`. When all fonts are loaded `wf-all` is applied.
168168

169169
You can use the [Font Style Matcher](https://meowni.ca/font-style-matcher/) to adjust the perfect fallback font and fallback CSS config.
170170

171171
Here is the example of how `body` element will look like after all fonts are being loaded (depending on the config).
172172

173173
```html
174174
<body
175-
class="wf-lazy-monday--loaded wf-font-awesome-5-brands--loaded wf-font-awesome-5-free--loaded wf-staatliches--loaded wf-henny-penny--loaded"
175+
class="wf-lazy-monday wf-font-awesome-5-brands wf-font-awesome-5-free wf-staatliches wf-all"
176176
></body>
177177
```
178178

179179
<img alt="FOUT example" src="https://res.cloudinary.com/dazdt97d3/image/upload/v1604140006/fouc.gif">
180180

181+
## V2 breaking changes
182+
* Removed `interval` and `timeout` options
183+
* Changed class name format to a more generic `wf-[font-family-name]` to avoid mixing naming conventions
184+
181185
## Issues and Contributions
182186

183187
Feel free to [report issues](https://github.com/codeAdrian/gatsby-omni-font-loader/issues) you find and feel free to contribute to the project by creating Pull Requests.

gatsby-browser.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ import { fontListener } from "./utils/fontListener";
66

77
export const onClientEntry = (
88
_,
9-
{ custom = [], web = [], enableListener, scope = SCOPE_DEFAULT }
9+
{ custom = [], web = [], enableListener = false, scope = SCOPE_DEFAULT }
1010
) => {
11-
if (enableListener) {
12-
const listenerProps = { fontNames, scope };
13-
const allFonts = [...custom, ...web];
14-
const fontNames = getFontNames(allFonts);
15-
16-
fontListener(listenerProps);
11+
if (!enableListener) {
12+
return;
1713
}
14+
15+
const allFonts = [...custom, ...web];
16+
const fontNames = getFontNames(allFonts);
17+
const listenerProps = { fontNames, scope };
18+
19+
fontListener(listenerProps);
1820
};
1921

2022
export const wrapRootElement = (

gatsby-ssr.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
import { MODE_DEFAULT } from "./consts";
22
import { getFontConfig } from "./generators";
3-
import { getFontFiles, getFontNames } from "./utils";
3+
import { getFontFiles } from "./utils";
44

55
export const onRenderBody = (
66
{ setHeadComponents },
7-
{
8-
enableListener,
9-
preconnect = [],
10-
preload = [],
11-
web = [],
12-
custom = [],
13-
mode = MODE_DEFAULT,
14-
}
7+
{ preconnect = [], preload = [], web = [], custom = [], mode = MODE_DEFAULT }
158
) => {
169
const allFonts = [...web, ...custom];
1710
const allPreloads = preload.concat(getFontFiles(allFonts));
18-
const fontNames = getFontNames(allFonts);
1911

2012
const preloadConfig = getFontConfig(
2113
preconnect,

0 commit comments

Comments
 (0)