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.
@@ -41,7 +41,9 @@ module.exports = (hexo, config, pluginConfig, swRules) => {
41
41
  /** 判断指定文件是否需要排除 */
42
42
  const isExclude = pathname => {
43
43
  // noinspection JSUnresolvedVariable
44
- for (let reg of pluginConfig.json.exclude) {
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.timeout ?? 1500
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.merge
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.charLimit ?? 1024
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.maxHtml ?? 15)) {
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.precisionMode
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.html ?? false) tidied.page.add(url.pathname)
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.default ?? false)
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]
@@ -138,7 +138,7 @@
138
138
  }) : {version: result}
139
139
  )
140
140
  )
141
- else console.error(`拉取 update.json 时出现 ${response.status} 异常`)
141
+ else throw `加载 update.json 时遇到异常,状态码:${response.status}`
142
142
  })
143
143
  }
144
144
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-swpp",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "hexo-log": "^3.0.0",