tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
27
pulls
pipelines
handle italic for already published custom font themes
awarm.space
1 day ago
2520133e
8a00c9de
+30
-1
1 changed file
expand all
collapse all
unified
split
src
fonts.ts
+30
-1
src/fonts.ts
···
147
147
return { fontName, googleFontsFamily };
148
148
}
149
149
150
150
+
// Ensure a Google Fonts family string includes italic variants and standard weights.
151
151
+
// Handles already-stored custom font IDs that may only specify upright weights.
152
152
+
function ensureItalicWeights(googleFontsFamily: string): string {
153
153
+
const [name, spec] = googleFontsFamily.split(/:(.+)/);
154
154
+
if (!name) return googleFontsFamily;
155
155
+
156
156
+
// Already includes italic axis — leave as-is
157
157
+
if (spec && spec.includes("ital")) return googleFontsFamily;
158
158
+
159
159
+
// Has wght@ with values — add italic variants for each weight
160
160
+
if (spec) {
161
161
+
const wghtMatch = spec.match(/wght@(.+)/);
162
162
+
if (wghtMatch) {
163
163
+
const weights = wghtMatch[1];
164
164
+
// Variable range like 400..700
165
165
+
if (weights.includes("..")) {
166
166
+
return `${name}:ital,wght@0,${weights};1,${weights}`;
167
167
+
}
168
168
+
// Discrete weights like 400;700
169
169
+
const uprightWeights = weights.split(";").map((w) => `0,${w}`);
170
170
+
const italicWeights = weights.split(";").map((w) => `1,${w}`);
171
171
+
return `${name}:ital,wght@${[...uprightWeights, ...italicWeights].join(";")}`;
172
172
+
}
173
173
+
}
174
174
+
175
175
+
// No weight spec at all — add standard weights with italics
176
176
+
return `${name}:ital,wght@0,400;0,700;1,400;1,700`;
177
177
+
}
178
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
162
-
googleFontsFamily: parsed.googleFontsFamily,
191
191
+
googleFontsFamily: ensureItalicWeights(parsed.googleFontsFamily),
163
192
fallback: ["system-ui", "sans-serif"],
164
193
};
165
194
}