MCPcopy Create free account
hub / github.com/fontsource/fontsource / generateFontVariants

Function generateFontVariants

api/metadata/src/fontlist/update.ts:6–33  ·  view source on GitHub ↗
({
	id,
	subsets,
	weights,
	styles,
}: FontMetadata)

Source from the content-addressed store, hash-verified

4import type { Fontlist, FontlistQueries, MetadataList } from './types';
5
6const 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
35const updateMetadata = async (env: Env, ctx: ExecutionContext) => {
36 const response = await fetch(METADATA_URL);

Callers 1

updateMetadataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected