hexo-theme-shokax 0.3.10 → 0.3.11

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.
Files changed (44) hide show
  1. package/_config.yml +26 -5
  2. package/package.json +8 -7
  3. package/scripts/filters/locals.js +6 -0
  4. package/scripts/filters/post.js +2 -0
  5. package/scripts/generaters/archive.js +13 -1
  6. package/scripts/generaters/config.js +4 -1
  7. package/scripts/generaters/images.js +2 -0
  8. package/scripts/generaters/index.js +2 -0
  9. package/scripts/generaters/pages.js +0 -2
  10. package/scripts/generaters/script.js +34 -9
  11. package/scripts/helpers/asset.js +16 -7
  12. package/scripts/helpers/engine.js +24 -1
  13. package/scripts/helpers/list_categories.js +4 -0
  14. package/scripts/helpers/summary_ai.js +4 -0
  15. package/scripts/helpers/symbols_count_time.js +14 -8
  16. package/scripts/plugin/check.js +5 -3
  17. package/scripts/plugin/index.js +36 -9
  18. package/scripts/plugin/lib/injects.js +15 -0
  19. package/scripts/tags/media.js +1 -0
  20. package/source/js/_app/components/sidebar.js +54 -56
  21. package/source/js/_app/fireworks.js +6 -137
  22. package/source/js/_app/globals/globalVars.js +80 -96
  23. package/source/js/_app/globals/handles.js +81 -60
  24. package/source/js/_app/globals/themeColor.js +30 -26
  25. package/source/js/_app/globals/thirdparty.js +25 -24
  26. package/source/js/_app/globals/tools.js +36 -30
  27. package/source/js/_app/library/anime.js +30 -15
  28. package/source/js/_app/library/dom.js +12 -5
  29. package/source/js/_app/library/loadFile.js +7 -9
  30. package/source/js/_app/library/proto.js +59 -7
  31. package/source/js/_app/library/scriptPjax.js +14 -9
  32. package/source/js/_app/library/storage.js +2 -4
  33. package/source/js/_app/library/vue.js +16 -19
  34. package/source/js/_app/page/comment.js +10 -11
  35. package/source/js/_app/page/common.js +8 -12
  36. package/source/js/_app/page/fancybox.js +13 -14
  37. package/source/js/_app/page/post.js +43 -45
  38. package/source/js/_app/page/search.js +20 -20
  39. package/source/js/_app/page/tab.js +7 -10
  40. package/source/js/_app/pjax/domInit.js +29 -29
  41. package/source/js/_app/pjax/refresh.js +45 -50
  42. package/source/js/_app/pjax/siteInit.js +27 -31
  43. package/source/js/_app/player.js +44 -27
  44. package/test/dom.test.js +0 -86
package/_config.yml CHANGED
@@ -83,13 +83,34 @@ polyfill:
83
83
  - fetch
84
84
 
85
85
  # 显示的动画(烟花)
86
+ # 参阅 https://github.com/D-Sketon/mouse-firework
86
87
  fireworks:
87
88
  enable: true
88
- color:
89
- - "rgba(255,182,185,.9)"
90
- - "rgba(250,227,217,.9)"
91
- - "rgba(187,222,214,.9)"
92
- - "rgba(138,198,209,.9)"
89
+ options:
90
+ excludeElements: ["a"]
91
+ particles:
92
+ - shape: circle
93
+ move: ["emit"]
94
+ easing: easeOutExpo
95
+ colors:
96
+ - "rgba(255,182,185,.9)"
97
+ - "rgba(250,227,217,.9)"
98
+ - "rgba(187,222,214,.9)"
99
+ - "rgba(138,198,209,.9)"
100
+ number: 30
101
+ duration: [1200, 1800]
102
+ shapeOptions:
103
+ radius: [16, 32]
104
+ - shape: circle
105
+ move: ["diffuse"]
106
+ easing: easeOutExpo
107
+ colors: ["#fff"]
108
+ number: 1
109
+ duration: [1200, 1800]
110
+ shapeOptions:
111
+ radius: 20
112
+ alpha: 0.5
113
+ lineWidth: 6
93
114
 
94
115
  font:
95
116
  enable: true
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "hexo-theme-shokax",
3
- "version": "0.3.10",
3
+ "version": "0.3.11",
4
4
  "description": "a hexo theme based on shoka",
5
5
  "main": "index.js",
6
6
  "repository": "https://github.com/theme-shoka-x/hexo-theme-shokaX",
7
7
  "author": "zkz098",
8
8
  "license": "AGPL-3.0-or-later",
9
9
  "scripts": {
10
- "test": "mocha test",
11
- "build": "pnpm install && tsc"
10
+ "test": "tsc --build --verbose",
11
+ "build": "cd ./source && tsc --build --verbose && cd ../scripts && tsc --build --verbose"
12
12
  },
13
13
  "devDependencies": {
14
14
  "@types/chai": "^4.3.11",
@@ -19,9 +19,9 @@
19
19
  "@types/lozad": "^1.16.4",
20
20
  "@types/mocha": "^10.0.6",
21
21
  "@types/node": "^20.10.6",
22
- "@typescript-eslint/eslint-plugin": "^6.17.0",
23
- "@typescript-eslint/parser": "^6.17.0",
24
- "chai": "^4.3.10",
22
+ "@typescript-eslint/eslint-plugin": "^6.18.0",
23
+ "@typescript-eslint/parser": "^6.18.0",
24
+ "chai": "^5.0.0",
25
25
  "eslint": "^8.56.0",
26
26
  "eslint-config-standard": "~17",
27
27
  "eslint-plugin-chai-friendly": "^0.7.2",
@@ -42,8 +42,9 @@
42
42
  "hexo": "^7.0.0",
43
43
  "js-yaml": "^4.1.0",
44
44
  "lozad": "^1.16.0",
45
+ "mouse-firework": "^0.0.3",
45
46
  "theme-shokax-anime": "^0.0.6",
46
- "theme-shokax-pjax": "^0.0.2"
47
+ "theme-shokax-pjax": "^0.0.3"
47
48
  },
48
49
  "engines": {
49
50
  "node": ">=18.0.0"
@@ -1,15 +1,19 @@
1
+ // @ts-ignore
1
2
  const fmtNum = (num) => {
2
3
  return num < 10 ? '0' + num : num;
3
4
  };
4
5
  hexo.extend.filter.register('template_locals', (locals) => {
5
6
  const { config } = hexo;
6
7
  const { __, theme } = locals;
8
+ // @ts-ignore
7
9
  const { i18n } = hexo.theme;
8
10
  const pangu = {
9
11
  spacing: (data) => {
10
12
  return data;
11
13
  }
12
14
  };
15
+ // Language & Config
16
+ // 根据主题配置的 Creative Commons 许可证生成链接
13
17
  locals.alternate = theme.alternate;
14
18
  locals.title = pangu.spacing(__('title') !== 'title' ? __('title') : config.title);
15
19
  locals.subtitle = pangu.spacing(__('subtitle') !== 'subtitle' ? __('subtitle') : config.subtitle);
@@ -19,6 +23,8 @@ hexo.extend.filter.register('template_locals', (locals) => {
19
23
  locals.languages.splice(locals.languages.indexOf('default'), 1);
20
24
  locals.page.lang = locals.page.lang || locals.page.language;
21
25
  locals.hostname = new URL(config.url).hostname || config.url;
26
+ // Creative Commons
27
+ // 根据主题配置的 Creative Commons 许可证生成链接
22
28
  if (theme.creative_commons.license === 'zero') {
23
29
  locals.ccURL = 'https://creativecommons.org/' + 'publicdomain/zero/1.0/' + (theme.creative_commons.language || '');
24
30
  }
@@ -1,3 +1,5 @@
1
+ /* global hexo */
1
2
  hexo.extend.filter.register('after_post_render', (data) => {
3
+ // 使用正则表达式将<img>标签的src属性替换为data-src属性
2
4
  data.content = data.content.replace(/(<img[^>]*) src=/img, '$1 data-src=');
3
5
  }, 0);
@@ -1,13 +1,17 @@
1
+ /* global hexo */
1
2
  'use strict';
2
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
5
  };
5
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ // @ts-ignore
6
8
  const hexo_pagination_1 = __importDefault(require("hexo-pagination"));
9
+ // @ts-ignore
7
10
  const fmtNum = num => {
8
11
  return num < 10 ? '0' + num : num;
9
12
  };
10
13
  if (!(hexo.config.archive && hexo.config.archive.enabled === false)) {
14
+ // when archive disabled pagination, per_page should be 0.
11
15
  let per_page;
12
16
  if (hexo.config.archive === 1) {
13
17
  per_page = 0;
@@ -28,6 +32,7 @@ if (!(hexo.config.archive && hexo.config.archive.enabled === false)) {
28
32
  const config = hexo.config;
29
33
  let archiveDir = config.archive_dir;
30
34
  const paginationDir = config.pagination_dir || 'page';
35
+ // @ts-ignore
31
36
  const allPosts = locals.posts.sort(config.archive_generator.order_by || '-date');
32
37
  const perPage = config.archive_generator.per_page;
33
38
  let result = [];
@@ -49,11 +54,14 @@ if (!(hexo.config.archive && hexo.config.archive.enabled === false)) {
49
54
  if (!config.archive_generator.yearly)
50
55
  return result;
51
56
  const posts = {};
57
+ // 按日期对文章进行分类
52
58
  allPosts.forEach(post => {
53
59
  const date = post.date;
54
60
  const year = date.year();
55
- const month = date.month() + 1;
61
+ const month = date.month() + 1; // month is started from 0
56
62
  if (!Object.prototype.hasOwnProperty.call(posts, year)) {
63
+ // 13个数组. 第一个数组是给这一年的文章准备的
64
+ // 其他则是各个月份的文章
57
65
  posts[year] = [
58
66
  [],
59
67
  [],
@@ -72,6 +80,7 @@ if (!(hexo.config.archive && hexo.config.archive.enabled === false)) {
72
80
  }
73
81
  posts[year][0].push(post);
74
82
  posts[year][month].push(post);
83
+ // Daily
75
84
  if (config.archive_generator.daily) {
76
85
  const day = date.date();
77
86
  if (!Object.prototype.hasOwnProperty.call(posts[year][month], 'day')) {
@@ -83,6 +92,7 @@ if (!(hexo.config.archive && hexo.config.archive.enabled === false)) {
83
92
  const Query = this.model('Post').Query;
84
93
  const years = Object.keys(posts);
85
94
  let year, data, month, monthData, url;
95
+ // Yearly
86
96
  for (let i = 0, len = years.length; i < len; i++) {
87
97
  year = +years[i];
88
98
  data = posts[year];
@@ -92,6 +102,7 @@ if (!(hexo.config.archive && hexo.config.archive.enabled === false)) {
92
102
  generate(url, new Query(data[0]), { year });
93
103
  if (!config.archive_generator.monthly && !config.archive_generator.daily)
94
104
  continue;
105
+ // Monthly
95
106
  for (month = 1; month <= 12; month++) {
96
107
  monthData = data[month];
97
108
  if (!monthData.length)
@@ -104,6 +115,7 @@ if (!(hexo.config.archive && hexo.config.archive.enabled === false)) {
104
115
  }
105
116
  if (!config.archive_generator.daily)
106
117
  continue;
118
+ // Daily
107
119
  for (let day = 1; day <= 31; day++) {
108
120
  const dayData = monthData.day[day];
109
121
  if (!dayData || !dayData.length)
@@ -3,19 +3,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ /* global hexo */
6
7
  const hexo_util_1 = require("hexo-util");
7
8
  const node_fs_1 = __importDefault(require("node:fs"));
8
9
  const path_1 = __importDefault(require("path"));
9
10
  const js_yaml_1 = __importDefault(require("js-yaml"));
10
11
  hexo.extend.filter.register('before_generate', () => {
11
12
  if (hexo.config.theme_config) {
13
+ // @ts-ignore
12
14
  hexo.theme.config = (0, hexo_util_1.deepMerge)(hexo.theme.config, hexo.config.theme_config);
13
15
  }
14
16
  const data = hexo.locals.get('data');
15
17
  if (data.languages) {
18
+ // @ts-ignore
16
19
  const { i18n } = hexo.theme;
17
20
  const mergeLang = lang => {
18
- if (data.languages[lang]) {
21
+ if (data.languages[lang]) { // @ts-ignore
19
22
  i18n.set(lang, (0, hexo_util_1.deepMerge)(i18n.get([lang]), data.languages[lang]));
20
23
  }
21
24
  };
@@ -1,5 +1,7 @@
1
+ /* global hexo */
1
2
  'use strict';
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ // @ts-ignore
3
5
  const fs = require("hexo-fs");
4
6
  hexo.extend.generator.register('images', function (locals) {
5
7
  const theme = hexo.theme.config;
@@ -1,3 +1,5 @@
1
+ // @ts-nocheck
2
+ /* global hexo */
1
3
  'use strict';
2
4
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
5
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -1,5 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  hexo.extend.generator.register('pages', function () {
4
2
  const config = hexo.config;
5
3
  return [
@@ -1,16 +1,40 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
4
24
  };
5
25
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const package_json_1 = __importDefault(require("../../package.json"));
7
- const fs = require("hexo-fs");
8
- const esbuild = require("esbuild");
26
+ /* global hexo */
27
+ // import env from '../../package.json'
28
+ const fs = __importStar(require("hexo-fs"));
29
+ const esbuild_1 = require("esbuild");
30
+ const env = {
31
+ version: '0.3.10'
32
+ };
9
33
  hexo.extend.generator.register('script', function (locals) {
10
34
  const config = hexo.config;
11
35
  const theme = hexo.theme.config;
12
36
  const siteConfig = {
13
- version: package_json_1.default.version,
37
+ version: env.version,
14
38
  hostname: config.url,
15
39
  root: config.root,
16
40
  statics: theme.statics,
@@ -27,6 +51,7 @@ hexo.extend.generator.register('script', function (locals) {
27
51
  fancybox: theme.vendors.js.fancybox
28
52
  },
29
53
  css: {
54
+ // valine: theme.css + '/comment.css',
30
55
  katex: theme.vendors.css.katex,
31
56
  mermaid: theme.css + '/mermaid.css',
32
57
  fancybox: theme.vendors.css.fancybox
@@ -45,8 +70,8 @@ hexo.extend.generator.register('script', function (locals) {
45
70
  disableVL: theme.disableVL,
46
71
  noPlayer: theme.experiments?.noPlayer,
47
72
  audio: undefined,
48
- fireworks: (theme.fireworks && theme.fireworks.enable)
49
- ? (theme.fireworks.color || ['rgba(255,182,185,.9)', 'rgba(250,227,217,.9)', 'rgba(187,222,214,.9)', 'rgba(138,198,209,.9)'])
73
+ fireworks: (theme.fireworks && theme.fireworks.enable && theme.fireworks.options)
74
+ ? theme.fireworks.options
50
75
  : undefined
51
76
  };
52
77
  if (config?.algolia) {
@@ -69,7 +94,7 @@ hexo.extend.generator.register('script', function (locals) {
69
94
  enterPoint = 'node_modules/hexo-theme-shokax/source/js/_app/pjax/siteInit.js';
70
95
  }
71
96
  text = 'const CONFIG = ' + JSON.stringify(siteConfig) + ';';
72
- esbuild.buildSync({
97
+ (0, esbuild_1.buildSync)({
73
98
  entryPoints: [enterPoint],
74
99
  bundle: true,
75
100
  outfile: 'shokax_temp.js',
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
2
+ /* global hexo */
5
3
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const package_json_1 = __importDefault(require("../../package.json"));
4
+ // import theme_env from '../../package.json'
7
5
  const hexo_util_1 = require("hexo-util");
6
+ const theme_env = {
7
+ version: '0.3.10'
8
+ };
8
9
  hexo.extend.helper.register('_new_comments', function (mode) {
9
10
  const root = this.config.url.replace(/^(https?:\/\/)?[^\/]*/, '');
10
11
  if (mode === 'twikoo') {
@@ -85,7 +86,7 @@ hexo.extend.helper.register('hexo_env', function (type) {
85
86
  return this.env[type];
86
87
  });
87
88
  hexo.extend.helper.register('theme_env', function (type) {
88
- return package_json_1.default[type];
89
+ return theme_env[type];
89
90
  });
90
91
  hexo.extend.helper.register('_vendor_font', () => {
91
92
  const config = hexo.theme.config.font;
@@ -95,6 +96,7 @@ hexo.extend.helper.register('_vendor_font', () => {
95
96
  const fontSubset = '&subset=latin,latin-ext';
96
97
  const fontStyles = ':300,300italic,400,400italic,700,700italic';
97
98
  const fontHost = 'https://fonts.googleapis.com';
99
+ // Get a font list from config
98
100
  let fontFamilies = ['global', 'logo', 'title', 'headings', 'posts', 'codes'].map(item => {
99
101
  if (config[item] && config[item].family && config[item].external) {
100
102
  return config[item].family + fontStyles;
@@ -102,8 +104,11 @@ hexo.extend.helper.register('_vendor_font', () => {
102
104
  return '';
103
105
  });
104
106
  fontFamilies = fontFamilies.filter(item => item !== '');
107
+ // @ts-ignore
105
108
  fontFamilies = [...new Set(fontFamilies)];
109
+ // @ts-ignore
106
110
  fontFamilies = fontFamilies.join('|');
111
+ // Merge extra parameters to the final processed font string
107
112
  return fontFamilies
108
113
  ? (0, hexo_util_1.htmlTag)('link', {
109
114
  rel: 'stylesheet',
@@ -111,10 +116,12 @@ hexo.extend.helper.register('_vendor_font', () => {
111
116
  })
112
117
  : '';
113
118
  });
119
+ // TODO 废弃方法
114
120
  hexo.extend.helper.register('_vendor_js', () => {
115
121
  const config = hexo.theme.config.vendors.js;
116
122
  if (!config)
117
123
  return '';
124
+ // Get a font list from config
118
125
  let vendorJs = ['pace', 'pjax', 'fetch', 'anime', 'algolia', 'instantsearch', 'lazyload', 'quicklink'].map(item => {
119
126
  if (config[item]) {
120
127
  return config[item];
@@ -122,7 +129,9 @@ hexo.extend.helper.register('_vendor_js', () => {
122
129
  return '';
123
130
  });
124
131
  vendorJs = vendorJs.filter(item => item !== '');
132
+ // @ts-ignore
125
133
  vendorJs = [...new Set(vendorJs)];
134
+ // @ts-ignore
126
135
  vendorJs = vendorJs.join(',');
127
136
  return vendorJs ? (0, hexo_util_1.htmlTag)('script', { src: `https://cdn.jsdelivr.net/combine/${vendorJs}` }, '') : '';
128
137
  });
@@ -130,12 +139,12 @@ hexo.extend.helper.register('_css', function (...urls) {
130
139
  const { statics, css } = hexo.theme.config;
131
140
  return urls.map(url => (0, hexo_util_1.htmlTag)('link', {
132
141
  rel: 'stylesheet',
133
- href: hexo_util_1.url_for.call(this, `${statics}${css}/${url}?v=${package_json_1.default.version}`)
142
+ href: hexo_util_1.url_for.call(this, `${statics}${css}/${url}?v=${theme_env.version}`)
134
143
  })).join('');
135
144
  });
136
145
  hexo.extend.helper.register('_js', function (...urls) {
137
146
  const { statics, js } = hexo.theme.config;
138
- return urls.map(url => (0, hexo_util_1.htmlTag)('script', { src: hexo_util_1.url_for.call(this, `${statics}${js}/${url}?v=${package_json_1.default.version}`) }, '')).join('');
147
+ return urls.map(url => (0, hexo_util_1.htmlTag)('script', { src: hexo_util_1.url_for.call(this, `${statics}${js}/${url}?v=${theme_env.version}`) }, '')).join('');
139
148
  });
140
149
  hexo.extend.helper.register('_list_vendor_js', () => {
141
150
  return hexo.theme.config.vendorsList.js;
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ // @ts-ignore
3
4
  const hexo_util_1 = require("hexo-util");
4
5
  const randomServer = parseInt(String(Math.random() * 4), 10) + 1;
5
6
  const randomBG = function (count = 1, image_server = null, image_list = []) {
@@ -18,7 +19,7 @@ const randomBG = function (count = 1, image_server = null, image_list = []) {
18
19
  if (img.startsWith('//') || img.startsWith('http')) {
19
20
  return img;
20
21
  }
21
- else if (hexo.theme.config.experiments?.usingRelative) {
22
+ else if (hexo.theme.config.experiments?.usingRelative) { // support relative url
22
23
  return img;
23
24
  }
24
25
  else {
@@ -47,7 +48,9 @@ const randomBG = function (count = 1, image_server = null, image_list = []) {
47
48
  }
48
49
  return parseImage(image_list[Math.floor(Math.random() * image_list.length)], 'mw690');
49
50
  };
51
+ // 注册hexo主题中的URL帮助方法
50
52
  hexo.extend.helper.register('_url', function (path, text, options = {}) {
53
+ // 如果未提供URL路径,则返回
51
54
  if (!path) {
52
55
  return;
53
56
  }
@@ -59,6 +62,7 @@ hexo.extend.helper.register('_url', function (path, text, options = {}) {
59
62
  if (attrs.class && Array.isArray(attrs.class)) {
60
63
  attrs.class = attrs.class.join(' ');
61
64
  }
65
+ // 返回HTML标记字符串
62
66
  return (0, hexo_util_1.htmlTag)(tag, attrs, decodeURI(text), false);
63
67
  });
64
68
  hexo.extend.helper.register('_image_url', function (img, path = '') {
@@ -95,24 +99,43 @@ hexo.extend.helper.register('_cover_index', function (item) {
95
99
  return randomBG(1, image_server, index_images.length === 0 ? image_list : index_images);
96
100
  }
97
101
  });
102
+ // 注册hexo主题的永久链接帮助方法
98
103
  hexo.extend.helper.register('_permapath', function (str) {
104
+ // 获取hexo的永久链接配置
99
105
  const { permalink } = hexo.config;
106
+ // 将输入字符串中的'index.html'替换为空字符串
100
107
  let url = str.replace(/index\.html$/, '');
108
+ // 如果永久链接不以'.html'结尾,将输入字符串中的'.html'替换为空字符串
101
109
  if (!permalink.endsWith('.html')) {
102
110
  url = url.replace(/\.html$/, '');
103
111
  }
112
+ // 返回处理后的URL字符串
104
113
  return url;
105
114
  });
106
115
  hexo.extend.helper.register('canonical', function () {
107
116
  return `<link rel="canonical" href="${this._permapath(this.url)}">`;
108
117
  });
118
+ /**
119
+ * Get page path given a certain language tag
120
+ */
121
+ // 注册hexo主题的国际化路径帮助方法
109
122
  hexo.extend.helper.register('i18n_path', function (language) {
123
+ // 获取当前页面的path和lang
110
124
  const { path, lang } = this.page;
125
+ // 如果path以lang开头,则截取掉lang部分,作为基础路径
111
126
  const base = path.startsWith(lang) ? path.slice(lang.length + 1) : path;
127
+ // 通过调用url_for方法,生成国际化路径
112
128
  return hexo_util_1.url_for.call(this, `${this.languages.indexOf(language) === 0 ? '' : '/' + language}/${base}`);
113
129
  });
130
+ /**
131
+ * Get the language name
132
+ */
133
+ // 注册hexo主题的语言名称帮助方法
114
134
  hexo.extend.helper.register('language_name', function (language) {
135
+ // 从主题配置中获取指定语言的名称
136
+ // @ts-ignore
115
137
  const name = hexo.theme.i18n.__(language)('name');
138
+ // 如果名称为默认值'name',则返回语言代码,否则返回语言名称
116
139
  return name === 'name' ? language : name;
117
140
  });
118
141
  hexo.extend.helper.register('random_color', function () {
@@ -1,4 +1,5 @@
1
1
  'use strict';
2
+ /* global hexo */
2
3
  const prepareQuery = (categories, parent) => {
3
4
  const query = {
4
5
  parent: undefined
@@ -12,6 +13,7 @@ const prepareQuery = (categories, parent) => {
12
13
  return categories.find(query).sort('name', 1).filter(cat => cat.length);
13
14
  };
14
15
  hexo.extend.helper.register('_list_categories', function (depth = 0) {
16
+ // let hexo = this
15
17
  const categories = this.site.categories;
16
18
  if (!categories || !categories.length)
17
19
  return '';
@@ -46,6 +48,7 @@ hexo.extend.helper.register('_list_categories', function (depth = 0) {
46
48
  return hierarchicalList(0);
47
49
  });
48
50
  hexo.extend.helper.register('_category_prev', function (name) {
51
+ // let hexo = this
49
52
  const categories = this.site.categories;
50
53
  if (!categories || !categories.length)
51
54
  return '';
@@ -60,6 +63,7 @@ hexo.extend.helper.register('_category_prev', function (name) {
60
63
  return result;
61
64
  });
62
65
  hexo.extend.helper.register('_category_posts', function (page) {
66
+ // let hexo = this
63
67
  const categories = this.site.categories;
64
68
  if (!categories || !categories.length || !page.categories || !page.categories.length)
65
69
  return '';
@@ -10,6 +10,7 @@ function getContent(post) {
10
10
  let db;
11
11
  function postMessage(path, content, dbPath, startMessage) {
12
12
  if (node_fs_1.default.existsSync('summary.json')) {
13
+ // @ts-ignore
13
14
  db = JSON.parse(node_fs_1.default.readFileSync('summary.json'));
14
15
  }
15
16
  else {
@@ -39,6 +40,7 @@ function postMessage(path, content, dbPath, startMessage) {
39
40
  throw Error('ERROR: Failed to get summary from Openai API');
40
41
  }
41
42
  response.json().then((data) => {
43
+ // @ts-ignore
42
44
  const summary = data.choices[0].message.content;
43
45
  try {
44
46
  db[path][dbPath] = summary;
@@ -63,6 +65,7 @@ function postMessage(path, content, dbPath, startMessage) {
63
65
  setTimeout(checkTime, 1000 * waitTime);
64
66
  return;
65
67
  }
68
+ // Openai API 针对个人用户免费试用限制 3 RPM,这里是25s后发送请求
66
69
  node_fs_1.default.writeFileSync('requested.lock', '');
67
70
  setTimeout(request, 1000 * 2.5 * waitTime);
68
71
  node_fs_1.default.unlinkSync('request.lock');
@@ -92,6 +95,7 @@ function postMessage(path, content, dbPath, startMessage) {
92
95
  }
93
96
  }
94
97
  else {
98
+ // custom尚未支持
95
99
  }
96
100
  }
97
101
  }
@@ -1,5 +1,11 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ /* global hexo */
4
+ /*!
5
+ hexo-symbols-count-time by theme-next
6
+ under GNU Lesser General Public License v3.0 or later
7
+ https://github.com/theme-next/hexo-symbols-count-time/blob/master/LICENSE
8
+ */
3
9
  const hexo_util_1 = require("hexo-util");
4
10
  const config = hexo.config.symbols_count_time = Object.assign({
5
11
  symbols: true,
@@ -25,20 +31,20 @@ function getFormatTime(minutes, suffix) {
25
31
  const fHours = Math.floor(minutes / 60);
26
32
  let fMinutes = Math.floor(minutes - (fHours * 60));
27
33
  if (fMinutes < 1) {
28
- fMinutes = 1;
34
+ fMinutes = 1; // 0 => 1
29
35
  }
30
36
  return fHours < 1
31
- ? fMinutes + ' ' + suffix
32
- : fHours + ':' + ('00' + fMinutes).slice(-2);
37
+ ? fMinutes + ' ' + suffix // < 59 => 59 mins.
38
+ : fHours + ':' + ('00' + fMinutes).slice(-2); // = 61 => 1:01
33
39
  }
34
40
  hexo.extend.helper.register('symbolsCount', function (post) {
35
41
  let symbolsResult = getSymbols(post);
36
42
  if (symbolsResult > 9999) {
37
- symbolsResult = Math.round(symbolsResult / 1000) + 'k';
43
+ symbolsResult = Math.round(symbolsResult / 1000) + 'k'; // > 9999 => 11k
38
44
  }
39
45
  else if (symbolsResult > 999) {
40
- symbolsResult = Math.round(symbolsResult / 100) / 10 + 'k';
41
- }
46
+ symbolsResult = Math.round(symbolsResult / 100) / 10 + 'k'; // > 999 => 1.1k
47
+ } // < 999 => 111
42
48
  return symbolsResult;
43
49
  });
44
50
  hexo.extend.helper.register('symbolsTime', function (post, awl = config.awl, wpm = config.wpm, suffix = config.suffix) {
@@ -48,8 +54,8 @@ hexo.extend.helper.register('symbolsTime', function (post, awl = config.awl, wpm
48
54
  hexo.extend.helper.register('symbolsCountTotal', function (site) {
49
55
  const symbolsResultTotal = getSymbolsTotal(site);
50
56
  return symbolsResultTotal < 1000000
51
- ? Math.round(symbolsResultTotal / 1000) + 'k'
52
- : Math.round(symbolsResultTotal / 100000) / 10 + 'm';
57
+ ? Math.round(symbolsResultTotal / 1000) + 'k' // < 999k => 111k
58
+ : Math.round(symbolsResultTotal / 100000) / 10 + 'm'; // > 999k => 1.1m
53
59
  });
54
60
  hexo.extend.helper.register('symbolsTimeTotal', function (site, awl = config.awl, wpm = config.wpm, suffix = config.suffix) {
55
61
  const minutes = Math.round(getSymbolsTotal(site) / (awl * wpm));
@@ -1,10 +1,11 @@
1
+ /* global hexo */
1
2
  let findProblem = false;
2
3
  hexo.on('generateBefore', function () {
3
4
  if (hexo.config.syntax_highlighter) {
4
5
  findProblem = true;
5
6
  hexo.log.error('[SXEC 101] Highlight.js or Prismjs enabled. The code block will render incomplete');
6
7
  }
7
- if (!hexo.config.autoprefixer || !hexo.config.markdown) {
8
+ if (!hexo.config.markdown) {
8
9
  findProblem = true;
9
10
  hexo.log.error(`[SXEC 102] Critical rendering plugins are missing or incorrectly configured.
10
11
  Some features will be disabled or render incorrectly`);
@@ -17,8 +18,9 @@ Some features will be disabled or render incorrectly`);
17
18
  findProblem = true;
18
19
  hexo.log.warn('[SXEC 201] Essential information(title, desc, lang, etc) config incorrectly, Page will render incorrectly');
19
20
  }
20
- if (hexo.theme.config.gitalk.clientID || hexo.theme.config.giscus.repo) {
21
- hexo.log.warn('You are using an deprecated feature and it was removed in the v0.3.10');
21
+ if (hexo.theme.config.gitalk?.clientID || hexo.theme.config.giscus?.repo) {
22
+ findProblem = true;
23
+ hexo.log.warn('[SXEC 202] You are using an deprecated feature and it was removed in the v0.3.10');
22
24
  }
23
25
  });
24
26
  hexo.on('generateAfter', function () {