hexo-theme-volantis 5.3.0 → 5.4.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## [5.4.0](https://github.com/volantis-x/hexo-theme-volantis/compare/v5.3.2...v5.4.0) (2022-06-09)
4
+
5
+
6
+ ### Features
7
+
8
+ * **VolantisRequest:** Fetch, POST, Get ([ea98dbc](https://github.com/volantis-x/hexo-theme-volantis/commit/ea98dbcc4c3a9bfc0bf6de452e0da826276ff29c))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **fcircle:** CDN ([#765](https://github.com/volantis-x/hexo-theme-volantis/issues/765)) ([35a2e97](https://github.com/volantis-x/hexo-theme-volantis/commit/35a2e971da07eb30e4cb9a0fdeaafe74580cbcd0))
14
+
15
+ ### [5.3.2](https://github.com/volantis-x/hexo-theme-volantis/compare/v5.3.1...v5.3.2) (2022-05-24)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * **check:** Check environment first ([f5692dd](https://github.com/volantis-x/hexo-theme-volantis/commit/f5692dd862cb0790a656866853e41908b2967de6))
21
+ * **revisioned:** calcFileHash ([1402b9e](https://github.com/volantis-x/hexo-theme-volantis/commit/1402b9ea7747bdcf60e6190b243970567c033528))
22
+
23
+ ### [5.3.1](https://github.com/volantis-x/hexo-theme-volantis/compare/v5.3.0...v5.3.1) (2022-05-23)
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * **bbtalk:** js config ([4bb7a12](https://github.com/volantis-x/hexo-theme-volantis/commit/4bb7a12a8d1ab384a223b946e7da1f3ecf60c9ac))
29
+
3
30
  ## [5.3.0](https://github.com/volantis-x/hexo-theme-volantis/compare/v5.2.0...v5.3.0) (2022-05-22)
4
31
 
5
32
 
package/_config.yml CHANGED
@@ -59,7 +59,7 @@ cdn:
59
59
  cdn_version: true
60
60
  # volantis static 静态资源文件 npm 包 CDN 地址 (后面加 "/" )
61
61
  # https://github.com/volantis-x/volantis-static
62
- volantis_static_cdn: https://unpkg.com/volantis-static@0.0.1649552113628/
62
+ volantis_static_cdn: https://unpkg.com/volantis-static@0.0.1654736714924/
63
63
  ########################################################################
64
64
  # 全局页面字符串替换 A => B (可用于临时修改错字等)
65
65
  replace:
@@ -841,7 +841,7 @@ plugins:
841
841
  bbtalk:
842
842
  # Set `plugins: ["bbtalk"]` to enable in front-matter
843
843
  # 不支持 Pjax
844
- js: https://unpkg.com/bbtalk@0.1.5/dist/bbtalk.min.js # BBtalk.js
844
+ js: https://unpkg.com/bbtalk@0.1.5/dist/bbtalk.js # BBtalk.js
845
845
  appId: 0KzOX4vC7Jsk6vzUGNeEiUaI-gzGzoHsz # your appID
846
846
  appKey: HwCiWuxfpvKiLm4teCUgTIba # your appKEY
847
847
  serverURLs: https://bbapi.heson10.com # Request Api 域名
@@ -852,10 +852,10 @@ plugins:
852
852
  fcircle:
853
853
  # Set `plugins: ["fcircle"]` to enable in front-matter
854
854
  # 支持 Pjax
855
- api: '' # api 地址
856
- message: '与主机通讯中……' # 占位文字
857
- css: 'https://cdn.jsdelivr.net/gh/lmm214/immmmm/themes/hello-friend/static/fcircle-beta.css'
858
- js: 'https://cdn.jsdelivr.net/gh/lmm214/immmmm/themes/hello-friend/static/fcircle-beta.js'
855
+ api: https://fcircle-api.example.com/ # api 地址
856
+ message: 与主机通讯中…… # 占位文字
857
+ css: volantis-static/libs/fcircle/fcircle.css
858
+ js: volantis-static/libs/fcircle/fcircle.js
859
859
 
860
860
  # 消息提示
861
861
  # izitoast@1.4.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-theme-volantis",
3
- "version": "5.3.0",
3
+ "version": "5.4.0",
4
4
  "description": "Elegant and powerful theme for Hexo.",
5
5
  "main": "package.json",
6
6
  "scripts": {
@@ -6,16 +6,14 @@ module.exports =(hexo) => {
6
6
  return `title 未配置!
7
7
  请在站点配置 _config.yml 中配置 title
8
8
  see: https://hexo.io/zh-cn/docs/configuration
9
- title not configured!
10
- see: https://hexo.io/zh-cn/docs/configuration`
9
+ title is not configured!`
11
10
  }
12
11
  if (!config.description) {
13
12
  return `description 未配置!
14
13
  请在站点配置 _config.yml 中配置 description
15
14
  description主要用于SEO,告诉搜索引擎一个关于您站点的简单描述,通常建议在其中包含您网站的关键词。
16
15
  see: https://hexo.io/zh-cn/docs/configuration
17
- description not configured!
18
- see: https://hexo.io/zh-cn/docs/configuration`
16
+ description is not configured!`
19
17
  }
20
18
  if (themeConfig?.search?.service===`google`||themeConfig?.search?.service===`algolia`||themeConfig?.search?.service===`azure`||themeConfig?.search?.service===`baidu`) {
21
19
  return `原 google, algolia, azure, baidu 站内搜索 系祖传代码, 且文档丢失, 不便后续维护 在 5.0 版本被移除
@@ -29,15 +27,16 @@ see: https://volantis.js.org/v5/theme-settings/#幻灯片背景-视差滚动效
29
27
  }
30
28
  if ("valinecount" in themeConfig?.article?.body?.top_meta||"valinecount" in themeConfig?.article?.body?.bottom_meta||"valinecount" in themeConfig?.article?.body?.meta_library) {
31
29
  return `ValineCount 在 5.0 版本被移除
32
- ValineCount has been removed in 5.0 version
30
+ ValineCount has been removed in version 5.0
33
31
  see: https://volantis.js.org/v5/theme-settings/#文章布局配置`
34
32
  }
35
33
  if (themeConfig?.comments?.service=="valine"||themeConfig?.comments?.service=="minivaline") {
36
34
  return `Valine 在 5.0 版本被移除
37
- Valine has been removed in 5.0 version
35
+ Valine has been removed in version 5.0
38
36
  see: https://volantis.js.org/v5/theme-settings/#选择评论系统`
39
37
  }
40
38
  } catch (error) {}
39
+ hexo.log.info(`Check environment configuration success!`);
41
40
  return true;
42
41
  };
43
42
 
@@ -6,12 +6,6 @@ module.exports =(hexo) => {
6
6
  hexo.checkEnvironment=1;
7
7
  hexo.log.info(`Checking environment configuration...`);
8
8
 
9
- // Checking configuration
10
- let checkConfiguration = require('./check-configuration')(hexo);
11
- if (checkConfiguration!==true) {
12
- CheckConfError(hexo,checkConfiguration);
13
- }
14
-
15
9
  // Checking environment
16
10
  exec('node -v', (err, stdout, stderr) => {
17
11
  if (err) {
@@ -38,7 +32,11 @@ module.exports =(hexo) => {
38
32
  hexo.log.info(`hexo-cli 版本:${stdout}`);
39
33
  CheckError(hexo,`hexo-cli 版本过低,请升级至 4.1 以上版本!`);
40
34
  }else{
41
- hexo.log.info(`Check environment configuration success!`);
35
+ // Checking configuration
36
+ let checkConfiguration = require('./check-configuration')(hexo);
37
+ if (checkConfiguration!==true) {
38
+ CheckConfError(hexo,checkConfiguration);
39
+ }
42
40
  }
43
41
  }
44
42
  });
@@ -74,9 +74,15 @@ const revisioned = (filePath) => {
74
74
  hexo.extend.helper.register("revisioned", revisioned);
75
75
 
76
76
  const calcFileHash = async (filePath) => {
77
- const buffer = await stream2buffer(hexo.route.get(filePath));
78
- const fileHash = crypto.createHash("md5").update(buffer).digest('hex').substring(0, 8);
79
- return fileHash;
77
+ if (hexo.route.get(filePath)) {
78
+ const buffer = await stream2buffer(hexo.route.get(filePath));
79
+ const fileHash = crypto.createHash("md5").update(buffer).digest('hex').substring(0, 8);
80
+ return fileHash;
81
+ } else {
82
+ // 随机生成 hash
83
+ return crypto.randomBytes(16).toString('hex').substring(0, 8);
84
+ }
85
+
80
86
  };
81
87
 
82
88
  const replaceRevisionPlaceholder = async () => {
@@ -84,75 +90,78 @@ const replaceRevisionPlaceholder = async () => {
84
90
  if (!hexo.theme.config.cdn_version) {
85
91
  return;
86
92
  }
87
-
88
- const options = hexo.config.new_revision || {};
89
- const include = options.include || [];
90
-
91
- const hashPromiseMap = {};
92
- const hashMap = {};
93
- const doHash = (filePath) =>
94
- calcFileHash(filePath).then((hash) => {
95
- hashMap[filePath] = hash;
96
- });
97
-
98
- await Promise.all(
99
- hexo.route.list().map(async (path) => {
100
- const [, , extension] = parseFilePath(path);
101
- if (![".css", ".js", ".html"].includes(extension)) {
102
- return;
103
- }
104
-
105
- let fileContent = await readFileAsString(path);
106
-
107
- const regexp = /\.!!revision:([^\)]+?)!!/g;
108
- const matchResult = [...fileContent.matchAll(regexp)];
109
- if (matchResult.length) {
110
- const hashTaskList = [];
111
-
112
- // 异步获取文件 hash
113
- matchResult.forEach((group) => {
114
- const filePath = group[1];
115
- if (!(filePath in hashPromiseMap)) {
116
- hashPromiseMap[filePath] = doHash(filePath);
117
- }
118
- hashTaskList.push(hashPromiseMap[filePath]);
119
- });
120
-
121
- // 等待全部 hash 完成
122
- await Promise.all(hashTaskList);
123
-
124
- // 替换 placeholder
125
- fileContent = fileContent.replace(regexp, function (match, filePath) {
126
- if (!(filePath in hashMap)) {
127
- throw new Error("file hash not computed");
93
+ try {
94
+ const options = hexo.config.new_revision || {};
95
+ const include = options.include || [];
96
+
97
+ const hashPromiseMap = {};
98
+ const hashMap = {};
99
+ const doHash = (filePath) =>
100
+ calcFileHash(filePath).then((hash) => {
101
+ hashMap[filePath] = hash;
102
+ });
103
+
104
+ await Promise.all(
105
+ hexo.route.list().map(async (path) => {
106
+ const [, , extension] = parseFilePath(path);
107
+ if (![".css", ".js", ".html"].includes(extension)) {
108
+ return;
109
+ }
110
+
111
+ let fileContent = await readFileAsString(path);
112
+
113
+ const regexp = /\.!!revision:([^\)]+?)!!/g;
114
+ const matchResult = [...fileContent.matchAll(regexp)];
115
+ if (matchResult.length) {
116
+ const hashTaskList = [];
117
+
118
+ // 异步获取文件 hash
119
+ matchResult.forEach((group) => {
120
+ const filePath = group[1];
121
+ if (!(filePath in hashPromiseMap)) {
122
+ hashPromiseMap[filePath] = doHash(filePath);
123
+ }
124
+ hashTaskList.push(hashPromiseMap[filePath]);
125
+ });
126
+
127
+ // 等待全部 hash 完成
128
+ await Promise.all(hashTaskList);
129
+
130
+ // 替换 placeholder
131
+ fileContent = fileContent.replace(regexp, function (match, filePath) {
132
+ if (!(filePath in hashMap)) {
133
+ throw new Error("file hash not computed");
134
+ }
135
+ return "." + hashMap[filePath];
136
+ });
137
+
138
+ hexo.route.set(path, fileContent);
139
+ }
140
+ })
141
+ );
142
+
143
+ await Promise.all(
144
+ hexo.route.list().map(async (path) => {
145
+ for (let i = 0, len = include.length; i < len; i++) {
146
+ if (minimatch(path, include[i])) {
147
+ return doHash(path);
128
148
  }
129
- return "." + hashMap[filePath];
130
- });
131
-
132
- hexo.route.set(path, fileContent);
133
- }
134
- })
135
- );
136
-
137
- await Promise.all(
138
- hexo.route.list().map(async (path) => {
139
- for (let i = 0, len = include.length; i < len; i++) {
140
- if (minimatch(path, include[i])) {
141
- return doHash(path);
142
149
  }
143
- }
144
- })
145
- );
146
-
147
- await Promise.all(
148
- Object.keys(hashMap).map(async (filePath) => {
149
- hexo.route.set(
150
- getRevisionedFilePath(filePath, hashMap[filePath]),
151
- await readFileAsBuffer(filePath)
152
- );
153
- hexo.route.remove(filePath);
154
- })
155
- );
150
+ })
151
+ );
152
+
153
+ await Promise.all(
154
+ Object.keys(hashMap).map(async (filePath) => {
155
+ hexo.route.set(
156
+ getRevisionedFilePath(filePath, hashMap[filePath]),
157
+ await readFileAsBuffer(filePath)
158
+ );
159
+ hexo.route.remove(filePath);
160
+ })
161
+ );
162
+ } catch (error) {
163
+
164
+ }
156
165
  };
157
166
 
158
- hexo.extend.filter.register("after_generate", replaceRevisionPlaceholder,999999999999999999999999999999999999);
167
+ hexo.extend.filter.register("after_generate", replaceRevisionPlaceholder,9999);
package/source/js/app.js CHANGED
@@ -67,7 +67,7 @@ const VolantisApp = (() => {
67
67
  }
68
68
 
69
69
  fn.event = () => {
70
- volantis.dom.$(document.getElementById("scroll-down")).on('click', function () {
70
+ volantis.dom.$(document.getElementById("scroll-down"))?.on('click', function () {
71
71
  fn.scrolltoElement(volantis.dom.bodyAnchor);
72
72
  });
73
73
 
@@ -1126,3 +1126,47 @@ const DOMController = {
1126
1126
  }
1127
1127
  }
1128
1128
  Object.freeze(DOMController);
1129
+
1130
+ const VolantisRequest = {
1131
+ timeoutFetch: (url, ms, requestInit) => {
1132
+ const controller = new AbortController()
1133
+ requestInit.signal?.addEventListener('abort', () => controller.abort())
1134
+ let promise = fetch(url, { ...requestInit, signal: controller.signal })
1135
+ if (ms > 0) {
1136
+ const timer = setTimeout(() => controller.abort(), ms)
1137
+ promise.finally(() => { clearTimeout(timer) })
1138
+ }
1139
+ promise = promise.catch((err) => {
1140
+ throw ((err || {}).name === 'AbortError') ? new Error(`Fetch timeout: ${url}`) : err
1141
+ })
1142
+ return promise
1143
+ },
1144
+
1145
+ Fetch: async (url, requestInit, timeout = 15000) => {
1146
+ const resp = await VolantisRequest.timeoutFetch(url, timeout, requestInit);
1147
+ if (!resp.ok) throw new Error(`Fetch error: ${url} | ${resp.status}`);
1148
+ let json = await resp.json()
1149
+ if (!json.success) throw json
1150
+ return json
1151
+ },
1152
+
1153
+ POST: async (url, data) => {
1154
+ const requestInit = {
1155
+ method: 'POST',
1156
+ }
1157
+ if (data) {
1158
+ const formData = new FormData();
1159
+ Object.keys(data).forEach(key => formData.append(key, String(data[key])))
1160
+ requestInit.body = formData;
1161
+ }
1162
+ const json = await VolantisRequest.Fetch(url, requestInit)
1163
+ return json.data;
1164
+ },
1165
+
1166
+ Get: async (url, data) => {
1167
+ const json = await VolantisRequest.Fetch(url + (data ? (`?${new URLSearchParams(data)}`) : ''), {
1168
+ method: 'GET'
1169
+ })
1170
+ }
1171
+ }
1172
+ Object.freeze(VolantisRequest);