Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/font-data-subset-field.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': minor
---

Adds a `subset` field to the `FontData` type exposed via `fontData` from `astro:assets`. When using multiple font subsets (e.g., `subsets: ["latin", "korean"]`), each font data entry now includes the subset name, making it possible to distinguish between font entries for different subsets that share the same weight and style.
1 change: 1 addition & 0 deletions packages/astro/src/assets/fonts/core/collect-font-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function collectFontData(
fontData.push({
weight: renderFontWeight(data.weight),
style: data.style,
subset: data.meta?.subset,
src: data.src
.filter((src) => 'url' in src)
.map((src) => ({
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/assets/fonts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export interface FontData {
src: Array<{ url: string; format?: string; tech?: string }>;
weight?: string;
style?: string;
subset?: string;
}

/**
Expand Down
55 changes: 55 additions & 0 deletions packages/astro/test/units/assets/fonts/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,7 @@ describe('fonts core', () => {
},
],
style: 'normal',
subset: undefined,
weight: '400',
},
{
Expand All @@ -1193,6 +1194,7 @@ describe('fonts core', () => {
},
],
style: 'italic',
subset: undefined,
weight: '500',
},
],
Expand All @@ -1206,6 +1208,59 @@ describe('fonts core', () => {
},
],
style: 'normal',
subset: undefined,
weight: '400',
},
],
},
);
});

it('collectFontData() includes subset from meta', () => {
assert.deepStrictEqual(
collectFontData([
{
family: { cssVariable: '--font' },
fonts: [
{
weight: '400',
style: 'normal',
src: [{ url: 'latin-400.woff2', format: 'woff2' }],
meta: { subset: 'latin' },
},
{
weight: '400',
style: 'normal',
src: [{ url: 'korean-400.woff2', format: 'woff2' }],
meta: { subset: 'korean' },
},
],
},
]),
{
'--font': [
{
src: [
{
format: 'woff2',
tech: undefined,
url: 'latin-400.woff2',
},
],
style: 'normal',
subset: 'latin',
weight: '400',
},
{
src: [
{
format: 'woff2',
tech: undefined,
url: 'korean-400.woff2',
},
],
style: 'normal',
subset: 'korean',
weight: '400',
},
],
Expand Down
6 changes: 6 additions & 0 deletions packages/astro/test/units/assets/fonts/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ describe('Fonts E2E', () => {
},
],
style: 'normal',
subset: 'latin',
weight: '700',
},
{
Expand All @@ -181,6 +182,7 @@ describe('Fonts E2E', () => {
},
],
style: 'italic',
subset: 'latin',
weight: '700',
},
],
Expand All @@ -194,6 +196,7 @@ describe('Fonts E2E', () => {
},
],
style: 'normal',
subset: undefined,
weight: '400',
},
],
Expand Down Expand Up @@ -306,6 +309,7 @@ describe('Fonts E2E', () => {
},
],
style: 'normal',
subset: 'latin',
weight: '500',
},
{
Expand All @@ -317,6 +321,7 @@ describe('Fonts E2E', () => {
},
],
style: 'italic',
subset: 'latin',
weight: '700',
},
],
Expand All @@ -330,6 +335,7 @@ describe('Fonts E2E', () => {
},
],
style: 'normal',
subset: undefined,
weight: '400',
},
],
Expand Down
Loading