hexo-theme-shokax 0.4.12 → 0.4.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,69 +1,78 @@
1
- "use strict";
2
- /* global hexo */
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
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;
5
14
  };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const package_json_1 = __importDefault(require("../../package.json"));
8
- const hexo_util_1 = require("hexo-util");
9
- const utils_1 = require("../utils");
10
- hexo.extend.helper.register('_safedump', (source) => {
11
- return JSON.stringify(source);
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_package = __toESM(require("../../package.json"));
24
+ var import_hexo_util = require("hexo-util");
25
+ var import_utils = require("../utils");
26
+ hexo.extend.helper.register("_safedump", (source) => {
27
+ return JSON.stringify(source);
12
28
  });
13
- hexo.extend.helper.register('hexo_env', function (type) {
14
- return this.env[type];
29
+ hexo.extend.helper.register("hexo_env", function(type) {
30
+ return this.env[type];
15
31
  });
16
- hexo.extend.helper.register('theme_env', function (type) {
17
- return package_json_1.default[type];
32
+ hexo.extend.helper.register("theme_env", function(type) {
33
+ return import_package.default[type];
18
34
  });
19
- hexo.extend.helper.register('_vendor_font', () => {
20
- const config = hexo.theme.config.font;
21
- if (!config || !config.enable)
22
- return '';
23
- const fontDisplay = '&display=swap';
24
- const fontSubset = '&subset=latin,latin-ext';
25
- const fontStyles = ':400,400italic,700,700italic';
26
- const fontHost = 'https://fonts.googleapis.com';
27
- // Get a font list from config
28
- let fontFamilies = ['global', 'logo', 'title', 'headings', 'posts', 'codes'].map(item => {
29
- if (config[item] && config[item].family && config[item].external) {
30
- return config[item].family + fontStyles;
31
- }
32
- return '';
33
- });
34
- fontFamilies = fontFamilies.filter(item => item !== '');
35
- // @ts-ignore
36
- fontFamilies = [...new Set(fontFamilies)];
37
- // @ts-ignore
38
- fontFamilies = fontFamilies.join('|');
39
- // Merge extra parameters to the final processed font string
40
- return fontFamilies
41
- ? (0, hexo_util_1.htmlTag)('link', {
42
- rel: 'stylesheet',
43
- href: `${fontHost}/css?family=${fontFamilies.concat(fontDisplay, fontSubset)}`,
44
- media: 'none',
45
- onload: "this.media='all'"
46
- })
47
- : '';
35
+ hexo.extend.helper.register("_vendor_font", () => {
36
+ const config = hexo.theme.config.font;
37
+ if (!config || !config.enable) return "";
38
+ const fontDisplay = "&display=swap";
39
+ const fontSubset = "&subset=latin,latin-ext";
40
+ const fontStyles = ":400,400italic,700,700italic";
41
+ const fontHost = "https://fonts.googleapis.com";
42
+ let fontFamilies = ["global", "logo", "title", "headings", "posts", "codes"].map((item) => {
43
+ if (config[item] && config[item].family && config[item].external) {
44
+ return config[item].family + fontStyles;
45
+ }
46
+ return "";
47
+ });
48
+ fontFamilies = fontFamilies.filter((item) => item !== "");
49
+ fontFamilies = [...new Set(fontFamilies)];
50
+ fontFamilies = fontFamilies.join("|");
51
+ return fontFamilies ? (0, import_hexo_util.htmlTag)("link", {
52
+ rel: "stylesheet",
53
+ href: `${fontHost}/css?family=${fontFamilies.concat(fontDisplay, fontSubset)}`,
54
+ media: "none",
55
+ onload: "this.media='all'"
56
+ }) : "";
48
57
  });
49
- hexo.extend.helper.register('_css', function (...urls) {
50
- const { statics, css } = hexo.theme.config;
51
- return urls.map(url => (0, hexo_util_1.htmlTag)('link', {
52
- rel: 'stylesheet',
53
- href: hexo_util_1.url_for.call(this, `${statics}${css}/${url}?v=${package_json_1.default.version}`)
54
- }), '').join('');
58
+ hexo.extend.helper.register("_css", function(...urls) {
59
+ const { statics, css } = hexo.theme.config;
60
+ return urls.map((url) => (0, import_hexo_util.htmlTag)("link", {
61
+ rel: "stylesheet",
62
+ href: import_hexo_util.url_for.call(this, `${statics}${css}/${url}?v=${import_package.default.version}`)
63
+ }), "").join("");
55
64
  });
56
- hexo.extend.helper.register('_js', function (...urls) {
57
- const { statics, js } = hexo.theme.config;
58
- 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}`), type: 'module', fetchpriority: 'high', defer: true }, '')).join('');
65
+ hexo.extend.helper.register("_js", function(...urls) {
66
+ const { statics, js } = hexo.theme.config;
67
+ return urls.map((url) => (0, import_hexo_util.htmlTag)("script", { src: import_hexo_util.url_for.call(this, `${statics}${js}/${url}?v=${import_package.default.version}`), type: "module", fetchpriority: "high", defer: true }, "")).join("");
59
68
  });
60
- hexo.extend.helper.register('vendor_js', function (vendor) {
61
- const res = (0, utils_1.getVendorLink)(hexo, hexo.theme.config.vendors.js[vendor]);
62
- return (0, hexo_util_1.htmlTag)('script', { src: res.url, integrity: res.sri, crossorigin: 'anonymous', fetchpriority: 'high' }, '');
69
+ hexo.extend.helper.register("vendor_js", function(vendor) {
70
+ const res = (0, import_utils.getVendorLink)(hexo, hexo.theme.config.vendors.js[vendor]);
71
+ return (0, import_hexo_util.htmlTag)("script", { src: res.url, integrity: res.sri, crossorigin: "anonymous", fetchpriority: "high" }, "");
63
72
  });
64
- hexo.extend.helper.register('_striptags', function (data) {
65
- return (0, hexo_util_1.stripHTML)(data);
73
+ hexo.extend.helper.register("_striptags", function(data) {
74
+ return (0, import_hexo_util.stripHTML)(data);
66
75
  });
67
- hexo.extend.helper.register('_truncate', function (data, end) {
68
- return data.substring(0, end);
76
+ hexo.extend.helper.register("_truncate", function(data, end) {
77
+ return data.substring(0, end);
69
78
  });
@@ -1,177 +1,163 @@
1
- 'use strict';
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
4
15
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- // @ts-ignore
7
- const hexo_util_1 = require("hexo-util");
8
- const node_fs_1 = __importDefault(require("node:fs"));
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var import_hexo_util = require("hexo-util");
25
+ var import_node_fs = __toESM(require("node:fs"));
9
26
  const randomServer = parseInt(String(Math.random() * 4), 10) + 1;
10
- const randomBG = function (count = 1, image_server = null, image_list = []) {
11
- let i;
12
- if (image_server) {
13
- if (count && count > 1) {
14
- const arr = new Array(count);
15
- for (i = 0; i < arr.length; i++) {
16
- arr[i] = image_server + '?' + Math.floor(Math.random() * 999999);
17
- }
18
- return arr;
19
- }
20
- return image_server + '?' + Math.floor(Math.random() * 999999);
21
- }
22
- const parseImage = function (img, size) {
23
- if (img.startsWith('//') || img.startsWith('http')) {
24
- return img;
25
- }
26
- else if (hexo.theme.config.experiments?.usingRelative) { // support relative url
27
- return img;
28
- }
29
- else {
30
- console.warn("sinaimg blocked all request from outside website,so don't use this format");
31
- return `https://tva${randomServer}.sinaimg.cn/` + size + '/' + img;
32
- }
33
- };
27
+ const randomBG = function(count = 1, image_server = null, image_list = []) {
28
+ let i;
29
+ if (image_server) {
34
30
  if (count && count > 1) {
35
- let shuffled = image_list.slice(0);
36
- while (shuffled.length <= 6) {
37
- shuffled = shuffled.concat(image_list.slice(0));
38
- }
39
- i = shuffled.length;
40
- const min = i - count;
41
- let temp;
42
- let index;
43
- while (i-- > min) {
44
- index = Math.floor((i + 1) * Math.random());
45
- temp = shuffled[index];
46
- shuffled[index] = shuffled[i];
47
- shuffled[i] = temp;
48
- }
49
- return shuffled.slice(min).map(function (img) {
50
- return parseImage(img, 'large');
51
- });
52
- }
53
- return parseImage(image_list[Math.floor(Math.random() * image_list.length)], 'mw690');
54
- };
55
- hexo.extend.helper.register('preloadjs', function () {
56
- const { statics, js } = hexo.theme.config;
57
- let res = '';
58
- node_fs_1.default.readdirSync('./shokaxTemp').forEach((file) => {
59
- if (file.endsWith('.js')) {
60
- res += (0, hexo_util_1.htmlTag)('link', { rel: 'modulepreload', href: hexo_util_1.url_for.call(this, `${statics}${js}/${file}`) }, '');
61
- }
62
- });
63
- return res;
64
- });
65
- hexo.extend.helper.register('load_async_css', function () {
66
- const { statics, css } = hexo.theme.config;
67
- let res = '';
68
- node_fs_1.default.readdirSync('./shokaxTemp').forEach((file) => {
69
- if (file.endsWith('.css')) {
70
- res += (0, hexo_util_1.htmlTag)('link', { rel: 'stylesheet', href: hexo_util_1.url_for.call(this, `${statics}${css}/${file}`), media: 'none', onload: "this.media='all'" }, '');
71
- }
72
- });
73
- return res;
74
- });
75
- // 注册hexo主题中的URL帮助方法
76
- hexo.extend.helper.register('_url', function (path, text, options = {}) {
77
- // 如果未提供URL路径,则返回
78
- if (!path) {
79
- return;
31
+ const arr = new Array(count);
32
+ for (i = 0; i < arr.length; i++) {
33
+ arr[i] = image_server + "?" + Math.floor(Math.random() * 999999);
34
+ }
35
+ return arr;
80
36
  }
81
- let tag = 'a';
82
- let attrs = { href: hexo_util_1.url_for.call(this, path), class: undefined, external: undefined, rel: undefined, 'data-url': undefined };
83
- for (const key in options) {
84
- attrs[key] = options[key];
37
+ return image_server + "?" + Math.floor(Math.random() * 999999);
38
+ }
39
+ const parseImage = function(img, size) {
40
+ if (img.startsWith("//") || img.startsWith("http")) {
41
+ return img;
42
+ } else if (hexo.theme.config.experiments?.usingRelative) {
43
+ return img;
44
+ } 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;
85
47
  }
86
- if (attrs.class && Array.isArray(attrs.class)) {
87
- attrs.class = attrs.class.join(' ');
48
+ };
49
+ if (count && count > 1) {
50
+ let shuffled = image_list.slice(0);
51
+ while (shuffled.length <= 6) {
52
+ shuffled = shuffled.concat(image_list.slice(0));
88
53
  }
89
- // 返回HTML标记字符串
90
- return (0, hexo_util_1.htmlTag)(tag, attrs, decodeURI(text), false);
91
- });
92
- hexo.extend.helper.register('_image_url', function (img, path = '') {
93
- const { statics } = hexo.theme.config;
94
- const { post_asset_folder } = hexo.config;
95
- if (img.startsWith('//') || img.startsWith('http')) {
96
- return img;
54
+ i = shuffled.length;
55
+ const min = i - count;
56
+ let temp;
57
+ let index;
58
+ while (i-- > min) {
59
+ index = Math.floor((i + 1) * Math.random());
60
+ temp = shuffled[index];
61
+ shuffled[index] = shuffled[i];
62
+ shuffled[i] = temp;
97
63
  }
98
- else {
99
- return hexo_util_1.url_for.call(this, statics + (post_asset_folder ? path : '') + img);
64
+ return shuffled.slice(min).map(function(img) {
65
+ return parseImage(img, "large");
66
+ });
67
+ }
68
+ return parseImage(image_list[Math.floor(Math.random() * image_list.length)], "mw690");
69
+ };
70
+ hexo.extend.helper.register("preloadjs", function() {
71
+ const { statics, js } = hexo.theme.config;
72
+ let res = "";
73
+ import_node_fs.default.readdirSync("./shokaxTemp").forEach((file) => {
74
+ if (file.endsWith(".js")) {
75
+ res += (0, import_hexo_util.htmlTag)("link", { rel: "modulepreload", href: import_hexo_util.url_for.call(this, `${statics}${js}/${file}`) }, "");
100
76
  }
77
+ });
78
+ return res;
101
79
  });
102
- hexo.extend.helper.register('_cover', function (item, num) {
103
- const { image_server, image_list } = hexo.theme.config;
104
- if (item.cover) {
105
- return this._image_url(item.cover, item.path);
106
- }
107
- else if (item.photos && item.photos.length > 0) {
108
- return this._image_url(item.photos[0], item.path);
109
- }
110
- else {
111
- return randomBG(num || 1, image_server, image_list);
80
+ hexo.extend.helper.register("load_async_css", function() {
81
+ const { statics, css } = hexo.theme.config;
82
+ let res = "";
83
+ import_node_fs.default.readdirSync("./shokaxTemp").forEach((file) => {
84
+ if (file.endsWith(".css")) {
85
+ res += (0, import_hexo_util.htmlTag)("link", { rel: "stylesheet", href: import_hexo_util.url_for.call(this, `${statics}${css}/${file}`), media: "none", onload: "this.media='all'" }, "");
112
86
  }
87
+ });
88
+ return res;
113
89
  });
114
- hexo.extend.helper.register('_cover_index', function (item) {
115
- const { index_images, image_list, image_server } = hexo.theme.config;
116
- if (item.cover) {
117
- return this._image_url(item.cover, item.path);
118
- }
119
- else if (item.photos && item.photos.length > 0) {
120
- return this._image_url(item.photos[0], item.path);
121
- }
122
- else {
123
- return randomBG(6, image_server, index_images.length === 0 ? image_list : index_images);
124
- }
90
+ hexo.extend.helper.register("_url", function(path, text, options = {}) {
91
+ if (!path) {
92
+ return;
93
+ }
94
+ let tag = "a";
95
+ let attrs = { href: import_hexo_util.url_for.call(this, path), class: void 0, external: void 0, rel: void 0, "data-url": void 0 };
96
+ for (const key in options) {
97
+ attrs[key] = options[key];
98
+ }
99
+ if (attrs.class && Array.isArray(attrs.class)) {
100
+ attrs.class = attrs.class.join(" ");
101
+ }
102
+ return (0, import_hexo_util.htmlTag)(tag, attrs, decodeURI(text), false);
125
103
  });
126
- // 注册hexo主题的永久链接帮助方法
127
- hexo.extend.helper.register('_permapath', function (str) {
128
- // 获取hexo的永久链接配置
129
- const { permalink } = hexo.config;
130
- // 将输入字符串中的'index.html'替换为空字符串
131
- let url = str.replace(/index\.html$/, '');
132
- // 如果永久链接不以'.html'结尾,将输入字符串中的'.html'替换为空字符串
133
- if (!permalink.endsWith('.html')) {
134
- url = url.replace(/\.html$/, '');
135
- }
136
- // 返回处理后的URL字符串
137
- return url;
104
+ hexo.extend.helper.register("_image_url", function(img, path = "") {
105
+ const { statics } = hexo.theme.config;
106
+ const { post_asset_folder } = hexo.config;
107
+ if (img.startsWith("//") || img.startsWith("http")) {
108
+ return img;
109
+ } else {
110
+ return import_hexo_util.url_for.call(this, statics + (post_asset_folder ? path : "") + img);
111
+ }
138
112
  });
139
- hexo.extend.helper.register('canonical', function () {
140
- return `<link rel="canonical" href="${this._permapath(this.url)}">`;
113
+ hexo.extend.helper.register("_cover", function(item, num) {
114
+ const { image_server, image_list } = hexo.theme.config;
115
+ if (item.cover) {
116
+ return this._image_url(item.cover, item.path);
117
+ } else if (item.photos && item.photos.length > 0) {
118
+ return this._image_url(item.photos[0], item.path);
119
+ } else {
120
+ return randomBG(num || 1, image_server, image_list);
121
+ }
141
122
  });
142
- /**
143
- * Get page path given a certain language tag
144
- */
145
- // 注册hexo主题的国际化路径帮助方法
146
- hexo.extend.helper.register('i18n_path', function (language) {
147
- // 获取当前页面的path和lang
148
- const { path, lang } = this.page;
149
- // 如果path以lang开头,则截取掉lang部分,作为基础路径
150
- const base = path.startsWith(lang) ? path.slice(lang.length + 1) : path;
151
- // 通过调用url_for方法,生成国际化路径
152
- return hexo_util_1.url_for.call(this, `${this.languages.indexOf(language) === 0 ? '' : '/' + language}/${base}`);
123
+ hexo.extend.helper.register("_cover_index", function(item) {
124
+ const { index_images, image_list, image_server } = hexo.theme.config;
125
+ if (item.cover) {
126
+ return this._image_url(item.cover, item.path);
127
+ } else if (item.photos && item.photos.length > 0) {
128
+ return this._image_url(item.photos[0], item.path);
129
+ } else {
130
+ return randomBG(6, image_server, index_images.length === 0 ? image_list : index_images);
131
+ }
153
132
  });
154
- /**
155
- * Get the language name
156
- */
157
- // 注册hexo主题的语言名称帮助方法
158
- hexo.extend.helper.register('language_name', function (language) {
159
- // 从主题配置中获取指定语言的名称
160
- // @ts-ignore
161
- const name = hexo.theme.i18n.__(language)('name');
162
- // 如果名称为默认值'name',则返回语言代码,否则返回语言名称
163
- return name === 'name' ? language : name;
133
+ hexo.extend.helper.register("_permapath", function(str) {
134
+ const { permalink } = hexo.config;
135
+ let url = str.replace(/index\.html$/, "");
136
+ if (!permalink.endsWith(".html")) {
137
+ url = url.replace(/\.html$/, "");
138
+ }
139
+ return url;
164
140
  });
165
- hexo.extend.helper.register('random_color', function () {
166
- const arr = [];
167
- for (let i = 0; i < 3; i++) {
168
- arr.push(Math.floor(Math.random() * 128 + 128));
169
- }
170
- const [r, g, b] = arr;
171
- 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)}`;
141
+ hexo.extend.helper.register("canonical", function() {
142
+ return `<link rel="canonical" href="${this._permapath(this.url)}">`;
143
+ });
144
+ hexo.extend.helper.register("i18n_path", function(language) {
145
+ const { path, lang } = this.page;
146
+ const base = path.startsWith(lang) ? path.slice(lang.length + 1) : path;
147
+ return import_hexo_util.url_for.call(this, `${this.languages.indexOf(language) === 0 ? "" : "/" + language}/${base}`);
148
+ });
149
+ hexo.extend.helper.register("language_name", function(language) {
150
+ const name = hexo.theme.i18n.__(language)("name");
151
+ return name === "name" ? language : name;
152
+ });
153
+ hexo.extend.helper.register("random_color", function() {
154
+ const arr = [];
155
+ for (let i = 0; i < 3; i++) {
156
+ arr.push(Math.floor(Math.random() * 128 + 128));
157
+ }
158
+ const [r, g, b] = arr;
159
+ 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)}`;
172
160
  });
173
- hexo.extend.helper.register('shokax_inject', function (point) {
174
- return hexo.theme.config.injects[point]
175
- .map(item => this.partial(item.layout, item.locals, item.options))
176
- .join('');
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("");
177
163
  });
@@ -1,80 +1,75 @@
1
1
  const prepareQuery = (categories, parent) => {
2
- const query = {
3
- parent: undefined
4
- };
5
- if (parent) {
6
- query.parent = parent;
7
- }
8
- else {
9
- query.parent = { $exists: false };
10
- }
11
- return categories.find(query).sort('name', 1).filter(cat => cat.length);
2
+ const query = {
3
+ parent: void 0
4
+ };
5
+ if (parent) {
6
+ query.parent = parent;
7
+ } else {
8
+ query.parent = { $exists: false };
9
+ }
10
+ return categories.find(query).sort("name", 1).filter((cat) => cat.length);
12
11
  };
13
- hexo.extend.helper.register('_list_categories', function (depth = 0) {
14
- const categories = this.site.categories;
15
- if (!categories || !categories.length)
16
- return '';
17
- const hierarchicalList = (level, parent) => {
18
- let result = '';
19
- prepareQuery(categories, parent).forEach((cat, i) => {
20
- let child;
21
- if (level + 1 < depth) {
22
- child = hierarchicalList(level + 1, cat._id);
23
- }
24
- const catname = `<a itemprop="url" href="${this.url_for(cat.path)}">${cat.name}</a><small>( ${cat.length} )</small>`;
25
- switch (level) {
26
- case 0:
27
- result += `<div><h2 class="item header">${catname}</h2>`;
28
- break;
29
- case 1:
30
- result += `<h3 class="item section">${catname}</h3>`;
31
- break;
32
- case 2:
33
- result += `<div class="item normal"><div class="title">${catname}</div></div>`;
34
- break;
35
- }
36
- if (child) {
37
- result += `${child}`;
38
- }
39
- if (level === 0) {
40
- result += '</div>';
41
- }
42
- });
43
- return result;
44
- };
45
- return hierarchicalList(0);
46
- });
47
- hexo.extend.helper.register('_category_prev', function (name) {
48
- const categories = this.site.categories;
49
- if (!categories || !categories.length)
50
- return '';
51
- let result = '';
52
- categories.find({ name }).forEach((current) => {
53
- if (current.parent) {
54
- categories.find({ _id: current.parent }).forEach((cat, i) => {
55
- result += `<a href="${this.url_for(cat.path)}">${cat.name}</a>`;
56
- });
57
- }
12
+ hexo.extend.helper.register("_list_categories", function(depth = 0) {
13
+ const categories = this.site.categories;
14
+ if (!categories || !categories.length) return "";
15
+ const hierarchicalList = (level, parent) => {
16
+ let result = "";
17
+ prepareQuery(categories, parent).forEach((cat, i) => {
18
+ let child;
19
+ if (level + 1 < depth) {
20
+ child = hierarchicalList(level + 1, cat._id);
21
+ }
22
+ const catname = `<a itemprop="url" href="${this.url_for(cat.path)}">${cat.name}</a><small>( ${cat.length} )</small>`;
23
+ switch (level) {
24
+ case 0:
25
+ result += `<div><h2 class="item header">${catname}</h2>`;
26
+ break;
27
+ case 1:
28
+ result += `<h3 class="item section">${catname}</h3>`;
29
+ break;
30
+ case 2:
31
+ result += `<div class="item normal"><div class="title">${catname}</div></div>`;
32
+ break;
33
+ }
34
+ if (child) {
35
+ result += `${child}`;
36
+ }
37
+ if (level === 0) {
38
+ result += "</div>";
39
+ }
58
40
  });
59
41
  return result;
42
+ };
43
+ return hierarchicalList(0);
60
44
  });
61
- hexo.extend.helper.register('_category_posts', function (page) {
62
- // let hexo = this
63
- const categories = this.site.categories;
64
- if (!categories || !categories.length || !page.categories || !page.categories.length)
65
- return '';
66
- let result = '';
67
- const cat = page.categories.toArray();
68
- categories.find({ _id: cat[cat.length - 1]._id }).forEach((category) => {
69
- if (category.posts) {
70
- category.posts.sort('date', 1).forEach((post) => {
71
- let current = '';
72
- if (post.path === page.path) {
73
- current = ' class="active"';
74
- }
75
- result += `<li ${current}><a href="${this.url_for(post.path)}" rel="bookmark" title="${post.title}">${post.title}</a></li>`;
76
- });
45
+ hexo.extend.helper.register("_category_prev", function(name) {
46
+ const categories = this.site.categories;
47
+ if (!categories || !categories.length) return "";
48
+ let result = "";
49
+ categories.find({ name }).forEach((current) => {
50
+ if (current.parent) {
51
+ categories.find({ _id: current.parent }).forEach((cat, i) => {
52
+ result += `<a href="${this.url_for(cat.path)}">${cat.name}</a>`;
53
+ });
54
+ }
55
+ });
56
+ return result;
57
+ });
58
+ hexo.extend.helper.register("_category_posts", function(page) {
59
+ const categories = this.site.categories;
60
+ if (!categories || !categories.length || !page.categories || !page.categories.length) return "";
61
+ let result = "";
62
+ const cat = page.categories.toArray();
63
+ categories.find({ _id: cat[cat.length - 1]._id }).forEach((category) => {
64
+ if (category.posts) {
65
+ category.posts.sort("date", 1).forEach((post) => {
66
+ let current = "";
67
+ if (post.path === page.path) {
68
+ current = ' class="active"';
77
69
  }
78
- });
79
- return result;
70
+ result += `<li ${current}><a href="${this.url_for(post.path)}" rel="bookmark" title="${post.title}">${post.title}</a></li>`;
71
+ });
72
+ }
73
+ });
74
+ return result;
80
75
  });