Skip to content

Commit 9875992

Browse files
committed
Update content according to PR comments
1 parent df4a473 commit 9875992

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

website/blog/2022-04-08-adding-fonts.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ hide_table_of_contents: false
1111
Every project is unique. Logo, colors, fonts, etc. are what define the visual identity of your website. In this post, we'll cover adding fonts to a project.
1212
<!--truncate-->
1313

14-
### Importing fonts into your project
15-
[Our documentation](/docs/basics/fonts) covers the necessary steps to add a font to your project, but here we'll cover the process in a bit more detail. To start, we need a font (or two). For this example, I'll use **_SourceSansPro_** and **_NotoSerif_** which I've downloaded from [Google Fonts](https://fonts.google.com/). These are in the `.ttf` format, so convert them to `.woff` and `.woff2. Whatever approach you use is okay - we recommend the following tools:
16-
- https://convertio.co/ttf-woff/
17-
- https://cloudconvert.com/ttf-to-woff
18-
- https://everythingfonts.com/ttf-to-woff
19-
20-
Fonts should go inside your theme's **_/assets/fonts_** folder. Copy the fonts you want to use there. You will also notice that this folder contains an **_index.js_** file. This file is used to import fonts into your project. Here's an example of how I imported my fonts:
14+
## Importing fonts into your project
15+
[Our documentation](/docs/basics/fonts) covers the necessary steps to add a font to your project, but here we'll cover the process in a bit more detail. To start, we need a font (or two). For this example, I'll use **_Source Sans Pro_** and **_Noto Serif_** which I've downloaded from [Google Fonts](https://fonts.google.com/). They are in the `.ttf` format (you may find some which are `.otf`, which will work in the same way), so you need to convert them to `.woff` and `.woff2`. Whatever approach you use is okay - we recommend the following tools:
16+
- [Convertio](https://convertio.co/ttf-woff/)
17+
- [Cloud Convert](https://cloudconvert.com/ttf-to-woff)
18+
- [Everything Fonts](https://everythingfonts.com/ttf-to-woff)
19+
- [Transfonter](https://transfonter.org/)
20+
21+
Fonts should go inside your theme's **_/assets/fonts_** folder. Copy the fonts you want to use there. You will also notice that this folder contains an **_index.js_** file, used to import fonts into your project. Here's an example of how I imported my fonts:
2122
```js
2223
// SourceSansPro WOFF
2324
import './SourceSansPro-Bold.woff';
@@ -73,8 +74,9 @@ Next, you can create a new file called **__typography.scss_** inside your **_/as
7374
@include font-face(global-settings(secondaryFont), 'NotoSerif-Italic', 400, italic);
7475
@include font-face(global-settings(secondaryFont), 'NotoSerif-Regular', 400);
7576
```
77+
If you would like to know more about the `font-face` mixin, you can take a look at our [Sass documentation](/sass).
7678

77-
Because this is a new file, we have to include it. You can do that inside **_/assets/styles/parts/_shared.scss_** file:
79+
Because this is a new file, we have to include it. You can do that inside **_/assets/styles/parts/\_shared.scss_** file:
7880
```scss
7981
// Project specific.
8082
@import 'utils/shared-variables';
@@ -83,28 +85,28 @@ Because this is a new file, we have to include it. You can do that inside **_/as
8385

8486
Run `npm start` to rebuild your **_public_** folder and assets. If you did everything correctly, your build should pass and you will see your fonts inside the **_public_** folder.
8587

86-
### Using only one font in a block
88+
## Using only one font in a block
8789

8890
There are multiple ways of using fonts in a block. The simplest example is if you have only one font you want to use for that specific block. In this case, we want the Heading block to only use _Noto Serif_.
8991

90-
To make our secondary font available for use, we need to first define it as a variable. We can do that in **_/assets/styles/parts/utils/_shared-variables.scss_**. We can see there that the base font is already defined, so all we need to do is add our secondary font below.
92+
To make our secondary font available for use, we need to first define it as a variable. We can do that in **_/assets/styles/parts/utils/\_shared-variables.scss_**. We can see there that the base font is already defined, so all we need to do is add our secondary font below.
9193

92-
To make things a bit more consistent, we may also want to rename `--global-font-family` CSS variable to `--base-font-family`. Just don't forget to search/replace this new variable name across your project! Once we're done, it should look like this:
94+
To make things a bit more consistent, we may also want to rename `--global-font-family` CSS variable to `--base-font-family`. Just don't forget to search/replace this new variable name across your project! Please note that the fallbacks for the fonts can be anything, this is just an example. Once we're done, it should look like this:
9395
```scss
9496
--base-font-family: var(--global-base-font), -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
9597
Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
9698

9799
--secondary-font-family: var(--global-secondary-font), -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
98100
Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
99101
```
100-
After defining `--secondary-font-family` CSS variable, we can go to **_/src/Blocks/components/heading/heading-style.scss_** and add the following rule to the `.heading` class:
102+
After defining the `--secondary-font-family` CSS variable, we can go to **_/src/Blocks/components/heading/heading-style.scss_** and add the following rule to the `.heading` class:
101103
```scss
102104
font-family: var(--secondary-font-family);
103105
```
104106

105107
And that's it! The Heading block will now use the _Noto Serif_ font.
106108

107-
### Adding an option for selecting fonts
109+
## Adding an option for selecting fonts
108110

109111
In some cases, you may want to give users the option to choose between fonts that they want to use in their block. For this example, we'll use the `paragraph` block where we want users to have both _Source Sans Pro_ and _Noto Serif_ available.
110112

@@ -189,7 +191,7 @@ The control for selecting a font should now be available under Paragraph options
189191

190192
After adding this single line of CSS code, your new option for selecting fonts will now be fully functional.
191193

192-
### Closing thoughts
194+
## Closing thoughts
193195
Adding fonts to a project is something you will usually only do when setting up a new project and then forget about it. As you could see in this blog post, this isn't a complicated process, but it has a specific set of steps that have to be taken in order for custom fonts to work in your project.
194196

195197
Of course, there are other ways to include fonts in your project, but the described process is what we recommend and use. This is the (Eightshift) Way.

0 commit comments

Comments
 (0)