You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/en/reference/font-provider-reference.mdx
+97-1Lines changed: 97 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -434,7 +434,7 @@ The preferred method for implementing a custom font provider is to export a func
434
434
435
435
### The font provider object
436
436
437
-
A `FontProvider` is an object containing required [`name`](#name) and [`resolveFont()`](#resolvefont) properties. It also has optional [`config`](#config), [`init()`](#init) and [`listFonts()`](#listfonts) properties available.
437
+
A `FontProvider` is an object containing required [`name`](#name) and [`resolveFont()`](#resolvefont) properties. It also has optional [`config`](#config), [`init()`](#init), [`listFonts()`](#listfonts) and [`getFontProperties()`](#getfontproperties) properties available.
438
438
439
439
The `FontProvider` type accepts a generic for family [options](/en/reference/configuration-reference/#fontoptions).
440
440
@@ -504,6 +504,93 @@ The project root, useful for resolving local files paths.
504
504
505
505
Optional callback, used to return the list of available font names.
Optional callback, used to return the properties a given font family actually supports. Astro compares the values [configured for the family](/en/reference/configuration-reference/#fontname) against these properties, and logs a warning when a provider cannot serve one of them (e.g. a weight that a family does not offer).
517
+
518
+
Return `undefined` when the family is unknown to your provider. Astro will then skip the check for that family.
519
+
520
+
```ts title="font-provider.ts" {6-11}
521
+
import type { FontProvider } from "astro";
522
+
523
+
export function registryFontProvider(): FontProvider {
524
+
return {
525
+
name: "registry",
526
+
getFontProperties: ({ familyName }) => ({
527
+
weights: ["400", "700"],
528
+
styles: ["normal", "italic"],
529
+
subsets: ["latin"],
530
+
formats: ["woff2"]
531
+
}),
532
+
// ...
533
+
};
534
+
}
535
+
```
536
+
537
+
:::note
538
+
Implementing this callback is currently optional, but it will be required in Astro 8.
539
+
:::
540
+
541
+
##### `options.familyName`
542
+
543
+
<p>
544
+
545
+
**Type:** `string`<br />
546
+
</p>
547
+
548
+
The font family name, as identified by your font provider.
549
+
550
+
##### The `FontProperties` object
551
+
552
+
The object returned by `getFontProperties()` describes what your provider can serve for the requested family. All of its properties are optional: any property you omit is understood as "this provider does not expose that information", not as "nothing is available".
553
+
554
+
##### `FontProperties.weights`
555
+
556
+
<p>
557
+
558
+
**Type:** `Array<string> | undefined`<br />
559
+
**Default:** `undefined`<br />
560
+
</p>
561
+
562
+
The [font weights](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight) available for the font family. Values are either individual weights (e.g. `"400"`), or ranges of weights for [variable fonts](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_fonts/Variable_fonts_guide) written as `"<min> <max>"` (e.g. `"100 900"`).
The [font formats](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@font-face/src#font_formats) your provider can serve. This describes your provider's capabilities rather than a single family's, so some of these formats may not exist for every family.
593
+
507
594
### Supporting a private registry
508
595
509
596
The following example defines a font provider for a private registry:
@@ -701,6 +788,9 @@ export function acmeFontProvider(): FontProvider {
0 commit comments