@xingwangzhe/stalux 1.4.4 → 1.4.6
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
|
@@ -155,7 +155,8 @@ async function generateSubsetOnDemand(
|
|
|
155
155
|
export function createDevFontMiddleware(projectRoot: string, logger: AstroIntegrationLogger) {
|
|
156
156
|
return async (req: any, res: any, next: any) => {
|
|
157
157
|
const url = req.url || "";
|
|
158
|
-
const
|
|
158
|
+
const pathname = url.split("?")[0].split("#")[0];
|
|
159
|
+
const match = pathname.match(/^\/fonts\/subset-(.+)\.css$/);
|
|
159
160
|
if (!match) return next();
|
|
160
161
|
|
|
161
162
|
const subsetId = match[1];
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import { createHash } from "node:crypto";
|
|
19
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync } from "node:fs";
|
|
19
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync, unlinkSync } from "node:fs";
|
|
20
20
|
import { resolve, basename, extname, join, dirname } from "node:path";
|
|
21
21
|
import { fileURLToPath } from "node:url";
|
|
22
22
|
|
|
@@ -263,6 +263,16 @@ export async function runFontSubsetting(
|
|
|
263
263
|
}
|
|
264
264
|
const fontBuffer = readFileSync(fontPath);
|
|
265
265
|
|
|
266
|
+
// Clean old generated font files to avoid stale cached references
|
|
267
|
+
const outDir = resolve(projectRoot, FONT_OUT_DIR);
|
|
268
|
+
if (existsSync(outDir)) {
|
|
269
|
+
for (const f of readdirSync(outDir)) {
|
|
270
|
+
if (f.startsWith("common-") || f.startsWith("subset-")) {
|
|
271
|
+
try { unlinkSync(join(outDir, f)); } catch { /* skip */ }
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
266
276
|
// 2. Scan content files
|
|
267
277
|
const contentFiles = scanContent(projectRoot);
|
|
268
278
|
logger.info(`Font subsetting: found ${contentFiles.length} content files`);
|
|
@@ -289,7 +299,6 @@ export async function runFontSubsetting(
|
|
|
289
299
|
}
|
|
290
300
|
|
|
291
301
|
// 5. Deduplicate and generate subsets
|
|
292
|
-
const outDir = resolve(projectRoot, FONT_OUT_DIR);
|
|
293
302
|
mkdirSync(outDir, { recursive: true });
|
|
294
303
|
|
|
295
304
|
// Dynamic import subset-font (ESM only)
|