hexo-swpp 2.3.2 → 2.3.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.
@@ -185,7 +185,14 @@ module.exports = (hexo, config, pluginConfig, swRules) => {
185
185
  Promise.all(taskList).then(() => {
186
186
  // noinspection JSUnresolvedVariable
187
187
  const publicRoot = config.public_dir
188
- fs.writeFileSync(nodePath.join(publicRoot, path), JSON.stringify(result), 'utf-8')
188
+ fs.writeFileSync(
189
+ nodePath.join(publicRoot, path),
190
+ JSON.stringify({
191
+ version: 1,
192
+ list: result
193
+ }),
194
+ 'utf-8'
195
+ )
189
196
  logger.info(`Generated: ${path}`)
190
197
  resolve(result)
191
198
  })
@@ -243,8 +250,11 @@ module.exports = (hexo, config, pluginConfig, swRules) => {
243
250
  const compare = (oldCache, newCache) => {
244
251
  const result = []
245
252
  if (!oldCache) return result
253
+ const refresh = oldCache.version !== newCache.version
254
+ if (refresh) return false
255
+ if (oldCache.version) oldCache = oldCache.list
246
256
  for (let path in oldCache) {
247
- if (newCache[path] !== oldCache[path]) result.push(path)
257
+ if (newCache.list[path] !== oldCache[path]) result.push(path)
248
258
  }
249
259
  return result
250
260
  }
@@ -316,14 +326,14 @@ module.exports = (hexo, config, pluginConfig, swRules) => {
316
326
  }
317
327
  // 整理更新的数据
318
328
  const tidied = tidyDiff(dif, expand)
319
- if (expand?.all) return writeJson({
329
+ if (expand?.all || tidied.all) return writeJson({
320
330
  global: (oldUpdate?.global ?? 0) + (tidied.updateGlobal ? 1 : 0),
321
- info: [newInfo]
331
+ info: [{version: newInfo.version}]
322
332
  })
323
333
  // 如果没有更新的文件就直接退出
324
334
  if (
325
335
  tidied.page.size === 0 && tidied.file.size === 0 &&
326
- !(tidied.archives || tidied.categories || tidied.tags || tidied.index)
336
+ !(tidied.archives || tidied.categories || tidied.tags || tidied.index || Object.keys(tidied.custom).length !== 0)
327
337
  ) return writeJson(oldUpdate ?? {
328
338
  global: 0,
329
339
  info: [{version: 0}]
@@ -358,7 +368,7 @@ module.exports = (hexo, config, pluginConfig, swRules) => {
358
368
  return result
359
369
  }
360
370
 
361
- // 压缩相同项目
371
+ // 压缩相同项目
362
372
  const zipInfo = (newInfo, oldInfo) => {
363
373
  oldInfo = oldInfo.change
364
374
  newInfo = newInfo.change
@@ -389,7 +399,7 @@ module.exports = (hexo, config, pluginConfig, swRules) => {
389
399
  return result.length === 0 ? undefined : result
390
400
  }
391
401
 
392
- // 将更新推送到 info
402
+ // 将更新推送到 info
393
403
  const pushUpdateToInfo = (info, tidied) => {
394
404
  const merges = [] // 要合并的更新
395
405
  // 推送页面更新
@@ -422,7 +432,7 @@ module.exports = (hexo, config, pluginConfig, swRules) => {
422
432
  }
423
433
  }
424
434
 
425
- // 将 diff 整理分类
435
+ // 将 diff 整理分类
426
436
  const tidyDiff = (dif, expand) => {
427
437
  const tidied = {
428
438
  /** 所有 HTML 页面 */
@@ -440,12 +450,18 @@ module.exports = (hexo, config, pluginConfig, swRules) => {
440
450
  /** 自定义配置项 */
441
451
  custom: {},
442
452
  /** 标记是否更新 global 版本号 */
443
- updateGlobal: expand?.global
453
+ updateGlobal: expand?.global,
454
+ /** 是否刷新全部缓存 */
455
+ all: false
456
+ }
457
+ if (!dif) {
458
+ tidied.all = tidied.updateGlobal = true
459
+ return tidied
444
460
  }
445
461
  // noinspection JSUnresolvedVariable
446
462
  const mode = pluginConfig.json?.precisionMode
447
463
  for (let it of dif) {
448
- const url = new URL(nodePath.join(root, it)) // 当前文件的 URL
464
+ const url = new URL(it.match(/^(https?|\/\/)/) ? it : nodePath.join(root, it)) // 当前文件的 URL
449
465
  const cache = findCache(url) // 查询缓存
450
466
  if (!cache) {
451
467
  logger.error(`[buildUpdate] 指定 URL(${url.pathname}) 未查询到缓存规则!`)
@@ -69,7 +69,7 @@
69
69
 
70
70
  /** 判断指定url击中了哪一种缓存,都没有击中则返回null */
71
71
  function findCache(url) {
72
- if (url.host === 'localhost') return
72
+ if (url.hostname === 'localhost') return
73
73
  for (let key in cacheList) {
74
74
  const value = cacheList[key]
75
75
  if (value.match(url)) return value
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-swpp",
3
- "version": "2.3.2",
3
+ "version": "2.3.4",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "hexo-log": "^3.0.0",