@xingwangzhe/stalux 1.5.3 → 1.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xingwangzhe/stalux",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "description": "A powerful, modern Astro blog theme \u2014 use as template or install as plugin",
5
5
  "keywords": [
6
6
  "astro",
@@ -357,79 +357,64 @@ export async function runFontSubsetting(
357
357
  const postMap: Record<string, string> = {};
358
358
 
359
359
  let subsetCount = 0;
360
- const cssGenerated = new Set<string>();
361
-
362
- if (!skipPerRoute) {
363
- for (const [hash, routes] of groups) {
364
- const filename = `subset-${hash}.ttf`;
365
- const outPath = join(outDir, filename);
366
- if (!existsSync(outPath)) {
367
- const route = routeSets.find((r) => r.hash === hash);
368
- const chars = route?.chars ?? "";
369
- const uniqueChars = chars
370
- .split("")
371
- .filter((ch) => !commonChars.includes(ch))
372
- .join("");
373
- if (uniqueChars.length > 0) {
374
- const glyphs = get_glyph_ids(uniqueChars, "stalux", "normal", 400);
375
- if (glyphs.length > 0) {
376
- const result = subset_font_full("stalux", "normal", 400, 0, glyphs);
377
- writeFileSync(outPath, result.fontBytes);
378
- subsetCount++;
379
- logger.info(
380
- ` subset ${subsetCount}: ${(result.fontBytes.length / 1024).toFixed(1)} KB → ${filename}`,
381
- );
360
+
361
+ if (!skipPerRoute) {
362
+ for (const [hash, routes] of groups) {
363
+ const filename = `subset-${hash}.ttf`;
364
+ const outPath = join(outDir, filename);
365
+ if (!existsSync(outPath)) {
366
+ const route = routeSets.find((r) => r.hash === hash);
367
+ const chars = route?.chars ?? "";
368
+ const uniqueChars = chars
369
+ .split("")
370
+ .filter((ch) => !commonChars.includes(ch))
371
+ .join("");
372
+ if (uniqueChars.length > 0) {
373
+ const glyphs = get_glyph_ids(uniqueChars, "stalux", "normal", 400);
374
+ if (glyphs.length > 0) {
375
+ const result = subset_font_full("stalux", "normal", 400, 0, glyphs);
376
+ writeFileSync(outPath, result.fontBytes);
377
+ subsetCount++;
378
+ logger.info(
379
+ ` subset ${subsetCount}: ${(result.fontBytes.length / 1024).toFixed(1)} KB → ${filename}`,
380
+ );
381
+ }
382
382
  }
383
383
  }
384
- }
385
384
 
386
- // Generate per-route CSS (one per unique hash, references all routes with this hash)
387
- if (!cssGenerated.has(hash)) {
388
- cssGenerated.add(hash);
385
+ // Generate per-route CSS (each route gets its own CSS file)
386
+ // If no unique chars, reference the common TTF as fallback
387
+ const refTtf = existsSync(outPath) ? filename : commonFilename;
389
388
  for (const route of routes) {
390
389
  const cssContent = `/* Auto-generated font subset for route: ${route} */
391
390
  @font-face {
392
391
  font-family: "LXGW WenKai Subset";
393
- src: url("/fonts/${filename}") format("truetype");
392
+ src: url("/fonts/${refTtf}") format("truetype");
394
393
  font-display: swap;
395
394
  }
396
395
  `;
397
- // Use first route's name as the CSS filename (they share the same subset)
398
- const cssName = routes.length === 1 ? route.replace("/", "-") : `group-${hash}`;
399
- const cssFilename = `subset-${cssName}.css`;
400
- writeFileSync(join(outDir, cssFilename), cssContent);
401
- routeMap[route] = cssFilename;
402
-
403
- if (route.startsWith("posts/")) {
404
- const abbrlink = route.replace("posts/", "");
405
- postMap[abbrlink] = cssFilename;
406
- }
407
- }
408
- } else {
409
- // CSS already generated, just map
410
- for (const route of routes) {
411
- const cssFilename =
412
- routes.length === 1
413
- ? `subset-${route.replace("/", "-")}.css`
414
- : `subset-group-${hash}.css`;
415
- routeMap[route] = cssFilename;
416
- if (route.startsWith("posts/")) {
417
- postMap[route.replace("posts/", "")] = cssFilename;
418
- }
396
+ const cssName = route.replace("/", "-");
397
+ const cssFilename = `subset-${cssName}.css`;
398
+ writeFileSync(join(outDir, cssFilename), cssContent);
399
+ routeMap[route] = cssFilename;
400
+
401
+ if (route.startsWith("posts/")) {
402
+ const abbrlink = route.replace("posts/", "");
403
+ postMap[abbrlink] = cssFilename;
419
404
  }
420
405
  }
421
406
  }
422
- }
423
407
 
424
- // 6. Generate manifest
425
- const manifest: FontManifest = {
426
- common: commonFilename,
427
- routes: routeMap,
428
- posts: postMap,
429
- };
430
- writeFileSync(join(outDir, "manifest.json"), JSON.stringify(manifest, null, 2));
431
-
432
- logger.info(
433
- `Font subsetting done: ${subsetCount} route subsets + common (${(fontBuffer.length / 1024 / 1024).toFixed(1)} MB → variable)`,
434
- );
408
+ // 6. Generate manifest
409
+ const manifest: FontManifest = {
410
+ common: commonFilename,
411
+ routes: routeMap,
412
+ posts: postMap,
413
+ };
414
+ writeFileSync(join(outDir, "manifest.json"), JSON.stringify(manifest, null, 2));
415
+
416
+ logger.info(
417
+ `Font subsetting done: ${subsetCount} route subsets + common (${(fontBuffer.length / 1024 / 1024).toFixed(1)} MB → variable)`,
418
+ );
419
+ }
435
420
  }