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.
@@ -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
- let endIndex
87
- if (removeIndex && path.endsWith('/index.html')) endIndex = path.length - 10
88
- else if (removeHtml && path.endsWith('.html')) endIndex = path.length - 5
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)) {
@@ -67,7 +67,8 @@
67
67
  const url = new URL(request.url)
68
68
  // [blockRequest call]
69
69
  if (findCache(url)) {
70
- const key = `${url.protocol}//${url.host}${url.pathname}`
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-swpp",
3
- "version": "2.8.3",
3
+ "version": "2.8.5",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "hexo-log": "^3.0.0",