hexo-swpp 1.3.5 → 1.4.1

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/README.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
    具体说明见:[小白也能用的 SW 构建插件 - 山岳库博](https://kmar.top/posts/73014407/)
4
4
 
5
-   `1.2.0`之前的版本存在功能缺陷,请勿使用!
5
+   `1.4.0`之前的版本存在功能缺陷,请勿使用!
package/index.js CHANGED
@@ -38,13 +38,15 @@ if (pluginConfig?.enable) {
38
38
  const absPath = module.path + '/sw-template.js'
39
39
  const rootPath = nodePath.resolve('./')
40
40
  const relativePath = nodePath.relative(rootPath, absPath)
41
- const template = fs.readFileSync(relativePath, 'utf8')
42
41
  const cache = fs.readFileSync('sw-cache.js', 'utf8')
43
42
  .replaceAll('module.exports.cacheList', 'const cacheList')
44
43
  .replaceAll('module.exports.replaceList', 'const replaceList')
44
+ const swContent = fs.readFileSync(relativePath, 'utf8')
45
+ .replaceAll('const { cacheList, replaceList } = require(\'../sw-cache\')', cache)
46
+ .replaceAll("'@$$[escape]'", (pluginConfig.escape ?? 0).toString())
45
47
  return {
46
48
  path: 'sw.js',
47
- data: template.replaceAll('const { cacheList, replaceList } = require(\'../sw-cache\')', cache)
49
+ data: swContent
48
50
  }
49
51
  })
50
52
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-swpp",
3
- "version": "1.3.5",
3
+ "version": "1.4.1",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "hexo-log": "^3.0.0",
package/sw-dom.js CHANGED
@@ -35,7 +35,7 @@
35
35
  if (sessionStorage.getItem('updated')) {
36
36
  // ${onSuccess}
37
37
  sessionStorage.removeItem('updated')
38
- } else setTimeout(() => postMessage2SW('update'), 1000)
38
+ } else postMessage2SW('update')
39
39
  navigator.serviceWorker.addEventListener('message', event => {
40
40
  const data = event.data
41
41
  switch (data.type) {
@@ -65,4 +65,4 @@
65
65
  break
66
66
  }
67
67
  })
68
- })
68
+ })()
package/sw-template.js CHANGED
@@ -171,7 +171,7 @@
171
171
  dbVersion.write(JSON.stringify(newVersion))
172
172
  return resolve(newVersion)
173
173
  }
174
- const refresh = parseChange(list, elementList, oldVersion.local)
174
+ const refresh = oldVersion.local < '@$$[escape]' ? true : parseChange(list, elementList, oldVersion.local)
175
175
  dbVersion.write(JSON.stringify(newVersion))
176
176
  //如果需要清理全站
177
177
  if (refresh) {