Skip to content

Commit 457f910

Browse files
authored
Use Astro’s experimental API for font loading (#29)
1 parent 701277c commit 457f910

File tree

6 files changed

+17
-23
lines changed

6 files changed

+17
-23
lines changed

astro.config.mjs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineConfig } from 'astro/config';
1+
import { defineConfig, fontProviders } from 'astro/config';
22
import db from '@astrojs/db';
33
import preact from '@astrojs/preact';
44
import sitemap from '@astrojs/sitemap';
@@ -31,7 +31,19 @@ export default defineConfig({
3131
inlineStylesheets: 'always'
3232
},
3333
experimental: {
34-
clientPrerender: true
34+
clientPrerender: true,
35+
fonts: [
36+
{
37+
provider: fontProviders.google({
38+
experimental: { variableAxis: { Inter: { opsz: ['14..32'] } } }
39+
}),
40+
name: 'Inter',
41+
cssVariable: '--astro-font-inter',
42+
weights: ['300 900'],
43+
styles: ['normal'],
44+
subsets: ['latin']
45+
}
46+
]
3547
},
3648
image: {
3749
remotePatterns: [

public/fonts/InterVariable.woff2

-344 KB
Binary file not shown.

src/layouts/Layout.astro

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
import { Font } from 'astro:assets';
23
import { ClientRouter } from 'astro:transitions';
34
import { Schema } from 'astro-seo-schema';
45
@@ -93,13 +94,7 @@ const description = Astro.props.description ?? starpodConfig.description;
9394

9495
<link rel="preload" as="image" href={show.image} />
9596

96-
<link
97-
crossorigin
98-
rel="preload"
99-
href="/fonts/InterVariable.woff2"
100-
as="font"
101-
type="font/woff2"
102-
/>
97+
<Font cssVariable="--astro-font-inter" preload />
10398

10499
<Schema
105100
slot="head"

src/styles/fonts.css

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/styles/global.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@import './fonts.css';
21
@import './tailwind.css';
32
@import './gradient-icon.css';
43
@import './buttons.css';

src/styles/tailwind.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
--color-light-text-body: oklch(59.68% 0.017 285.89);
3737
--color-light-text-heading: oklch(30.55% 0.052 292.57);
3838

39-
--font-inter: Inter, sans-serif;
39+
--font-inter: var(--astro-font-inter);
4040
}
4141

4242
/*

0 commit comments

Comments
 (0)