hexo-swpp 2.7.0 → 2.7.2
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/index.js +0 -1
- package/lib/jsonBuilder.js +16 -6
- package/lib/sort.js +1 -2
- package/lib/swBuilder.js +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
package/lib/jsonBuilder.js
CHANGED
|
@@ -18,7 +18,7 @@ module.exports = (hexo, hexoConfig, swRules) => {
|
|
|
18
18
|
hexo.extend.console.register('swpp', '生成前端更新需要的 json 文件以及相关缓存', {}, async () => {
|
|
19
19
|
// noinspection JSUnresolvedVariable
|
|
20
20
|
if (!fs.existsSync(hexoConfig.public_dir))
|
|
21
|
-
return logger.
|
|
21
|
+
return logger.warn('[SWPP] 未检测到发布目录,跳过 swpp 执行')
|
|
22
22
|
// 读取拓展 json
|
|
23
23
|
const expandName = 'update.json'
|
|
24
24
|
const expand = fs.existsSync(expandName) ? JSON.parse(fs.readFileSync(expandName, 'utf-8')) : undefined
|
|
@@ -82,7 +82,7 @@ module.exports = (hexo, hexoConfig, swRules) => {
|
|
|
82
82
|
const cache = new Set() // 已经计算过的文件
|
|
83
83
|
// noinspection JSUnresolvedVariable
|
|
84
84
|
eachAllFile(hexoConfig.public_dir, path => {
|
|
85
|
-
if (!fs.existsSync(path)) return logger.error(
|
|
85
|
+
if (!fs.existsSync(path)) return logger.error(`[SWPP] ${path} 不存在!`)
|
|
86
86
|
let endIndex
|
|
87
87
|
if (removeIndex && path.endsWith('/index.html')) endIndex = path.length - 10
|
|
88
88
|
else if (removeHtml && path.endsWith('.html')) endIndex = path.length - 5
|
|
@@ -127,7 +127,11 @@ module.exports = (hexo, hexoConfig, swRules) => {
|
|
|
127
127
|
result[key] = crypto.createHash('md5').update(text).digest('hex')
|
|
128
128
|
if (key.endsWith('.js')) handleJsContent(text)
|
|
129
129
|
else if (key.endsWith('.css')) handleCssContent(text)
|
|
130
|
-
}).catch(err =>
|
|
130
|
+
}).catch(err => {
|
|
131
|
+
logger.error(`[SWPP HandleLink] 拉取 ${url} 时出现 ${err.status ?? '未知'} 异常`)
|
|
132
|
+
logger.error(err)
|
|
133
|
+
}
|
|
134
|
+
)
|
|
131
135
|
)
|
|
132
136
|
}
|
|
133
137
|
// 处理指定 JS
|
|
@@ -145,7 +149,7 @@ module.exports = (hexo, hexoConfig, swRules) => {
|
|
|
145
149
|
const link = content.substring(start, end)
|
|
146
150
|
if (!link.match(/['"$`]/)) handleLink(link)
|
|
147
151
|
} catch (e) {
|
|
148
|
-
logger.error(`
|
|
152
|
+
logger.error(`[SWPP JsHandler] 处理 ${content} 时出现异常`)
|
|
149
153
|
logger.error(e)
|
|
150
154
|
}
|
|
151
155
|
})
|
|
@@ -233,6 +237,12 @@ module.exports = (hexo, hexoConfig, swRules) => {
|
|
|
233
237
|
}
|
|
234
238
|
}).catch(err => {
|
|
235
239
|
err.url = link
|
|
240
|
+
if (err.type === 'request-timeout') {
|
|
241
|
+
logger.error(
|
|
242
|
+
`[SWPP FetchFile] 拉取文件 [${link}] 时出现了超时错误,如果您构建所在的位置无法访问该资源,` +
|
|
243
|
+
"请尝试通过 DevReplace(https://kmar.top/posts/73014407/#4ea71e00)功能解决该问题。"
|
|
244
|
+
)
|
|
245
|
+
}
|
|
236
246
|
reject(err)
|
|
237
247
|
})
|
|
238
248
|
})
|
|
@@ -247,7 +257,7 @@ module.exports = (hexo, hexoConfig, swRules) => {
|
|
|
247
257
|
.then(response => resolve(response.json()))
|
|
248
258
|
.catch(err => {
|
|
249
259
|
if (err.status === 404) {
|
|
250
|
-
logger.
|
|
260
|
+
logger.warn(`[SWPP JsonBuilder] 拉取 ${err.url} 时出现 404 错误,如果您是第一次构建请忽略这个警告。`)
|
|
251
261
|
resolve()
|
|
252
262
|
} else throw err
|
|
253
263
|
})
|
|
@@ -471,7 +481,7 @@ module.exports = (hexo, hexoConfig, swRules) => {
|
|
|
471
481
|
const url = new URL(it.match(/^(https?|\/\/)/) ? it : nodePath.join(root, it)) // 当前文件的 URL
|
|
472
482
|
const cache = findCache(url) // 查询缓存
|
|
473
483
|
if (!cache) {
|
|
474
|
-
logger.error(`[
|
|
484
|
+
logger.error(`[SWPP BuildUpdate] 指定 URL(${url.pathname}) 未查询到缓存规则!`)
|
|
475
485
|
continue
|
|
476
486
|
}
|
|
477
487
|
if (!cache.clean) tidied.updateGlobal = true
|
package/lib/sort.js
CHANGED
|
@@ -16,8 +16,7 @@ module.exports = config => {
|
|
|
16
16
|
const list = {
|
|
17
17
|
posts: 'title',
|
|
18
18
|
pages: 'title',
|
|
19
|
-
tags: 'name'
|
|
20
|
-
categories: 'name'
|
|
19
|
+
tags: 'name'
|
|
21
20
|
}
|
|
22
21
|
Object.assign(list, config.sort)
|
|
23
22
|
const Locals = require(`${nodePath.resolve('./', 'node_modules/hexo/lib/hexo/locals')}`).prototype
|
package/lib/swBuilder.js
CHANGED
|
@@ -44,7 +44,7 @@ module.exports = (hexo, hexoConfig, rules) => {
|
|
|
44
44
|
case 'bigint': return `${any.toString()}n${separator}`
|
|
45
45
|
default: return any.toString() + separator
|
|
46
46
|
case 'symbol':
|
|
47
|
-
logger.error("[
|
|
47
|
+
logger.error("[SWPP ServiceWorkerBuilder] 不支持写入 symbol 类型,请从 sw-rules.js 中移除相关内容!")
|
|
48
48
|
throw '不支持写入 symbol 类型'
|
|
49
49
|
}
|
|
50
50
|
}
|