hexo-theme-shokax 0.4.12 → 0.4.14
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/_config.yml +4 -0
- package/layout/_partials/layout.pug +19 -15
- package/layout/_partials/post/nav.pug +5 -1
- package/package.json +3 -2
- package/scripts/filters/locals.js +41 -48
- package/scripts/filters/post.js +2 -4
- package/scripts/generaters/archive.js +121 -125
- package/scripts/generaters/config.js +61 -49
- package/scripts/generaters/images.js +17 -20
- package/scripts/generaters/index.js +111 -100
- package/scripts/generaters/pages.js +14 -14
- package/scripts/generaters/script.js +161 -153
- package/scripts/helpers/asset.js +68 -59
- package/scripts/helpers/engine.js +145 -159
- package/scripts/helpers/list_categories.js +68 -73
- package/scripts/helpers/summary_ai.js +100 -94
- package/scripts/helpers/symbols_count_time.js +43 -51
- package/scripts/libtypes.d.js +15 -0
- package/scripts/plugin/check.js +26 -27
- package/scripts/plugin/index.js +64 -73
- package/scripts/plugin/lib/injects-point.js +40 -19
- package/scripts/plugin/lib/injects.js +89 -73
- package/scripts/tags/links.js +51 -34
- package/scripts/tags/media.js +33 -16
- package/scripts/utils.js +40 -18
- package/source/js/_app/page/search.ts +2 -3
- package/toolbox/compiler.mjs +30 -24
package/scripts/helpers/asset.js
CHANGED
@@ -1,69 +1,78 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
var
|
4
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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(
|
14
|
-
|
29
|
+
hexo.extend.helper.register("hexo_env", function(type) {
|
30
|
+
return this.env[type];
|
15
31
|
});
|
16
|
-
hexo.extend.helper.register(
|
17
|
-
|
32
|
+
hexo.extend.helper.register("theme_env", function(type) {
|
33
|
+
return import_package.default[type];
|
18
34
|
});
|
19
|
-
hexo.extend.helper.register(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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(
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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(
|
57
|
-
|
58
|
-
|
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(
|
61
|
-
|
62
|
-
|
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(
|
65
|
-
|
73
|
+
hexo.extend.helper.register("_striptags", function(data) {
|
74
|
+
return (0, import_hexo_util.stripHTML)(data);
|
66
75
|
});
|
67
|
-
hexo.extend.helper.register(
|
68
|
-
|
76
|
+
hexo.extend.helper.register("_truncate", function(data, end) {
|
77
|
+
return data.substring(0, end);
|
69
78
|
});
|
@@ -1,177 +1,163 @@
|
|
1
|
-
|
2
|
-
var
|
3
|
-
|
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
|
-
|
6
|
-
//
|
7
|
-
|
8
|
-
|
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
|
11
|
-
|
12
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
-
|
87
|
-
|
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
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
99
|
-
|
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(
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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(
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
-
|
127
|
-
hexo.
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
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(
|
140
|
-
|
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
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
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
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
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(
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
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(
|
174
|
-
|
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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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(
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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(
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
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
|
});
|