pug-site-core 2.0.14 → 2.0.16

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/lib/generate.js CHANGED
@@ -272,7 +272,7 @@ export async function fetchDataToJsonFile(args) {
272
272
  return Promise.reject(new Error(obj.getDataFn + "获取数据函数不存在"));
273
273
  }
274
274
 
275
- if (filterFun.length && !filterFun.includes(obj.getDataFn)) {
275
+ if (!isFillFun(obj.getDataFn)) {
276
276
  continue;
277
277
  }
278
278
 
@@ -282,6 +282,13 @@ export async function fetchDataToJsonFile(args) {
282
282
  await checkData(data, language, obj.getDataFn);
283
283
  let outPutPath = obj.outPutPath.split("/").join(pathSymbol);
284
284
  if (Array.isArray(data)) {
285
+ await fse.remove(
286
+ paths.resolveRoot(
287
+ "jsonData",
288
+ language,
289
+ ...outPutPath.split(pathSymbol).slice(0, -1)
290
+ )
291
+ );
285
292
  let name = outPutPath.split(pathSymbol).pop().replace(/\..*$/, "");
286
293
  const regex = /^\[.+\]$/;
287
294
  if (regex.test(name)) {
@@ -321,7 +328,7 @@ export async function fetchDataToJsonFile(args) {
321
328
  return Promise.reject(new Error(`${funName} 获取数据函数不存在`));
322
329
  }
323
330
 
324
- if (filterFun.length && !filterFun.includes(funName)) {
331
+ if (!isFillFun(funName)) {
325
332
  continue;
326
333
  }
327
334
 
@@ -330,6 +337,9 @@ export async function fetchDataToJsonFile(args) {
330
337
  let data = await getData[funName](language);
331
338
  await checkData(data, language, funName);
332
339
  if (Array.isArray(data)) {
340
+ await fse.remove(
341
+ paths.resolveRoot("jsonData", language, ...jsonFilePath.slice(0, -1))
342
+ );
333
343
  await async.eachLimit(data, 12, async (item, index) => {
334
344
  let lastJsonFilePath;
335
345
  if (item.page_name) {
package/lib/imagemin.js CHANGED
@@ -74,6 +74,11 @@ export async function compressImages(inputPath, quality = 0.7) {
74
74
  return acc;
75
75
  }, {});
76
76
 
77
+ // 统计所有图片压缩前后的总大小
78
+ let totalAllOriginalSize = 0;
79
+ let totalAllCompressedSize = 0;
80
+ let totalProcessedFiles = 0;
81
+
77
82
  // 处理每个目录中的图片
78
83
  for (const [dir, files] of Object.entries(filesByDir)) {
79
84
  const relativeDir = path.relative(stats.isFile() ? path.dirname(targetPath) : targetPath, dir);
@@ -94,7 +99,8 @@ export async function compressImages(inputPath, quality = 0.7) {
94
99
  continue;
95
100
  }
96
101
 
97
- console.log(`处理目录: ${relativeDir || '.'}`);
102
+ // 显示当前处理的目录的绝对路径
103
+ console.log(`处理目录: ${dir}`);
98
104
 
99
105
  // 压缩图片
100
106
  await imagemin(validFiles, {
@@ -133,7 +139,10 @@ export async function compressImages(inputPath, quality = 0.7) {
133
139
  if (originalSize > 0 && compressedSize > 0) {
134
140
  totalOriginalSize += originalSize;
135
141
  totalCompressedSize += compressedSize;
142
+ totalAllOriginalSize += originalSize;
143
+ totalAllCompressedSize += compressedSize;
136
144
  processedFiles++;
145
+ totalProcessedFiles++;
137
146
 
138
147
  const savingPercent = ((originalSize - compressedSize) / originalSize * 100).toFixed(2);
139
148
  console.log(` ${path.basename(file)}: ${formatBytes(originalSize)} → ${formatBytes(compressedSize)} (节省 ${savingPercent}%)`);
@@ -149,6 +158,14 @@ export async function compressImages(inputPath, quality = 0.7) {
149
158
 
150
159
  const endTime = Date.now();
151
160
  console.log(`图片压缩完成,共处理 ${imageFiles.length} 个文件,耗时 ${(endTime - startTime) / 1000} 秒`);
161
+
162
+ // 输出所有图片的总体压缩情况
163
+ if (totalProcessedFiles > 0) {
164
+ const totalAllSavingPercent = ((totalAllOriginalSize - totalAllCompressedSize) / totalAllOriginalSize * 100).toFixed(2);
165
+ const savedSize = formatBytes(Math.abs(totalAllOriginalSize - totalAllCompressedSize));
166
+ console.log(`总体压缩情况: ${formatBytes(totalAllOriginalSize)} → ${formatBytes(totalAllCompressedSize)}`);
167
+ console.log(`共节省: ${savedSize} (${totalAllSavingPercent}%)`);
168
+ }
152
169
  } catch (error) {
153
170
  console.error('图片压缩失败:', error);
154
171
  throw error;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "pug-site-core",
3
- "version": "2.0.14",
3
+ "version": "2.0.16",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {
7
- "dev": "nodemon --ext js --ignore node_modules/ --ignore template/ index.js",
7
+ "dev": "nodemon --ignore jsonData/ --ignore node_modules/ --ignore template/ --ext js index.js",
8
8
  "getData": "node index.js",
9
9
  "getFun": "node index.js",
10
10
  "compileFn": "node index.js",
@@ -45,7 +45,7 @@
45
45
  "imagemin-svgo": "^10.0.1"
46
46
  },
47
47
  "license": "ISC",
48
- "description": "图片压缩模块导出问题",
48
+ "description": "修复带getData排除函数参数时无法删掉以前json文件问题、优化代码",
49
49
  "files": [
50
50
  "lib/",
51
51
  "index.js"