| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,7 +90,18 @@ export default defineFontProvider('fontshare', async (_options, ctx) => { | |||
| 90 | 90 | ||
| 91 | 91 | const css = await ctx.fetch(`${BASE_URL}/css?f[]=${font.slug}@${numbers.join(',')}`).then(res => res.text()) | |
| 92 | 92 | ||
| 93 | - return cleanFontFaces(extractFontFaceData(css), options.formats) | ||
| 93 | + const fontFaces = extractFontFaceData(css) | ||
| 94 | + for (const face of fontFaces) { | ||
| 95 | + for (const source of face.src) { | ||
| 96 | + // fontshare serves protocol-relative URLs, which are only resolvable from within a | ||
| 97 | + // stylesheet loaded over http(s) | ||
| 98 | + if ('url' in source && source.url.startsWith('//')) { | ||
| 99 | + source.url = `https:${source.url}` | ||
| 100 | + } | ||
| 101 | + } | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + return cleanFontFaces(fontFaces, options.formats) | ||
| 94 | 105 | } | |
| 95 | 106 | ||
| 96 | 107 | return { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,7 @@ describe('fontshare', () => { | |||
| 19 | 19 | "src": [ | |
| 20 | 20 | { | |
| 21 | 21 | "format": "woff2", | |
| 22 | - "url": "//cdn.fontshare.com/font", | ||
| 22 | + "url": "https://cdn.fontshare.com/font", | ||
| 23 | 23 | }, | |
| 24 | 24 | ], | |
| 25 | 25 | "style": "normal", | |
@@ -41,7 +41,7 @@ describe('fontshare', () => { | |||
| 41 | 41 | "src": [ | |
| 42 | 42 | { | |
| 43 | 43 | "format": "woff2", | |
| 44 | - "url": "//cdn.fontshare.com/font", | ||
| 44 | + "url": "https://cdn.fontshare.com/font", | ||
| 45 | 45 | }, | |
| 46 | 46 | ], | |
| 47 | 47 | "style": "italic", | |
@@ -51,6 +51,15 @@ describe('fontshare', () => { | |||
| 51 | 51 | `) | |
| 52 | 52 | }) | |
| 53 | 53 | ||
| 54 | + it('returns absolute font URLs', async () => { | ||
| 55 | + const unifont = await createUnifont([providers.fontshare()]) | ||
| 56 | + const { fonts } = await unifont.resolveFont('Satoshi', { styles: ['normal'] }) | ||
| 57 | + const urls = fonts.flatMap(font => font.src.flatMap(source => 'url' in source ? source.url : [])) | ||
| 58 | + | ||
| 59 | + expect(urls.length).toBeGreaterThan(0) | ||
| 60 | + expect(urls.every(url => url.startsWith('https://'))).toBe(true) | ||
| 61 | + }) | ||
| 62 | + | ||
| 54 | 63 | it('supports variable fonts', async () => { | |
| 55 | 64 | const unifont = await createUnifont([providers.fontshare()]) | |
| 56 | 65 | const { fonts } = await unifont.resolveFont('Satoshi', { weights: ['300 900'] }) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments