a tool for shared writing and social publishing

handle italic for already published custom font themes

+30 -1
+30 -1
src/fonts.ts
··· 147 147 return { fontName, googleFontsFamily }; 148 148 } 149 149 150 + // Ensure a Google Fonts family string includes italic variants and standard weights. 151 + // Handles already-stored custom font IDs that may only specify upright weights. 152 + function ensureItalicWeights(googleFontsFamily: string): string { 153 + const [name, spec] = googleFontsFamily.split(/:(.+)/); 154 + if (!name) return googleFontsFamily; 155 + 156 + // Already includes italic axis — leave as-is 157 + if (spec && spec.includes("ital")) return googleFontsFamily; 158 + 159 + // Has wght@ with values — add italic variants for each weight 160 + if (spec) { 161 + const wghtMatch = spec.match(/wght@(.+)/); 162 + if (wghtMatch) { 163 + const weights = wghtMatch[1]; 164 + // Variable range like 400..700 165 + if (weights.includes("..")) { 166 + return `${name}:ital,wght@0,${weights};1,${weights}`; 167 + } 168 + // Discrete weights like 400;700 169 + const uprightWeights = weights.split(";").map((w) => `0,${w}`); 170 + const italicWeights = weights.split(";").map((w) => `1,${w}`); 171 + return `${name}:ital,wght@${[...uprightWeights, ...italicWeights].join(";")}`; 172 + } 173 + } 174 + 175 + // No weight spec at all — add standard weights with italics 176 + return `${name}:ital,wght@0,400;0,700;1,400;1,700`; 177 + } 178 + 150 179 export function getFontConfig(fontId: string | undefined): FontConfig { 151 180 if (!fontId) return fonts[defaultFontId]; 152 181 ··· 159 188 displayName: parsed.fontName, 160 189 fontFamily: parsed.fontName, 161 190 type: "google", 162 - googleFontsFamily: parsed.googleFontsFamily, 191 + googleFontsFamily: ensureItalicWeights(parsed.googleFontsFamily), 163 192 fallback: ["system-ui", "sans-serif"], 164 193 }; 165 194 }