| 4 | import type { Fontlist, FontlistQueries, MetadataList } from './types'; |
| 5 | |
| 6 | const generateFontVariants = ({ |
| 7 | id, |
| 8 | subsets, |
| 9 | weights, |
| 10 | styles, |
| 11 | }: FontMetadata): FontVariants => { |
| 12 | const variants: FontVariants = {}; |
| 13 | |
| 14 | for (const weight of weights) { |
| 15 | variants[weight] = variants[weight] || {}; |
| 16 | |
| 17 | for (const style of styles) { |
| 18 | variants[weight][style] = variants[weight][style] || {}; |
| 19 | |
| 20 | for (const subset of subsets) { |
| 21 | variants[weight][style][subset] = { |
| 22 | url: { |
| 23 | woff2: `https://cdn.jsdelivr.net/fontsource/fonts/${id}@latest/${subset}-${weight}-${style}.woff2`, |
| 24 | woff: `https://cdn.jsdelivr.net/fontsource/fonts/${id}@latest/${subset}-${weight}-${style}.woff`, |
| 25 | ttf: `https://cdn.jsdelivr.net/fontsource/fonts/${id}@latest/${subset}-${weight}-${style}.ttf`, |
| 26 | }, |
| 27 | }; |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | return variants; |
| 33 | }; |
| 34 | |
| 35 | const updateMetadata = async (env: Env, ctx: ExecutionContext) => { |
| 36 | const response = await fetch(METADATA_URL); |