hexo-theme-shokax 0.4.25 → 0.5.0-beta1

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 (68) hide show
  1. package/README.md +19 -31
  2. package/UsageRestrictions.md +2 -2
  3. package/_config.yml +11 -25
  4. package/_images.yml +0 -7
  5. package/eslint.config.mjs +4 -5
  6. package/layout/_mixin/card.pug +1 -2
  7. package/layout/_mixin/comment.pug +0 -1
  8. package/layout/_mixin/segment.pug +1 -1
  9. package/layout/_partials/footer.pug +1 -4
  10. package/layout/_partials/head/head.pug +0 -8
  11. package/layout/_partials/head/pwa.pug +1 -1
  12. package/layout/_partials/header.pug +0 -1
  13. package/layout/_partials/layout.pug +4 -14
  14. package/layout/_partials/post/footer.pug +0 -2
  15. package/layout/_partials/post/post.pug +1 -2
  16. package/layout/_partials/post/reward.pug +1 -1
  17. package/layout/_partials/sidebar/overview.pug +0 -2
  18. package/layout/_partials/third-party/baidu-analytics.pug +1 -1
  19. package/layout/_partials/third-party/google-analytics.pug +1 -1
  20. package/layout/archive.pug +3 -0
  21. package/layout/category.pug +3 -0
  22. package/layout/index.pug +3 -0
  23. package/layout/page.pug +7 -0
  24. package/layout/post.pug +8 -0
  25. package/layout/tag.pug +3 -0
  26. package/package.json +9 -10
  27. package/scripts/filters/post.js +1 -1
  28. package/scripts/generaters/config.js +12 -7
  29. package/scripts/generaters/images.js +9 -8
  30. package/scripts/generaters/index.js +57 -44
  31. package/scripts/generaters/script.js +18 -33
  32. package/scripts/helpers/engine.js +2 -7
  33. package/scripts/plugin/index.js +32 -69
  34. package/scripts/tags/media.js +1 -1
  35. package/source/css/app.styl +0 -13
  36. package/source/css/page.styl +3 -0
  37. package/source/css/post.styl +5 -0
  38. package/source/css/scaffolding.styl +5 -0
  39. package/source/js/_app/components/comments.ts +2 -3
  40. package/source/js/_app/components/sidebar.ts +35 -35
  41. package/source/js/_app/components/tcomments.ts +0 -1
  42. package/source/js/_app/globals/globalVars.ts +0 -15
  43. package/source/js/_app/globals/handles.ts +9 -9
  44. package/source/js/_app/globals/themeColor.ts +5 -6
  45. package/source/js/_app/globals/thirdparty.ts +2 -2
  46. package/source/js/_app/globals/tools.ts +4 -6
  47. package/source/js/_app/library/anime.ts +30 -19
  48. package/source/js/_app/library/declare.d.ts +0 -5
  49. package/source/js/_app/library/proto.ts +0 -67
  50. package/source/js/_app/library/vue.ts +7 -7
  51. package/source/js/_app/page/common.ts +8 -10
  52. package/source/js/_app/page/fancybox.ts +6 -8
  53. package/source/js/_app/page/post.ts +42 -54
  54. package/source/js/_app/page/search.ts +1 -6
  55. package/source/js/_app/page/tab.ts +8 -9
  56. package/source/js/_app/pjax/domInit.ts +19 -14
  57. package/source/js/_app/pjax/refresh.ts +8 -36
  58. package/source/js/_app/pjax/siteInit.ts +13 -42
  59. package/source/js/_app/player.ts +14 -798
  60. package/toolbox/compiler.mjs +20 -48
  61. package/toolbox/dev-version.mjs +14 -0
  62. package/README_en.MD +0 -71
  63. package/scripts/plugin/lib/injects-point.js +0 -41
  64. package/scripts/plugin/lib/injects.js +0 -105
  65. package/source/js/_app/library/dom.ts +0 -28
  66. package/source/js/_app/library/loadFile.ts +0 -47
  67. package/source/js/_app/library/scriptPjax.ts +0 -56
  68. package/source/js/_app/library/storage.ts +0 -12
@@ -21,13 +21,31 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
22
  mod
23
23
  ));
24
+ var import_promises = require("node:fs/promises");
24
25
  var import_hexo_pagination = __toESM(require("hexo-pagination"));
25
- const fs = require("hexo-fs");
26
+ function getFileExtension(path) {
27
+ const filename = path.split(/[\\/]/).pop() || "";
28
+ const lastDotIndex = filename.lastIndexOf(".");
29
+ return lastDotIndex > 0 ? filename.slice(lastDotIndex + 1) : "";
30
+ }
26
31
  hexo.config.index_generator = Object.assign({
27
32
  per_page: typeof hexo.config.per_page === "undefined" ? 10 : hexo.config.per_page,
28
33
  order_by: "-date"
29
34
  }, hexo.config.index_generator);
30
- hexo.extend.generator.register("index", function(locals) {
35
+ hexo.extend.helper.register("getCoverExt", function(path) {
36
+ const theme = hexo.theme.config;
37
+ if (theme.homeConfig.cateCards.length > 0) {
38
+ const cardMap = /* @__PURE__ */ new Map();
39
+ theme.homeConfig.cateCards.forEach((card) => {
40
+ cardMap.set(card.slug, card.cover);
41
+ });
42
+ if (cardMap.has(path)) {
43
+ const cover = cardMap.get(path);
44
+ return getFileExtension(cover);
45
+ }
46
+ }
47
+ });
48
+ hexo.extend.generator.register("index", async function(locals) {
31
49
  const covers = [];
32
50
  const catlist = [];
33
51
  let pages;
@@ -37,6 +55,7 @@ hexo.extend.generator.register("index", function(locals) {
37
55
  const paginationDir = config.pagination_dir || "page";
38
56
  const path = config.index_generator.path || "";
39
57
  const categories = locals.categories;
58
+ const theme = hexo.theme.config;
40
59
  const getTopcat = function(cat) {
41
60
  if (cat.parent) {
42
61
  const pCat = categories.findOne({ _id: cat.parent });
@@ -46,50 +65,44 @@ hexo.extend.generator.register("index", function(locals) {
46
65
  }
47
66
  };
48
67
  if (categories && categories.length) {
49
- categories.forEach((cat) => {
50
- const cover = `source/_posts/${cat.slug}`;
51
- if (fs.existsSync(cover + "/cover.avif")) {
52
- covers.push({
53
- path: cat.slug + "/cover.avif",
54
- data: function() {
55
- return fs.createReadStream(cover + "/cover.avif");
56
- }
57
- });
58
- } else if (fs.existsSync(cover + "/cover.webp")) {
59
- covers.push({
60
- path: cat.slug + "/cover.webp",
61
- data: function() {
62
- return fs.createReadStream(cover + "/cover.webp");
68
+ await Promise.all(
69
+ categories.map(async (cat) => {
70
+ const cover = `source/_posts/${cat.slug}`;
71
+ if (theme.homeConfig.cateCards.length > 0) {
72
+ const cardMap = /* @__PURE__ */ new Map();
73
+ theme.homeConfig.cateCards.forEach((card) => {
74
+ cardMap.set(card.slug, card.cover);
75
+ });
76
+ if (cardMap.has(cat.slug)) {
77
+ const cover2 = cardMap.get(cat.slug);
78
+ const coverData = await (0, import_promises.readFile)(`source/_posts/${cover2}`);
79
+ covers.push({
80
+ path: `${cat.slug}/cover.${getFileExtension(cover2)}`,
81
+ data: coverData
82
+ });
83
+ const topcat = getTopcat(cat);
84
+ if (topcat._id !== cat._id) {
85
+ cat.top = topcat;
86
+ }
87
+ const child = categories.find({ parent: cat._id });
88
+ let pl = 6;
89
+ if (child.length !== 0) {
90
+ cat.child = child.length;
91
+ cat.subs = child.sort({ name: 1 }).limit(6).toArray();
92
+ pl = Math.max(0, pl - child.length);
93
+ if (pl > 0) {
94
+ cat.subs.push(...cat.posts.sort({ title: 1 }).filter(function(item, i) {
95
+ return item.categories.last()._id === cat._id;
96
+ }).limit(pl).toArray());
97
+ }
98
+ } else {
99
+ cat.subs = cat.posts.sort({ title: 1 }).limit(6).toArray();
100
+ }
101
+ catlist.push(cat);
63
102
  }
64
- });
65
- } else if (fs.existsSync(cover + "/cover.jpg")) {
66
- covers.push({
67
- path: cat.slug + "/cover.jpg",
68
- data: function() {
69
- return fs.createReadStream(cover + "/cover.jpg");
70
- }
71
- });
72
- const topcat = getTopcat(cat);
73
- if (topcat._id !== cat._id) {
74
- cat.top = topcat;
75
- }
76
- const child = categories.find({ parent: cat._id });
77
- let pl = 6;
78
- if (child.length !== 0) {
79
- cat.child = child.length;
80
- cat.subs = child.sort({ name: 1 }).limit(6).toArray();
81
- pl = Math.max(0, pl - child.length);
82
- if (pl > 0) {
83
- cat.subs.push(...cat.posts.sort({ title: 1 }).filter(function(item, i) {
84
- return item.categories.last()._id === cat._id;
85
- }).limit(pl).toArray());
86
- }
87
- } else {
88
- cat.subs = cat.posts.sort({ title: 1 }).limit(6).toArray();
89
103
  }
90
- catlist.push(cat);
91
- }
92
- });
104
+ })
105
+ );
93
106
  }
94
107
  if (posts.length > 0) {
95
108
  pages = (0, import_hexo_pagination.default)(path, posts, {
@@ -21,10 +21,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  mod
22
22
  ));
23
23
  var import_package = __toESM(require("../../package.json"));
24
- var import_node_fs = __toESM(require("node:fs"));
24
+ var import_promises = __toESM(require("node:fs/promises"));
25
25
  var import_esbuild = require("esbuild");
26
26
  var import_utils = require("../utils");
27
- hexo.extend.generator.register("script", function(locals) {
27
+ hexo.extend.generator.register("script", async function(locals) {
28
28
  const config = hexo.config;
29
29
  const theme = hexo.theme.config;
30
30
  const siteConfig = {
@@ -55,10 +55,6 @@ hexo.extend.generator.register("script", function(locals) {
55
55
  enable: theme.outime.enable,
56
56
  days: theme.outime.days
57
57
  },
58
- quicklink: {
59
- timeout: theme.quicklink.timeout,
60
- priority: theme.quicklink.priority
61
- },
62
58
  playerAPI: theme.playerAPI,
63
59
  experiments: {
64
60
  copyrightLength: theme.experiments.copyrightLength
@@ -93,14 +89,15 @@ hexo.extend.generator.register("script", function(locals) {
93
89
  siteConfig.audio = theme.audio;
94
90
  }
95
91
  let enterPoint, patchDir;
96
- if (import_node_fs.default.existsSync("themes/shokaX/source/js/_app/pjax/siteInit.ts")) {
97
- patchDir = "themes/shokaX/source/js/_app/components/cloudflare.ts";
92
+ try {
93
+ await import_promises.default.readFile("themes/shokaX/source/js/_app/pjax/siteInit.ts", "utf-8");
98
94
  enterPoint = "themes/shokaX/source/js/_app/pjax/siteInit.ts";
99
- } else {
100
- patchDir = "node_modules/hexo-theme-shokax/source/js/_app/components/cloudflare.ts";
95
+ patchDir = "themes/shokaX/source/js/_app/components/cloudflare.ts";
96
+ } catch (e) {
101
97
  enterPoint = "node_modules/hexo-theme-shokax/source/js/_app/pjax/siteInit.ts";
98
+ patchDir = "node_modules/hexo-theme-shokax/source/js/_app/components/cloudflare.ts";
102
99
  }
103
- (0, import_esbuild.buildSync)({
100
+ await (0, import_esbuild.build)({
104
101
  entryPoints: [enterPoint],
105
102
  bundle: true,
106
103
  outdir: "shokaxTemp",
@@ -121,8 +118,6 @@ hexo.extend.generator.register("script", function(locals) {
121
118
  mainFields: ["module", "browser", "main"],
122
119
  splitting: true,
123
120
  define: {
124
- __UNLAZY_LOGGING__: "false",
125
- __UNLAZY_HASH_DECODING__: theme.modules.unlazyHash ? "true" : "false",
126
121
  __shokax_player__: theme.modules.player ? "true" : "false",
127
122
  __shokax_VL__: theme.modules.visibilityListener ? "true" : "false",
128
123
  __shokax_fireworks__: theme.fireworks && theme.fireworks.enable && theme.fireworks.options && theme.modules.fireworks ? "true" : "false",
@@ -139,35 +134,27 @@ hexo.extend.generator.register("script", function(locals) {
139
134
  }
140
135
  });
141
136
  const res = [];
142
- import_node_fs.default.readdirSync("./shokaxTemp").forEach((file) => {
143
- const fileText = import_node_fs.default.readFileSync(`./shokaxTemp/${file}`, { encoding: "utf-8" });
144
- if (file.endsWith("js")) {
145
- const result = hexo.render.renderSync({ text: fileText, engine: "js" });
137
+ (await import_promises.default.readdir("shokaxTemp")).forEach(async (file) => {
138
+ const fileContent = await import_promises.default.readFile("shokaxTemp/" + file);
139
+ if (file.endsWith(".js")) {
146
140
  res.push({
147
141
  path: theme.js + "/" + file,
148
- data: function() {
149
- return result;
150
- }
142
+ data: fileContent
151
143
  });
152
- } else if (file.endsWith("css")) {
153
- const result = hexo.render.renderSync({ text: fileText, engine: "css" });
144
+ } else if (file.endsWith(".css")) {
154
145
  res.push({
155
146
  path: theme.css + "/" + file,
156
- data: function() {
157
- return result;
158
- }
147
+ data: fileContent
159
148
  });
160
149
  } else {
161
150
  res.push({
162
- path: theme.js + "/" + file,
163
- data: function() {
164
- return fileText;
165
- }
151
+ path: theme.statics + "/" + file,
152
+ data: fileContent
166
153
  });
167
154
  }
168
155
  });
169
156
  if (theme.experiments.cloudflarePatch) {
170
- const result = (0, import_esbuild.buildSync)({
157
+ await (0, import_esbuild.build)({
171
158
  entryPoints: [patchDir],
172
159
  bundle: true,
173
160
  platform: "browser",
@@ -187,9 +174,7 @@ hexo.extend.generator.register("script", function(locals) {
187
174
  });
188
175
  res.push({
189
176
  path: theme.js + "/cf-patch.js",
190
- data: function() {
191
- return import_node_fs.default.readFileSync("./cf-patch.js", { encoding: "utf-8" });
192
- }
177
+ data: await import_promises.default.readFile("cf-patch.js")
193
178
  });
194
179
  }
195
180
  return res;
@@ -23,7 +23,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
  ));
24
24
  var import_hexo_util = require("hexo-util");
25
25
  var import_node_fs = __toESM(require("node:fs"));
26
- const randomServer = parseInt(String(Math.random() * 4), 10) + 1;
27
26
  const randomBG = function(count = 1, image_server = null, image_list = []) {
28
27
  let i;
29
28
  if (image_server) {
@@ -37,13 +36,12 @@ const randomBG = function(count = 1, image_server = null, image_list = []) {
37
36
  return image_server + "?" + Math.floor(Math.random() * 999999);
38
37
  }
39
38
  const parseImage = function(img, size) {
40
- if (img.startsWith("//") || img.startsWith("http")) {
39
+ if (img.startsWith("//") || img.startsWith("https")) {
41
40
  return img;
42
41
  } else if (hexo.theme.config.experiments?.usingRelative) {
43
42
  return img;
44
43
  } else {
45
- console.warn("sinaimg blocked all request from outside website,so don't use this format");
46
- return `https://tva${randomServer}.sinaimg.cn/` + size + "/" + img;
44
+ throw new Error("Image URL is not valid: " + img);
47
45
  }
48
46
  };
49
47
  if (count && count > 1) {
@@ -158,6 +156,3 @@ hexo.extend.helper.register("random_color", function() {
158
156
  const [r, g, b] = arr;
159
157
  return `#${r.toString(16).length > 1 ? r.toString(16) : "0" + r.toString(16)}${g.toString(16).length > 1 ? g.toString(16) : "0" + g.toString(16)}${b.toString(16).length > 1 ? b.toString(16) : "0" + b.toString(16)}`;
160
158
  });
161
- hexo.extend.helper.register("shokax_inject", function(point) {
162
- return hexo.theme.config.injects[point].map((item) => this.partial(item.layout, item.locals, item.options)).join("");
163
- });
@@ -1,75 +1,38 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __copyProps = (to, from, except, desc) => {
8
- if (from && typeof from === "object" || typeof from === "function") {
9
- for (let key of __getOwnPropNames(from))
10
- if (!__hasOwnProp.call(to, key) && key !== except)
11
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
- }
13
- return to;
14
- };
15
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
- // If the importer is in node compatibility mode or this is not an ESM
17
- // file that has been converted to a CommonJS file using a Babel-
18
- // compatible transform (i.e. "__esModule" has not been set), then set
19
- // "default" to the CommonJS "module.exports" for node compatibility.
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
- mod
22
- ));
23
- var import_injects = __toESM(require("./lib/injects"));
24
1
  var import_package = require("../../package.json");
25
- var fs = __toESM(require("node:fs"));
26
- /*!
27
- index.js in next-theme/hexo-theme-next by next-theme
28
- under GNU AFFERO GENERAL PUBLIC LICENSE v3.0 OR LATER
29
- https://github.com/next-theme/hexo-theme-next/blob/master/LICENSE.md
30
- */
31
- hexo.on("generateBefore", () => {
32
- (0, import_injects.default)(hexo);
33
- fs.rmSync("./shokaxTemp", { force: true, recursive: true });
34
- if (fs.existsSync("cf-patch.js")) {
35
- fs.unlinkSync("cf-patch.js");
36
- }
37
- if (fs.existsSync("request.lock")) {
38
- fs.unlinkSync("request.lock");
39
- }
40
- if (fs.existsSync("requested.lock")) {
41
- fs.unlinkSync("requested.lock");
2
+ var import_promises = require("node:fs/promises");
3
+ hexo.on("generateBefore", async () => {
4
+ await (0, import_promises.rm)("./shokaxTemp", { force: true, recursive: true });
5
+ try {
6
+ await (0, import_promises.unlink)("cf-patch.js");
7
+ } catch (e) {
42
8
  }
43
9
  });
44
- hexo.on("generateAfter", () => {
45
- fetch("https://registry.npmmirror.com/hexo-theme-shokax/latest", { headers: {
46
- "User-Agent": "ShokaX Client (hexo-theme-shokax)"
47
- } }).then((res) => {
48
- res.json().then((resp) => {
49
- try {
50
- const latest = resp["version"];
51
- const current = import_package.version.split(".");
52
- let isOutdated = false;
53
- for (let i = 0; i < Math.max(latest.length, current.length); i++) {
54
- if (!current[i] || latest[i] > current[i]) {
55
- isOutdated = true;
56
- break;
57
- }
58
- if (latest[i] < current[i]) {
59
- break;
60
- }
61
- }
62
- if (isOutdated) {
63
- hexo.log.warn(`Your theme ShokaX is outdated. Current version: v${current.join(".")}, latest version: v${latest.join(".")}`);
64
- hexo.log.warn("Visit https://github.com/theme-shoka-x/hexo-theme-shokaX/releases for more information.");
65
- }
66
- } catch (e) {
67
- hexo.log.warn("Failed to detect version info. Error message:");
68
- hexo.log.warn(e);
10
+ hexo.on("generateAfter", async () => {
11
+ try {
12
+ const res = await fetch("https://registry.npmmirror.com/hexo-theme-shokax/latest", {
13
+ headers: {
14
+ "User-Agent": "ShokaX Client (hexo-theme-shokax)"
69
15
  }
70
- }).catch((e) => {
71
- hexo.log.warn("Failed to detect version info. Error message:");
72
- hexo.log.warn(e);
73
16
  });
74
- });
17
+ const resp = await res.json();
18
+ const latest = resp.version;
19
+ const current = import_package.version.split(".");
20
+ let isOutdated = false;
21
+ for (let i = 0; i < Math.max(latest.length, current.length); i++) {
22
+ if (!current[i] || latest[i] > current[i]) {
23
+ isOutdated = true;
24
+ break;
25
+ }
26
+ if (latest[i] < current[i]) {
27
+ break;
28
+ }
29
+ }
30
+ if (isOutdated) {
31
+ hexo.log.warn(`Your theme ShokaX is outdated. Current version: v${current.join(".")}, latest version: v${latest.join(".")}`);
32
+ hexo.log.warn("Visit https://github.com/theme-shoka-x/hexo-theme-shokaX/releases for more information.");
33
+ }
34
+ } catch (e) {
35
+ hexo.log.warn("Failed to detect version info. Error message:");
36
+ hexo.log.warn(e);
37
+ }
75
38
  });
@@ -30,7 +30,7 @@ function postMedia(args, content) {
30
30
  switch (args[0]) {
31
31
  case "video":
32
32
  case "audio":
33
- return `<div class="media-container"><div class="player" data-type="${args[0]}" data-src='${JSON.stringify(list)}'></div></div>`;
33
+ return `<div class="media-container"><div class="player" data-type="${args[0]}" src='${JSON.stringify(list)}'></div></div>`;
34
34
  }
35
35
  }
36
36
  hexo.extend.tag.register("media", postMedia, { ends: true });
@@ -20,22 +20,9 @@ if $_iconfont = hexo-config('style.iconfont')
20
20
  else
21
21
  @import "_iconfont";
22
22
 
23
- // Scaffolding
24
- @import "_common/scaffolding";
25
-
26
- // Layout
27
- @import "_common/outline";
28
-
29
- // Components
30
- @import "_common/components";
31
-
32
23
  if $custom = hexo-config('style.custom')
33
24
  @import $custom;
34
25
 
35
- if hexo-config('injects.style')
36
- for $inject_style in hexo-config('injects.style')
37
- @import $inject_style;
38
-
39
26
  if $optimize = hexo-config('experiments.optimizeLongPosts')
40
27
  @import "optimize.styl"
41
28
 
@@ -0,0 +1,3 @@
1
+ @import "scaffolding"
2
+
3
+ @import "_common/components/pages"
@@ -0,0 +1,5 @@
1
+ @import "scaffolding"
2
+
3
+ @import "_common/components/post"
4
+ @import "_common/components/highlight"
5
+ @import "_common/components/tags"
@@ -0,0 +1,5 @@
1
+ @import "app"
2
+
3
+ @import "_common/scaffolding"
4
+ @import "_common/outline"
5
+ @import "_common/components/third-party"
@@ -1,6 +1,8 @@
1
1
  import { CONFIG } from '../globals/globalVars'
2
2
  import { init, RecentComments } from '@waline/client'
3
+ // @ts-ignore
3
4
  import { pageviewCount } from '@waline/client/pageview'
5
+ // @ts-ignore
4
6
  await import('@waline/client/style')
5
7
 
6
8
  export const walineComment = function () {
@@ -21,7 +23,6 @@ export const walineComment = function () {
21
23
  }
22
24
 
23
25
  export const walinePageview = function () {
24
- // TODO waline 上游此模块存在问题
25
26
  pageviewCount({
26
27
  serverURL: CONFIG.waline.serverURL,
27
28
  path: window.location.pathname
@@ -35,7 +36,6 @@ export const walineRecentComments = async function () {
35
36
  serverURL: CONFIG.waline.serverURL.replace(/\/+$/, ''),
36
37
  count: 10
37
38
  })
38
- // TODO 疑似 waline API 返回格式与文档不一致,需要确认是否为上游问题
39
39
  // @ts-ignore
40
40
  comments.data.forEach(function (item) {
41
41
  let cText = (item.orig.length > 50) ? item.orig.substring(0, 50) + '...' : item.orig
@@ -74,7 +74,6 @@ export const walineRecentComments = async function () {
74
74
  commentTime.className = 'breadcrumb'
75
75
  commentTime.innerText = `${item.nick} @ ${item.time}`
76
76
  commentLink.href = root + item.href
77
- commentLink['data-pjax-state'] = 'data-pjax-state'
78
77
  commentEl.className = 'item'
79
78
 
80
79
  commentText.appendChild(document.createElement('br'))
@@ -3,14 +3,12 @@
3
3
  import { CONFIG, Container, diffY, menuToggle, showContents, sideBar } from '../globals/globalVars'
4
4
  import { clipBoard } from '../globals/tools'
5
5
  import { pageScroll, transition } from '../library/anime'
6
- import { $dom } from '../library/dom'
7
- import initProto, { getHeight, setDisplay } from '../library/proto'
6
+ import { getHeight, setDisplay } from '../library/proto'
8
7
 
9
- initProto()
10
8
  export const sideBarToggleHandle = (event:Event, force?:number) => {
11
- if (sideBar.hasClass('on')) {
12
- sideBar.removeClass('on')
13
- menuToggle.removeClass('close')
9
+ if (sideBar.classList.contains('on')) {
10
+ sideBar.classList.remove('on')
11
+ menuToggle.classList.remove('close')
14
12
  if (force) {
15
13
  // @ts-ignore
16
14
  // noinspection JSConstantReassignment
@@ -25,8 +23,8 @@ export const sideBarToggleHandle = (event:Event, force?:number) => {
25
23
  sideBar.style = ''
26
24
  } else {
27
25
  transition(sideBar, 'slideRightIn', () => {
28
- sideBar.addClass('on')
29
- menuToggle.addClass('close')
26
+ sideBar.classList.add('on')
27
+ menuToggle.classList.add('close')
30
28
  })
31
29
  }
32
30
  }
@@ -61,29 +59,30 @@ export const sideBarTab = () => {
61
59
  const text = document.createTextNode(element.getAttribute('data-title'))
62
60
  span.appendChild(text)
63
61
  tab.appendChild(span)
64
- tab.addClass(item + ' item')
62
+ tab.classList.add(item)
63
+ tab.classList.add('item')
65
64
 
66
65
  if (active) {
67
- element.addClass(active)
68
- tab.addClass(active)
66
+ element.classList.add(active)
67
+ tab.classList.add(active)
69
68
  } else {
70
- element.removeClass('active')
69
+ element.classList.remove('active')
71
70
  }
72
71
  tab.addEventListener('click', (event) => {
73
72
  const target = event.currentTarget as HTMLElement
74
- if (target.hasClass('active')) return
73
+ if (target.classList.contains('active')) return
75
74
 
76
- sideBar.find('.tab .item').forEach((element) => {
77
- element.removeClass('active')
75
+ sideBar.querySelectorAll('.tab .item').forEach((element) => {
76
+ element.classList.remove('active')
78
77
  })
79
78
 
80
- sideBar.find('.panel').forEach((element) => {
81
- element.removeClass('active')
79
+ sideBar.querySelectorAll('.panel').forEach((element) => {
80
+ element.classList.remove('active')
82
81
  })
83
82
 
84
- sideBar.querySelector('.panel.' + target.className.replace(' item', '')).addClass('active')
83
+ sideBar.querySelector('.panel.' + target.className.replace(' item', '')).classList.add('active')
85
84
 
86
- target.addClass('active')
85
+ target.classList.add('active')
87
86
  })
88
87
 
89
88
  list.appendChild(tab)
@@ -104,39 +103,39 @@ export const sidebarTOC = () => {
104
103
 
105
104
  if (!target) return
106
105
 
107
- if (target.hasClass('current')) {
106
+ if (target.classList.contains('current')) {
108
107
  return
109
108
  }
110
109
 
111
- $dom.each('.toc .active', (element) => {
112
- element && element.removeClass('active current')
110
+ document.querySelectorAll('.toc .active').forEach((element) => {
111
+ element && element.classList.remove('active current')
113
112
  })
114
113
 
115
114
  sections.forEach((element) => {
116
- element && element.removeClass('active')
115
+ element && element.classList.remove('active')
117
116
  })
118
117
 
119
- target.addClass('active current')
120
- sections[index] && sections[index].addClass('active')
118
+ target.classList.add('active current')
119
+ sections[index] && sections[index].classList.add('active')
121
120
 
122
121
  let parent = <Element> target.parentNode
123
122
 
124
123
  while (!parent.matches('.contents')) {
125
124
  if (parent.matches('li')) {
126
- parent.addClass('active')
125
+ parent.classList.add('active')
127
126
  const t = document.getElementById(decodeURIComponent(parent.querySelector('a.toc-link').getAttribute('href').replace('#', '')))
128
127
  if (t) {
129
- t.addClass('active')
128
+ t.classList.add('active')
130
129
  }
131
130
  }
132
131
  parent = <Element> parent.parentNode
133
132
  }
134
133
  // Scrolling to center active TOC element if TOC content is taller than viewport.
135
- if (getComputedStyle(sideBar).display !== 'none' && tocElement.hasClass('active')) {
134
+ if (getComputedStyle(sideBar).display !== 'none' && tocElement.classList.contains('active')) {
136
135
  pageScroll((tocElement as HTMLElement), target.offsetTop - ((tocElement as HTMLElement).offsetHeight / 4))
137
136
  }
138
137
  }
139
- const navItems = $dom.all('.contents li')
138
+ const navItems = document.querySelectorAll<HTMLElement>('.contents li')
140
139
 
141
140
  if (navItems.length < 1) {
142
141
  return
@@ -224,18 +223,19 @@ export const goToCommentHandle = () => {
224
223
  }
225
224
 
226
225
  export const menuActive = () => {
227
- $dom.each('.menu .item:not(.title)', (element) => {
226
+ document.querySelectorAll('.menu .item:not(.title)').forEach((element) => {
228
227
  const target = <HTMLAnchorElement> element.querySelector('a[href]')
229
- const parentItem = element.parentNode.parentNode
228
+ const parentItem = element.parentNode.parentNode as HTMLElement
230
229
  if (!target) return
231
230
  const isSamePath = target.pathname === location.pathname || target.pathname === location.pathname.replace('index.html', '')
232
231
  const isSubPath = !CONFIG.root.startsWith(target.pathname) && location.pathname.startsWith(target.pathname)
233
232
  const active = !target.onclick && target.hostname === location.hostname && (isSamePath || isSubPath)
234
- element.toggleClass('active', active)
235
- if (element.parentNode.querySelector('.active') && parentItem.hasClass('dropdown')) {
236
- parentItem.removeClass('active').addClass('expand')
233
+ element.classList.toggle('active', active)
234
+ if (element.parentNode.querySelector('.active') && parentItem.classList.contains('dropdown')) {
235
+ parentItem.classList.remove('active')
236
+ parentItem.classList.add('expand')
237
237
  } else {
238
- parentItem.removeClass('expand')
238
+ parentItem.classList.remove('expand')
239
239
  }
240
240
  })
241
241
  }
@@ -40,7 +40,6 @@ export const twikooRecentComments = async function () {
40
40
  commentTime.className = 'breadcrumb'
41
41
  commentTime.innerText = `${item.nick} @ ${item.time}`
42
42
  commentLink.href = root + item.href
43
- commentLink['data-pjax-state'] = 'data-pjax-state'
44
43
  commentEl.className = 'item'
45
44
 
46
45
  commentText.appendChild(document.createElement('br'))
@@ -1,9 +1,4 @@
1
- import { $dom } from '../library/dom'
2
- import Pjax from 'theme-shokax-pjax'
3
- import initProto from '../library/proto'
4
-
5
1
  export const CONFIG = shokax_CONFIG
6
- initProto()
7
2
  export const statics = CONFIG.statics.indexOf('//') > 0 ? CONFIG.statics : CONFIG.root
8
3
  export const scrollAction: { x: number, y: number } = { x: 0, y: 0 }
9
4
  export let diffY = 0
@@ -19,7 +14,6 @@ export const quickBtn = document.getElementById('quick')
19
14
  export const sideBar = document.getElementById('sidebar')
20
15
  export const siteBrand = document.getElementById('brand')
21
16
  export let toolBtn = document.getElementById('tool')
22
- export let toolPlayer
23
17
  export let backToTop: HTMLElement
24
18
  export let goToComment
25
19
  export let showContents
@@ -29,7 +23,6 @@ export let oWinHeight = window.innerHeight
29
23
  export let oWinWidth = window.innerWidth
30
24
  export let LOCAL_HASH = 0
31
25
  export let LOCAL_URL = window.location.href
32
- export let pjax:Pjax
33
26
 
34
27
  export function setSiteNavHeight (value:number):void {
35
28
  siteNavHeight = value
@@ -66,18 +59,10 @@ export function setLocalUrl (value:string):void {
66
59
  LOCAL_URL = value
67
60
  }
68
61
 
69
- export function setPjax (value:Pjax):void {
70
- pjax = value
71
- }
72
-
73
62
  export function setOriginTitle (value:string):void {
74
63
  originTitle = value
75
64
  }
76
65
 
77
- export function setToolPlayer (value:any):void {
78
- toolPlayer = value
79
- }
80
-
81
66
  export function setBackToTop (value:HTMLElement):void {
82
67
  backToTop = value
83
68
  }