Skip to content

Commit 2c1ae85

Browse files
fix(fonts): invalid dev url with oblique style and angles (#16075)
1 parent b089b90 commit 2c1ae85

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

.changeset/tired-worlds-dream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fixes a case where invalid URLs would be generated in development when using font families with an oblique `style` and angles

packages/astro/src/assets/fonts/infra/dev-font-file-id-generator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export class DevFontFileIdGenerator implements FontFileIdGenerator {
2727
return weight?.replace(/\s+/g, '-');
2828
}
2929

30+
#formatStyle(style: unifont.FontFaceData['style']): string | undefined {
31+
return style?.replace(/\s+/g, '-')
32+
}
33+
3034
generate({
3135
cssVariable,
3236
originalUrl,
@@ -41,7 +45,7 @@ export class DevFontFileIdGenerator implements FontFileIdGenerator {
4145
return [
4246
cssVariable.slice(2),
4347
this.#formatWeight(font.weight),
44-
font.style,
48+
this.#formatStyle(font.style),
4549
font.meta?.subset,
4650
`${this.#hasher.hashString(this.#contentResolver.resolve(originalUrl))}.${type}`,
4751
]

packages/astro/test/units/assets/fonts/infra.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,15 @@ describe('fonts infra', () => {
409409
}),
410410
'foo-200-700-italic-cyrillic-whatever.woff2',
411411
);
412+
assert.equal(
413+
resolver.generate({
414+
cssVariable: '--foo',
415+
font: { weight: '500', style: 'oblique 0deg 15deg', meta: { subset: 'latin' }, src: [] },
416+
originalUrl: 'whatever',
417+
type: 'woff2',
418+
}),
419+
'foo-500-oblique-0deg-15deg-latin-whatever.woff2',
420+
);
412421
});
413422

414423
describe('UnifontFontResolver', () => {

0 commit comments

Comments
 (0)