| 1 | import type { UrlResolver } from '@fontsource-utils/core'; |
| 2 | |
| 3 | export const jsDelivrResolver = ( |
| 4 | fontId: string, |
| 5 | variable = false, |
| 6 | ): UrlResolver => { |
| 7 | const prefix = `${fontId}-`; |
| 8 | const packageId = `${fontId}${variable ? ':vf' : ''}@latest`; |
| 9 | |
| 10 | const baseUrl = `https://cdn.jsdelivr.net/fontsource/fonts/${packageId}`; |
| 11 | |
| 12 | return ({ source }) => { |
| 13 | // Strip the font id prefix from filename for our CDN endpoints. |
| 14 | const filename = source.filename.startsWith(prefix) |
| 15 | ? source.filename.slice(prefix.length) |
| 16 | : source.filename; |
| 17 | |
| 18 | return `${baseUrl}/${filename}`; |
| 19 | }; |
| 20 | }; |