hexo-swpp 2.3.6 → 2.4.0-beta.0
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/jsonBuilder.js +1 -1
- package/lib/sw-template.js +15 -8
- package/lib/swBuilder.js +12 -0
- package/package.json +1 -1
package/lib/jsonBuilder.js
CHANGED
|
@@ -167,7 +167,7 @@ module.exports = (hexo, config, pluginConfig, swRules) => {
|
|
|
167
167
|
.each((i, it) => handleLink(it))
|
|
168
168
|
const relList = ['stylesheet', 'manifest', 'icon', 'shortcut icon', 'mask-icon']
|
|
169
169
|
for (let value of relList) {
|
|
170
|
-
html(`link[href][rel
|
|
170
|
+
html(`link[href][rel='${value}']`)
|
|
171
171
|
.map((i, ele) => html(ele).attr('href'))
|
|
172
172
|
.each((i, it) => handleLink(it))
|
|
173
173
|
}
|
package/lib/sw-template.js
CHANGED
|
@@ -24,8 +24,13 @@
|
|
|
24
24
|
.then(keys => Promise.all(
|
|
25
25
|
keys.map(async it => {
|
|
26
26
|
const url = it.url
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
if (url !== CTRL_PATH && list.match(url)) {
|
|
28
|
+
// [debug delete]
|
|
29
|
+
// noinspection ES6MissingAwait
|
|
30
|
+
cache.delete(it)
|
|
31
|
+
return url
|
|
32
|
+
}
|
|
33
|
+
return null
|
|
29
34
|
})
|
|
30
35
|
)).then(list => list.filter(it => it))
|
|
31
36
|
)
|
|
@@ -43,6 +48,7 @@
|
|
|
43
48
|
if (response.status === 200) {
|
|
44
49
|
const clone = response.clone()
|
|
45
50
|
caches.open(CACHE_NAME).then(it => it.put(key, clone))
|
|
51
|
+
// [debug put]
|
|
46
52
|
}
|
|
47
53
|
return response
|
|
48
54
|
})
|
|
@@ -55,6 +61,7 @@
|
|
|
55
61
|
})
|
|
56
62
|
|
|
57
63
|
self.addEventListener('message', event => {
|
|
64
|
+
// [debug message]
|
|
58
65
|
if (event.data === 'update') {
|
|
59
66
|
updateJson().then(info =>
|
|
60
67
|
// noinspection JSUnresolvedVariable
|
|
@@ -116,16 +123,16 @@
|
|
|
116
123
|
return newVersion
|
|
117
124
|
}
|
|
118
125
|
// noinspection JSIncompatibleTypesComparison
|
|
119
|
-
|
|
120
|
-
|
|
126
|
+
const aid = escape !== 0 && escape !== oldVersion.escape
|
|
127
|
+
let refresh = aid ? true : parseChange(list, info, oldVersion.local)
|
|
121
128
|
dbVersion.write(newVersion)
|
|
129
|
+
// [debug escape]
|
|
122
130
|
//如果需要清理全站
|
|
123
131
|
if (refresh) {
|
|
124
|
-
if (global
|
|
125
|
-
|
|
126
|
-
else list.refresh = true
|
|
132
|
+
if (global !== oldVersion.global || aid) list.refresh = true
|
|
133
|
+
else list.clean(new CacheChangeExpression({'flag': 'all'}))
|
|
127
134
|
}
|
|
128
|
-
return {list
|
|
135
|
+
return {list, version: newVersion}
|
|
129
136
|
})
|
|
130
137
|
}
|
|
131
138
|
return fetchFile(new Request('/update.json'), false)
|
package/lib/swBuilder.js
CHANGED
|
@@ -120,6 +120,18 @@ module.exports = (hexo, config, pluginConfig, rules) => {
|
|
|
120
120
|
return event.respondWith(new Response(null, {status: 208}))
|
|
121
121
|
`)
|
|
122
122
|
}
|
|
123
|
+
// noinspection JSUnresolvedVariable
|
|
124
|
+
if (pluginConfig.sw.debug) {
|
|
125
|
+
swContent = swContent.replaceAll('// [debug delete]', `
|
|
126
|
+
console.debug(\`delete cache: \${url}\`)
|
|
127
|
+
`).replaceAll('// [debug put]', `
|
|
128
|
+
console.debug(\`put cache: \${key}\`)
|
|
129
|
+
`).replaceAll('// [debug message]', `
|
|
130
|
+
console.debug(\`receive: \${event.data}\`)
|
|
131
|
+
`).replaceAll('// [debug escape]', `
|
|
132
|
+
console.debug(\`escape: \${aid}\`)
|
|
133
|
+
`)
|
|
134
|
+
}
|
|
123
135
|
return {
|
|
124
136
|
path: 'sw.js',
|
|
125
137
|
data: swContent
|