Skip to content

Commit ec475be

Browse files
authored
Merge pull request #670 from DuendeSoftware/google-fonts
Use Astro's experimental fonts for Roboto
2 parents 86aab89 + b5b998f commit ec475be

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

astro.config.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @ts-check
2-
import { defineConfig } from "astro/config";
2+
import { defineConfig, fontProviders } from "astro/config";
33
import starlight from "@astrojs/starlight";
44
import starlightLinksValidator from "starlight-links-validator";
55
import starlightClientMermaid from "@pasqal-io/starlight-client-mermaid";
@@ -18,6 +18,18 @@ export default defineConfig({
1818
site: "https://docs.duendesoftware.com",
1919
trailingSlash: "ignore",
2020
redirects: {},
21+
experimental: {
22+
fonts: [
23+
{
24+
provider: fontProviders.google(),
25+
name: "Roboto",
26+
cssVariable: "--font-roboto",
27+
weights: ["100 900", "bold"],
28+
styles: ["normal", "italic"],
29+
display: "swap",
30+
},
31+
],
32+
},
2133
integrations: [
2234
starlight({
2335
customCss: ["./src/styles/custom.css"],

src/components/Head.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
import { getImagePath } from "astro-opengraph-images";
3+
import { Font } from "astro:assets";
34
45
const { head } = Astro.locals.starlightRoute;
56
const { url, site } = Astro;
@@ -8,4 +9,4 @@ const openGraphImageUrl = getImagePath({ url, site });
89

910
{head.map(({ tag: Tag, attrs, content }) => <Tag {...attrs} set:html={content} />)}
1011
{openGraphImageUrl && (<meta property="og:image" content={openGraphImageUrl} />)}
11-
12+
<Font cssVariable="--font-roboto" preload />

src/styles/custom.css

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
/* Font */
2-
@import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100..900;1,100..900&display=swap');
3-
41
/* Dark mode colors. */
52
:root {
6-
--sl-font: 'Roboto';
3+
/* coming from Astro Font support. See astro.config.mjs */
4+
/*noinspection CssUnresolvedCustomProperty*/
5+
--sl-font: var(--font-roboto);
76
--sl-color-accent-low: #43257c;
87
--sl-color-accent: #6e45af;
98
--sl-color-accent-high: #916bdb;

0 commit comments

Comments
 (0)