hexo-swpp 2.3.0 → 2.3.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/lib/jsonBuilder.js +11 -9
- package/lib/sw-template.js +1 -1
- package/package.json +1 -1
package/lib/jsonBuilder.js
CHANGED
|
@@ -41,7 +41,9 @@ module.exports = (hexo, config, pluginConfig, swRules) => {
|
|
|
41
41
|
/** 判断指定文件是否需要排除 */
|
|
42
42
|
const isExclude = pathname => {
|
|
43
43
|
// noinspection JSUnresolvedVariable
|
|
44
|
-
|
|
44
|
+
const exclude = pluginConfig.json?.exclude
|
|
45
|
+
if (!exclude) return false
|
|
46
|
+
for (let reg of exclude) {
|
|
45
47
|
if (pathname.match(new RegExp(reg, 'i'))) return true
|
|
46
48
|
}
|
|
47
49
|
return false
|
|
@@ -202,7 +204,7 @@ module.exports = (hexo, config, pluginConfig, swRules) => {
|
|
|
202
204
|
referer: new URL(link).hostname,
|
|
203
205
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.62'
|
|
204
206
|
},
|
|
205
|
-
timeout: pluginConfig.external
|
|
207
|
+
timeout: pluginConfig.external?.timeout ?? 1500
|
|
206
208
|
}).then(response => {
|
|
207
209
|
switch (response.status) {
|
|
208
210
|
case 200: case 301: case 302:
|
|
@@ -250,9 +252,9 @@ module.exports = (hexo, config, pluginConfig, swRules) => {
|
|
|
250
252
|
/** 判断指定资源是否需要合并 */
|
|
251
253
|
const isMerge = (pathname, tidied) => {
|
|
252
254
|
// noinspection JSUnresolvedVariable
|
|
253
|
-
const optional = pluginConfig.json
|
|
254
|
-
const {tag_dir, archive_dir, category_dir} = config
|
|
255
|
+
const optional = pluginConfig.json?.merge
|
|
255
256
|
if (!optional) return false
|
|
257
|
+
const {tag_dir, archive_dir, category_dir} = config
|
|
256
258
|
if (pathname.includes(`/${tag_dir}/`)) {
|
|
257
259
|
if (optional.tags ?? true)
|
|
258
260
|
return tidied.tags = true
|
|
@@ -337,7 +339,7 @@ module.exports = (hexo, config, pluginConfig, swRules) => {
|
|
|
337
339
|
info: [newInfo]
|
|
338
340
|
}
|
|
339
341
|
// noinspection JSUnresolvedVariable
|
|
340
|
-
const charLimit = pluginConfig.json
|
|
342
|
+
const charLimit = pluginConfig.json?.charLimit ?? 1024
|
|
341
343
|
if (JSON.stringify(result).length > charLimit) {
|
|
342
344
|
return {
|
|
343
345
|
global: result.global,
|
|
@@ -392,7 +394,7 @@ module.exports = (hexo, config, pluginConfig, swRules) => {
|
|
|
392
394
|
const merges = [] // 要合并的更新
|
|
393
395
|
// 推送页面更新
|
|
394
396
|
// noinspection JSUnresolvedVariable
|
|
395
|
-
if (tidied.page.size > (pluginConfig.json
|
|
397
|
+
if (tidied.page.size > (pluginConfig.json?.maxHtml ?? 15)) {
|
|
396
398
|
// 如果 html 数量超过阈值就直接清掉所有 html
|
|
397
399
|
info.change.push({flag: 'html'})
|
|
398
400
|
} else {
|
|
@@ -441,7 +443,7 @@ module.exports = (hexo, config, pluginConfig, swRules) => {
|
|
|
441
443
|
updateGlobal: expand?.global
|
|
442
444
|
}
|
|
443
445
|
// noinspection JSUnresolvedVariable
|
|
444
|
-
const mode = pluginConfig.json
|
|
446
|
+
const mode = pluginConfig.json?.precisionMode
|
|
445
447
|
for (let it of dif) {
|
|
446
448
|
const url = new URL(nodePath.join(root, it)) // 当前文件的 URL
|
|
447
449
|
const cache = findCache(url) // 查询缓存
|
|
@@ -452,11 +454,11 @@ module.exports = (hexo, config, pluginConfig, swRules) => {
|
|
|
452
454
|
if (!cache.clean) tidied.updateGlobal = true
|
|
453
455
|
if (isMerge(url.pathname, tidied)) continue
|
|
454
456
|
if (it.match(/(\/|\.html)$/)) { // 判断缓存是否是 html
|
|
455
|
-
if (mode
|
|
457
|
+
if (mode?.html ?? false) tidied.page.add(url.pathname)
|
|
456
458
|
else tidied.page.add(clipPageName(url.href, !it.endsWith('/')))
|
|
457
459
|
} else {
|
|
458
460
|
const extendedName = (it.includes('.') ? it.match(/[^.]+$/)[0] : null) ?? 'default'
|
|
459
|
-
const setting = mode[extendedName] ?? (mode
|
|
461
|
+
const setting = (mode && mode[extendedName]) ?? (mode?.default ?? false)
|
|
460
462
|
if (setting) tidied.file.add(url.pathname)
|
|
461
463
|
else {
|
|
462
464
|
let name = url.href.match(/[^/]+$/)[0]
|
package/lib/sw-template.js
CHANGED