hexo-swpp 2.8.3 → 2.8.5
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 +3 -9
- package/lib/sw-template.js +2 -1
- package/lib/swBuilder.js +1 -1
- package/package.json +1 -1
package/lib/jsonBuilder.js
CHANGED
|
@@ -74,20 +74,14 @@ module.exports = (hexo, hexoConfig, swRules, ejectValues) => {
|
|
|
74
74
|
*/
|
|
75
75
|
const buildNewJson = (path, flag) => new Promise(resolve => {
|
|
76
76
|
const result = {} // 存储新的 MD5 表
|
|
77
|
-
// noinspection JSUnresolvedVariable
|
|
78
|
-
const removeIndex = hexoConfig.pretty_urls?.trailing_index
|
|
79
|
-
// noinspection JSUnresolvedVariable
|
|
80
|
-
const removeHtml = hexoConfig.pretty_urls?.trailing_html
|
|
81
77
|
const taskList = [] // 拉取任务列表
|
|
82
78
|
const cache = new Set() // 已经计算过的文件
|
|
83
79
|
// noinspection JSUnresolvedVariable
|
|
84
80
|
eachAllFile(hexoConfig.public_dir, path => {
|
|
85
81
|
if (!fs.existsSync(path)) return logger.error(`[SWPP] ${path} 不存在!`)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
else endIndex = path.length
|
|
90
|
-
const url = new URL(nodePath.join(root, path.substring(7, endIndex)))
|
|
82
|
+
const endIndex = path.length - (path.endsWith('/index.html') ? 10 : 0)
|
|
83
|
+
// noinspection JSUnresolvedReference
|
|
84
|
+
const url = new URL(nodePath.join(root, path.substring(hexoConfig.public_dir.length, endIndex)))
|
|
91
85
|
if (isExclude(url.href)) return
|
|
92
86
|
let content = null
|
|
93
87
|
if (findCache(url)) {
|
package/lib/sw-template.js
CHANGED
|
@@ -67,7 +67,8 @@
|
|
|
67
67
|
const url = new URL(request.url)
|
|
68
68
|
// [blockRequest call]
|
|
69
69
|
if (findCache(url)) {
|
|
70
|
-
|
|
70
|
+
let key = `${url.protocol}//${url.host}${url.pathname}`
|
|
71
|
+
if (key.endsWith('/index.html')) key = key.substring(0, key.length - 10)
|
|
71
72
|
event.respondWith(caches.match(key)
|
|
72
73
|
.then(cache => cache ?? fetchFile(request, true)
|
|
73
74
|
.then(response => {
|
package/lib/swBuilder.js
CHANGED
|
@@ -166,7 +166,7 @@ module.exports = (hexo, hexoConfig, rules, ejectValues) => {
|
|
|
166
166
|
const rootPath = nodePath.resolve('./')
|
|
167
167
|
const relativePath = nodePath.relative(rootPath, absPath)
|
|
168
168
|
const template = fs.readFileSync(relativePath, 'utf-8')
|
|
169
|
-
.replaceAll('// ${onSuccess}', domConfig.onsuccess)
|
|
169
|
+
.replaceAll('// ${onSuccess}', `(${domConfig.onsuccess.toString()})()`)
|
|
170
170
|
return {
|
|
171
171
|
path: 'sw-dom.js',
|
|
172
172
|
data: template
|