-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(css): Reduce layout shift with fonts fallback
- Loading branch information
Showing
7 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import fs from "node:fs/promises"; | ||
|
||
import { createFontStack } from "@capsizecss/core"; | ||
import Arial from "@capsizecss/metrics/arial"; | ||
import NotoSans from "@capsizecss/metrics/notoSans"; | ||
import Roboto from "@capsizecss/metrics/roboto"; | ||
import Teko from "@capsizecss/metrics/teko"; | ||
import WorkSans from "@capsizecss/metrics/workSans"; | ||
import prettier from "prettier"; | ||
import stylelint from "stylelint"; | ||
|
||
const filepath = "./public/css/global/fonts-fallback.css"; | ||
|
||
const heading = createFontStack([Teko, NotoSans, Roboto, Arial]); | ||
const text = createFontStack([WorkSans, NotoSans, Roboto, Arial]); | ||
|
||
let code = ` | ||
${heading.fontFaces} | ||
${text.fontFaces} | ||
`; | ||
|
||
// Run Stylelint autofixer | ||
const linterResult = await stylelint.lint({ code, fix: true }); | ||
code = linterResult.code ?? ""; | ||
|
||
// Run Prettier formatter | ||
const prettierOptions = await prettier.resolveConfig(filepath, { | ||
editorconfig: true, | ||
}); | ||
code = await prettier.format(code, { filepath, ...prettierOptions }); | ||
|
||
await fs.writeFile(filepath, code); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
@font-face { | ||
ascent-override: 155.511%; | ||
descent-override: 77.1062%; | ||
font-family: "Teko Fallback: Noto Sans"; | ||
size-adjust: 61.6034%; | ||
src: local("Noto Sans Regular"), local("NotoSans-Regular"); | ||
} | ||
|
||
@font-face { | ||
ascent-override: 145.9389%; | ||
descent-override: 72.3601%; | ||
font-family: "Teko Fallback: Roboto"; | ||
size-adjust: 65.6439%; | ||
src: local("Roboto"), local("Roboto-Regular"); | ||
} | ||
|
||
@font-face { | ||
ascent-override: 146.2593%; | ||
descent-override: 72.519%; | ||
font-family: "Teko Fallback: Arial"; | ||
line-gap-override: 0%; | ||
size-adjust: 65.5001%; | ||
src: local("Arial"), local("ArialMT"); | ||
} | ||
|
||
@font-face { | ||
ascent-override: 88.3407%; | ||
descent-override: 23.0826%; | ||
font-family: "Work Sans Fallback: Noto Sans"; | ||
size-adjust: 105.2743%; | ||
src: local("Noto Sans Regular"), local("NotoSans-Regular"); | ||
} | ||
|
||
@font-face { | ||
ascent-override: 82.9031%; | ||
descent-override: 21.6618%; | ||
font-family: "Work Sans Fallback: Roboto"; | ||
size-adjust: 112.1791%; | ||
src: local("Roboto"), local("Roboto-Regular"); | ||
} | ||
|
||
@font-face { | ||
ascent-override: 83.0851%; | ||
descent-override: 21.7093%; | ||
font-family: "Work Sans Fallback: Arial"; | ||
line-gap-override: 0%; | ||
size-adjust: 111.9334%; | ||
src: local("Arial"), local("ArialMT"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters