Skip to content

Commit 18df464

Browse files
committed
feat: add fallback fonts
1 parent fa9767f commit 18df464

5 files changed

Lines changed: 68 additions & 2 deletions

File tree

astro.config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import mdx from "@astrojs/mdx";
22
import sitemap from "@astrojs/sitemap";
33
import vercel from "@astrojs/vercel";
44
import netlify from "@astrojs/netlify";
5+
import { FontaineTransform } from "fontaine";
56

67
import { defineConfig } from "astro/config";
78
import { loadEnv } from "vite";
9+
import { join, dirname } from "node:path";
810

911
import markdown from "./src/lib/markdownConfig";
1012
import { SITE_URI } from "./src/consts";
@@ -22,4 +24,13 @@ export default defineConfig({
2224
: adapter === "vercel"
2325
? vercel()
2426
: undefined,
27+
vite: {
28+
plugins: [
29+
FontaineTransform.vite({
30+
fallbacks: ["Noto Sans", "Roboto", "Arial"],
31+
resolvePath: (id) =>
32+
new URL(join(dirname(import.meta.url), "node_modules", id)),
33+
}),
34+
],
35+
},
2536
});

bun.lockb

9.88 KB
Binary file not shown.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"astro": "^5.3.0",
4545
"autoprefixer": "^10.4.20",
4646
"cssnano": "^7.0.6",
47+
"fontaine": "^0.5.0",
4748
"mdast-util-to-string": "^4.0.0",
4849
"postcss-import": "^16.1.0",
4950
"postcss-load-config": "^6.0.1",

src/layouts/Layout.astro

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
2-
import "@fontsource-variable/lexend";
3-
import "@fontsource-variable/jetbrains-mono";
2+
import "@styles/fonts.css";
43
import "@styles/global.css";
54
65
import Head from "@comps/Head.astro";

src/styles/fonts.css

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* lexend-latin-ext-wght-normal */
2+
@font-face {
3+
font-family: "Lexend Variable";
4+
font-style: normal;
5+
font-display: swap;
6+
font-weight: 100 900;
7+
src: url(@fontsource-variable/lexend/files/lexend-latin-ext-wght-normal.woff2)
8+
format("woff2-variations");
9+
unicode-range:
10+
U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304,
11+
U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB,
12+
U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
13+
}
14+
15+
/* lexend-latin-wght-normal */
16+
@font-face {
17+
font-family: "Lexend Variable";
18+
font-style: normal;
19+
font-display: swap;
20+
font-weight: 100 900;
21+
src: url(@fontsource-variable/lexend/files/lexend-latin-wght-normal.woff2)
22+
format("woff2-variations");
23+
unicode-range:
24+
U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
25+
U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212,
26+
U+2215, U+FEFF, U+FFFD;
27+
}
28+
29+
/* jetbrains-mono-latin-ext-wght-normal */
30+
@font-face {
31+
font-family: "JetBrains Mono Variable";
32+
font-style: normal;
33+
font-display: swap;
34+
font-weight: 100 800;
35+
src: url(@fontsource-variable/jetbrains-mono/files/jetbrains-mono-latin-ext-wght-normal.woff2)
36+
format("woff2-variations");
37+
unicode-range:
38+
U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304,
39+
U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB,
40+
U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
41+
}
42+
43+
/* jetbrains-mono-latin-wght-normal */
44+
@font-face {
45+
font-family: "JetBrains Mono Variable";
46+
font-style: normal;
47+
font-display: swap;
48+
font-weight: 100 800;
49+
src: url(@fontsource-variable/jetbrains-mono/files/jetbrains-mono-latin-wght-normal.woff2)
50+
format("woff2-variations");
51+
unicode-range:
52+
U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
53+
U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212,
54+
U+2215, U+FEFF, U+FFFD;
55+
}

0 commit comments

Comments
 (0)