hexo-theme-shokax 0.4.6-dev6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- package/CODE_OF_CONDUCT.md +128 -128
- package/CONTRIBUTING.md +58 -58
- package/LICENSE +660 -660
- package/LICENSE-shoka +21 -21
- package/README.md +76 -99
- package/README_en.MD +75 -91
- package/UsageRestrictions.md +25 -25
- package/_config.yml +381 -381
- package/_images.yml +9 -9
- package/eslint.config.mjs +55 -55
- package/languages/README.md +19 -19
- package/languages/default.yml +1 -1
- package/languages/en.yml +153 -153
- package/languages/ja.yml +153 -153
- package/languages/zh-CN.yml +153 -153
- package/languages/zh-HK.yml +153 -153
- package/languages/zh-TW.yml +153 -153
- package/layout/_alternate/atom.ejs +30 -30
- package/layout/_alternate/json.ejs +16 -16
- package/layout/_alternate/rss.ejs +34 -34
- package/layout/_mixin/breadcrumb.pug +33 -33
- package/layout/_mixin/card.pug +38 -38
- package/layout/_mixin/comment.pug +6 -6
- package/layout/_mixin/postmeta.pug +29 -29
- package/layout/_mixin/segment.pug +35 -35
- package/layout/_mixin/sidebar.pug +40 -40
- package/layout/_mixin/widgets.pug +28 -28
- package/layout/_partials/footer.pug +43 -43
- package/layout/_partials/head/head.pug +55 -55
- package/layout/_partials/head/head_com.pug +24 -24
- package/layout/_partials/head/pwa.pug +18 -18
- package/layout/_partials/header.pug +18 -18
- package/layout/_partials/layout.pug +140 -140
- package/layout/_partials/loading.pug +13 -13
- package/layout/_partials/pagination.pug +4 -4
- package/layout/_partials/post/copyright.pug +20 -20
- package/layout/_partials/post/footer.pug +17 -17
- package/layout/_partials/post/nav.pug +13 -13
- package/layout/_partials/post/post.pug +41 -41
- package/layout/_partials/post/reward.pug +18 -18
- package/layout/_partials/sidebar/menu.pug +37 -37
- package/layout/_partials/sidebar/overview.pug +42 -42
- package/layout/_partials/third-party/baidu-analytics.pug +11 -11
- package/layout/_partials/third-party/clarity.pug +8 -8
- package/layout/_partials/third-party/google-analytics.pug +9 -9
- package/layout/archive.pug +118 -118
- package/layout/category.pug +59 -59
- package/layout/index.pug +33 -33
- package/layout/page.pug +55 -55
- package/layout/post.pug +36 -36
- package/layout/tag.pug +43 -43
- package/package.json +71 -72
- package/scripts/filters/locals.js +52 -0
- package/scripts/filters/post.js +5 -0
- package/scripts/generaters/archive.js +133 -0
- package/scripts/generaters/config.js +51 -0
- package/scripts/generaters/images.js +23 -0
- package/scripts/generaters/index.js +107 -0
- package/scripts/generaters/pages.js +15 -0
- package/scripts/generaters/script.js +156 -0
- package/scripts/helpers/asset.js +73 -0
- package/scripts/helpers/engine.js +177 -0
- package/scripts/helpers/list_categories.js +80 -0
- package/scripts/helpers/summary_ai.js +107 -0
- package/scripts/helpers/symbols_count_time.js +69 -0
- package/scripts/plugin/check.js +32 -0
- package/scripts/plugin/index.js +81 -0
- package/scripts/plugin/lib/injects-point.js +20 -0
- package/scripts/plugin/lib/injects.js +89 -0
- package/scripts/tags/links.js +44 -0
- package/scripts/tags/media.js +19 -0
- package/scripts/utils.js +13 -0
- package/source/assets/algolia_logo.svg +9 -9
- package/source/assets/logo.svg +16 -16
- package/source/css/_colors.styl +207 -207
- package/source/css/_common/components/components.styl +6 -6
- package/source/css/_common/components/highlight/highlight.styl +357 -357
- package/source/css/_common/components/highlight/operation.styl +21 -21
- package/source/css/_common/components/pages/collapse.styl +119 -119
- package/source/css/_common/components/pages/home.styl +391 -391
- package/source/css/_common/components/pages/pages.styl +56 -56
- package/source/css/_common/components/pages/tag-cloud.styl +12 -12
- package/source/css/_common/components/post/breadcrumb.styl +39 -39
- package/source/css/_common/components/post/copyright.styl +41 -41
- package/source/css/_common/components/post/expand.styl +263 -263
- package/source/css/_common/components/post/footer.styl +11 -11
- package/source/css/_common/components/post/header.styl +79 -79
- package/source/css/_common/components/post/nav.styl +64 -64
- package/source/css/_common/components/post/post.styl +29 -29
- package/source/css/_common/components/post/reward.styl +50 -50
- package/source/css/_common/components/post/rtl.styl +12 -12
- package/source/css/_common/components/post/tags.styl +39 -39
- package/source/css/_common/components/tags/collapse.styl +72 -72
- package/source/css/_common/components/tags/container.styl +49 -49
- package/source/css/_common/components/tags/label.styl +12 -12
- package/source/css/_common/components/tags/links.styl +77 -77
- package/source/css/_common/components/tags/list.styl +131 -131
- package/source/css/_common/components/tags/note.styl +70 -70
- package/source/css/_common/components/tags/player.styl +361 -361
- package/source/css/_common/components/tags/quiz.styl +200 -200
- package/source/css/_common/components/tags/tabs.styl +89 -89
- package/source/css/_common/components/tags/tags.styl +9 -9
- package/source/css/_common/components/third-party/loading.styl +222 -222
- package/source/css/_common/components/third-party/mermaid/class.styl +90 -90
- package/source/css/_common/components/third-party/mermaid/flowchart.styl +72 -72
- package/source/css/_common/components/third-party/mermaid/gantt.styl +251 -251
- package/source/css/_common/components/third-party/mermaid/git.styl +7 -7
- package/source/css/_common/components/third-party/mermaid/mermaid.styl +37 -37
- package/source/css/_common/components/third-party/mermaid/pie.styl +9 -9
- package/source/css/_common/components/third-party/mermaid/sequence.styl +95 -95
- package/source/css/_common/components/third-party/mermaid/state.styl +130 -130
- package/source/css/_common/components/third-party/pace.styl +18 -18
- package/source/css/_common/components/third-party/search.styl +167 -167
- package/source/css/_common/components/third-party/theme.styl +151 -151
- package/source/css/_common/components/third-party/third-party.styl +22 -22
- package/source/css/_common/components/third-party/widgets.styl +57 -57
- package/source/css/_common/outline/footer/footer.styl +67 -67
- package/source/css/_common/outline/header/brand.styl +77 -77
- package/source/css/_common/outline/header/header.styl +20 -20
- package/source/css/_common/outline/header/image.styl +85 -85
- package/source/css/_common/outline/header/menu.styl +117 -117
- package/source/css/_common/outline/header/nav.styl +81 -81
- package/source/css/_common/outline/header/right.styl +15 -15
- package/source/css/_common/outline/header/tool.styl +207 -207
- package/source/css/_common/outline/header/waves.styl +57 -57
- package/source/css/_common/outline/mobile.styl +46 -46
- package/source/css/_common/outline/outline.styl +78 -78
- package/source/css/_common/outline/sidebar/author.styl +59 -59
- package/source/css/_common/outline/sidebar/dimmer.styl +23 -23
- package/source/css/_common/outline/sidebar/menu.styl +63 -63
- package/source/css/_common/outline/sidebar/quick.styl +43 -43
- package/source/css/_common/outline/sidebar/related.styl +56 -56
- package/source/css/_common/outline/sidebar/sidebar.styl +80 -80
- package/source/css/_common/outline/sidebar/social.styl +69 -69
- package/source/css/_common/outline/sidebar/state.styl +37 -37
- package/source/css/_common/outline/sidebar/tab.styl +71 -71
- package/source/css/_common/outline/sidebar/toc.styl +47 -47
- package/source/css/_common/scaffolding/animate.styl +322 -322
- package/source/css/_common/scaffolding/base.styl +190 -190
- package/source/css/_common/scaffolding/buttons.styl +48 -48
- package/source/css/_common/scaffolding/divider.styl +36 -36
- package/source/css/_common/scaffolding/iconfont.styl +443 -443
- package/source/css/_common/scaffolding/normalize.styl +273 -273
- package/source/css/_common/scaffolding/pagination.styl +81 -81
- package/source/css/_common/scaffolding/ribbon.styl +38 -38
- package/source/css/_common/scaffolding/scaffolding.styl +14 -14
- package/source/css/_common/scaffolding/scrollbar.styl +37 -37
- package/source/css/_common/scaffolding/tables.styl +50 -50
- package/source/css/_common/scaffolding/tip.styl +19 -19
- package/source/css/_common/scaffolding/toggles.styl +59 -59
- package/source/css/_iconfont.styl +455 -455
- package/source/css/_mixins.styl +148 -148
- package/source/css/_variables.styl +89 -89
- package/source/css/app.styl +41 -41
- package/source/css/mermaid.styl +5 -5
- package/source/css/optimize.styl +5 -5
- package/source/js/_app/components/comments.ts +88 -88
- package/source/js/_app/components/sidebar.ts +239 -239
- package/source/js/_app/components/tcomments.ts +54 -54
- package/source/js/_app/globals/globalVars.ts +99 -99
- package/source/js/_app/globals/handles.ts +124 -124
- package/source/js/_app/globals/themeColor.ts +63 -63
- package/source/js/_app/globals/thirdparty.ts +63 -63
- package/source/js/_app/globals/tools.ts +75 -75
- package/source/js/_app/library/anime.ts +110 -110
- package/source/js/_app/library/declare.d.ts +128 -128
- package/source/js/_app/library/dom.ts +28 -28
- package/source/js/_app/library/loadFile.ts +47 -47
- package/source/js/_app/library/proto.ts +137 -137
- package/source/js/_app/library/scriptPjax.ts +72 -72
- package/source/js/_app/library/storage.ts +12 -12
- package/source/js/_app/library/vue.ts +49 -49
- package/source/js/_app/page/common.ts +43 -43
- package/source/js/_app/page/fancybox.ts +72 -72
- package/source/js/_app/page/post.ts +266 -266
- package/source/js/_app/page/search.ts +115 -115
- package/source/js/_app/page/tab.ts +60 -60
- package/source/js/_app/pjax/domInit.ts +97 -97
- package/source/js/_app/pjax/refresh.ts +140 -140
- package/source/js/_app/pjax/siteInit.ts +106 -106
- package/source/js/_app/player.ts +798 -798
- package/toolbox/compiler.mjs +10 -19
- package/toolbox/hoistdep.mjs +5 -5
- package/toolbox/lib.mjs +63 -63
- package/index.html +0 -231
- package/meta.json +0 -6431
@@ -0,0 +1,177 @@
|
|
1
|
+
'use strict';
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
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"));
|
9
|
+
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
|
+
};
|
34
|
+
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;
|
80
|
+
}
|
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];
|
85
|
+
}
|
86
|
+
if (attrs.class && Array.isArray(attrs.class)) {
|
87
|
+
attrs.class = attrs.class.join(' ');
|
88
|
+
}
|
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;
|
97
|
+
}
|
98
|
+
else {
|
99
|
+
return hexo_util_1.url_for.call(this, statics + (post_asset_folder ? path : '') + img);
|
100
|
+
}
|
101
|
+
});
|
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);
|
112
|
+
}
|
113
|
+
});
|
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
|
+
}
|
125
|
+
});
|
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;
|
138
|
+
});
|
139
|
+
hexo.extend.helper.register('canonical', function () {
|
140
|
+
return `<link rel="canonical" href="${this._permapath(this.url)}">`;
|
141
|
+
});
|
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}`);
|
153
|
+
});
|
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;
|
164
|
+
});
|
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)}`;
|
172
|
+
});
|
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('');
|
177
|
+
});
|
@@ -0,0 +1,80 @@
|
|
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);
|
12
|
+
};
|
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
|
+
}
|
58
|
+
});
|
59
|
+
return result;
|
60
|
+
});
|
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
|
+
});
|
77
|
+
}
|
78
|
+
});
|
79
|
+
return result;
|
80
|
+
});
|
@@ -0,0 +1,107 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
7
|
+
function getContent(post) {
|
8
|
+
return post?.raw ?? post?._content ?? post.content;
|
9
|
+
}
|
10
|
+
let db;
|
11
|
+
function postMessage(path, content, dbPath, startMessage) {
|
12
|
+
if (node_fs_1.default.existsSync('summary.json')) {
|
13
|
+
// @ts-ignore
|
14
|
+
db = JSON.parse(node_fs_1.default.readFileSync('summary.json', { encoding: 'utf-8' }));
|
15
|
+
}
|
16
|
+
else {
|
17
|
+
db = {};
|
18
|
+
}
|
19
|
+
const config = hexo.theme.config.summary;
|
20
|
+
if (config.enable) {
|
21
|
+
if (typeof db?.[path] !== 'undefined' && typeof db?.[path]?.[dbPath] !== 'undefined') {
|
22
|
+
return db[path][dbPath];
|
23
|
+
}
|
24
|
+
else {
|
25
|
+
if (typeof db?.[path] === 'undefined') {
|
26
|
+
db[path] = {};
|
27
|
+
}
|
28
|
+
else {
|
29
|
+
db[path][dbPath] = '';
|
30
|
+
}
|
31
|
+
}
|
32
|
+
if (config.mode === 'openai') {
|
33
|
+
const request = () => {
|
34
|
+
fetch(`${config.openai.remote}/v1/chat/completions`, {
|
35
|
+
method: 'POST',
|
36
|
+
headers: requestHeaders,
|
37
|
+
body: JSON.stringify(requestBody)
|
38
|
+
}).then((response) => {
|
39
|
+
if (!response.ok) {
|
40
|
+
throw Error('ERROR: Failed to get summary from Openai API');
|
41
|
+
}
|
42
|
+
response.json().then((data) => {
|
43
|
+
// @ts-ignore
|
44
|
+
const summary = data.choices[0].message.content;
|
45
|
+
try {
|
46
|
+
db[path][dbPath] = summary;
|
47
|
+
}
|
48
|
+
catch (e) {
|
49
|
+
db ??= {};
|
50
|
+
db[path] ??= {};
|
51
|
+
db[path][dbPath] ??= '';
|
52
|
+
db[path][dbPath] = summary;
|
53
|
+
}
|
54
|
+
node_fs_1.default.writeFileSync('summary.json', JSON.stringify(db));
|
55
|
+
if (node_fs_1.default.existsSync('requested.lock')) {
|
56
|
+
node_fs_1.default.unlinkSync('requested.lock');
|
57
|
+
}
|
58
|
+
return summary;
|
59
|
+
});
|
60
|
+
});
|
61
|
+
};
|
62
|
+
const checkTime = (waitTime) => {
|
63
|
+
if (node_fs_1.default.existsSync('request.lock')) {
|
64
|
+
if (node_fs_1.default.existsSync('requested.lock')) {
|
65
|
+
setTimeout(checkTime, 1000 * waitTime);
|
66
|
+
return;
|
67
|
+
}
|
68
|
+
// Openai API 针对个人用户免费试用限制 3 RPM,这里是25s后发送请求
|
69
|
+
node_fs_1.default.writeFileSync('requested.lock', '');
|
70
|
+
setTimeout(request, 1000 * 2.5 * waitTime);
|
71
|
+
node_fs_1.default.unlinkSync('request.lock');
|
72
|
+
}
|
73
|
+
else {
|
74
|
+
node_fs_1.default.writeFileSync('request.lock', '');
|
75
|
+
request();
|
76
|
+
}
|
77
|
+
};
|
78
|
+
const requestHeaders = {
|
79
|
+
'Content-Type': 'application/json',
|
80
|
+
Authorization: `Bearer ${config.openai.apikey}`
|
81
|
+
};
|
82
|
+
const requestBody = {
|
83
|
+
model: 'gpt-3.5-turbo',
|
84
|
+
messages: [{ role: 'user', content: `${startMessage} ${content}` }],
|
85
|
+
temperature: 0.7
|
86
|
+
};
|
87
|
+
if (config.pricing === 'trial') {
|
88
|
+
hexo.log.info('Requesting OpenAI API... (3 RPM mode)');
|
89
|
+
hexo.log.info('It may take 20 minutes or more (depending on the number of articles, each one takes 25 seconds)');
|
90
|
+
checkTime(10);
|
91
|
+
}
|
92
|
+
else {
|
93
|
+
hexo.log.info('Requesting OpenAI API... (60 RPM mode)');
|
94
|
+
checkTime(0.5);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
else {
|
98
|
+
// custom尚未支持
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
hexo.extend.helper.register('get_summary', (post) => {
|
103
|
+
return postMessage(post.path, getContent(post), 'summary', '请为下述文章提供一份200字以内的概括,使用中文回答且尽可能简洁: ');
|
104
|
+
});
|
105
|
+
hexo.extend.helper.register('get_introduce', () => {
|
106
|
+
return hexo.theme.config.summary.introduce;
|
107
|
+
});
|
@@ -0,0 +1,69 @@
|
|
1
|
+
'use strict';
|
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
|
+
*/
|
9
|
+
const hexo_util_1 = require("hexo-util");
|
10
|
+
const config = hexo.config.symbols_count_time = Object.assign({
|
11
|
+
symbols: true,
|
12
|
+
time: true,
|
13
|
+
total_symbols: true,
|
14
|
+
total_time: true,
|
15
|
+
exclude_codeblock: false,
|
16
|
+
awl: 4,
|
17
|
+
wpm: 275,
|
18
|
+
suffix: 'mins.'
|
19
|
+
}, hexo.config.symbols_count_time);
|
20
|
+
function getSymbols(post) {
|
21
|
+
return post?._content?.length ?? post?.content?.length ?? post.length;
|
22
|
+
}
|
23
|
+
function getSymbolsTotal(site) {
|
24
|
+
let symbolsResultCount = 0;
|
25
|
+
site.posts.forEach((post) => {
|
26
|
+
symbolsResultCount += getSymbols(post);
|
27
|
+
});
|
28
|
+
return symbolsResultCount;
|
29
|
+
}
|
30
|
+
function getFormatTime(minutes, suffix) {
|
31
|
+
const fHours = Math.floor(minutes / 60);
|
32
|
+
let fMinutes = Math.floor(minutes - (fHours * 60));
|
33
|
+
if (fMinutes < 1) {
|
34
|
+
fMinutes = 1; // 0 => 1
|
35
|
+
}
|
36
|
+
return fHours < 1
|
37
|
+
? fMinutes + ' ' + suffix // < 59 => 59 mins.
|
38
|
+
: fHours + ':' + ('00' + fMinutes).slice(-2); // = 61 => 1:01
|
39
|
+
}
|
40
|
+
hexo.extend.helper.register('symbolsCount', function (post) {
|
41
|
+
let symbolsResult = getSymbols(post);
|
42
|
+
if (symbolsResult > 9999) {
|
43
|
+
symbolsResult = Math.round(symbolsResult / 1000) + 'k'; // > 9999 => 11k
|
44
|
+
}
|
45
|
+
else if (symbolsResult > 999) {
|
46
|
+
symbolsResult = Math.round(symbolsResult / 100) / 10 + 'k'; // > 999 => 1.1k
|
47
|
+
} // < 999 => 111
|
48
|
+
return symbolsResult;
|
49
|
+
});
|
50
|
+
hexo.extend.helper.register('symbolsTime', function (post, awl = config.awl, wpm = config.wpm, suffix = config.suffix) {
|
51
|
+
const minutes = Math.round(getSymbols(post) / (awl * wpm));
|
52
|
+
return getFormatTime(minutes, suffix);
|
53
|
+
});
|
54
|
+
hexo.extend.helper.register('symbolsCountTotal', function (site) {
|
55
|
+
const symbolsResultTotal = getSymbolsTotal(site);
|
56
|
+
return symbolsResultTotal < 1000000
|
57
|
+
? Math.round(symbolsResultTotal / 1000) + 'k' // < 999k => 111k
|
58
|
+
: Math.round(symbolsResultTotal / 100000) / 10 + 'm'; // > 999k => 1.1m
|
59
|
+
});
|
60
|
+
hexo.extend.helper.register('symbolsTimeTotal', function (site, awl = config.awl, wpm = config.wpm, suffix = config.suffix) {
|
61
|
+
const minutes = Math.round(getSymbolsTotal(site) / (awl * wpm));
|
62
|
+
return getFormatTime(minutes, suffix);
|
63
|
+
});
|
64
|
+
hexo.extend.filter.register('after_post_render', (data) => {
|
65
|
+
let { content } = data;
|
66
|
+
if (config.exclude_codeblock)
|
67
|
+
content = content.replace(/<pre>.*?<\/pre>/g, '');
|
68
|
+
data.length = (0, hexo_util_1.stripHTML)(content).replace(/\r?\n|\r/g, '').replace(/\s+/g, '').length;
|
69
|
+
}, 0);
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/* global hexo */
|
2
|
+
let findProblem = false;
|
3
|
+
hexo.on('generateBefore', function () {
|
4
|
+
if (hexo.config.syntax_highlighter) {
|
5
|
+
findProblem = true;
|
6
|
+
hexo.log.error('[SXEC 101] Highlight.js or Prismjs enabled. The code block will render incomplete');
|
7
|
+
}
|
8
|
+
if (!hexo.config.markdown) {
|
9
|
+
findProblem = true;
|
10
|
+
hexo.log.error(`[SXEC 102] Critical rendering plugins are missing or incorrectly configured.
|
11
|
+
Some features will be disabled or render incorrectly`);
|
12
|
+
}
|
13
|
+
if (parseInt(process.version.match(/\d{2,3}/)[0]) < 18) {
|
14
|
+
findProblem = true;
|
15
|
+
hexo.log.error('[SXEC 103] Too old Node.js version, install the latest LTS version');
|
16
|
+
}
|
17
|
+
if (!hexo.config.title || !hexo.config.description || !hexo.config.language || !hexo.config.timezone || !hexo.config.url) {
|
18
|
+
findProblem = true;
|
19
|
+
hexo.log.warn('[SXEC 201] Essential information(title, desc, lang, etc) config incorrectly, Page will render incorrectly');
|
20
|
+
}
|
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');
|
24
|
+
}
|
25
|
+
});
|
26
|
+
hexo.on('generateAfter', function () {
|
27
|
+
if (findProblem) {
|
28
|
+
hexo.log.warn(`The environment check found some problems that can lead to rendering errors, effect errors,
|
29
|
+
performance degradation, not working correctly, etc`);
|
30
|
+
hexo.log.warn('ShokaX has output them into console, read them to get more information. You can search error code in docs(For example, SXEC 101)');
|
31
|
+
}
|
32
|
+
});
|
@@ -0,0 +1,81 @@
|
|
1
|
+
"use strict";
|
2
|
+
/*!
|
3
|
+
index.js in next-theme/hexo-theme-next by next-theme
|
4
|
+
under GNU AFFERO GENERAL PUBLIC LICENSE v3.0 OR LATER
|
5
|
+
https://github.com/next-theme/hexo-theme-next/blob/master/LICENSE.md
|
6
|
+
*/
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
8
|
+
if (k2 === undefined) k2 = k;
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
12
|
+
}
|
13
|
+
Object.defineProperty(o, k2, desc);
|
14
|
+
}) : (function(o, m, k, k2) {
|
15
|
+
if (k2 === undefined) k2 = k;
|
16
|
+
o[k2] = m[k];
|
17
|
+
}));
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
20
|
+
}) : function(o, v) {
|
21
|
+
o["default"] = v;
|
22
|
+
});
|
23
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
24
|
+
if (mod && mod.__esModule) return mod;
|
25
|
+
var result = {};
|
26
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
27
|
+
__setModuleDefault(result, mod);
|
28
|
+
return result;
|
29
|
+
};
|
30
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
31
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
32
|
+
};
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
34
|
+
const injects_1 = __importDefault(require("./lib/injects"));
|
35
|
+
const package_json_1 = require("../../package.json");
|
36
|
+
const fs = __importStar(require("node:fs"));
|
37
|
+
hexo.on('generateBefore', () => {
|
38
|
+
// 加载`theme_injects`过滤器
|
39
|
+
(0, injects_1.default)(hexo);
|
40
|
+
fs.rmSync('./shokaxTemp', { force: true, recursive: true });
|
41
|
+
if (fs.existsSync('request.lock')) {
|
42
|
+
fs.unlinkSync('request.lock');
|
43
|
+
}
|
44
|
+
if (fs.existsSync('requested.lock')) {
|
45
|
+
fs.unlinkSync('requested.lock');
|
46
|
+
}
|
47
|
+
});
|
48
|
+
hexo.on('generateAfter', () => {
|
49
|
+
// 检查版本更新
|
50
|
+
fetch('https://api.shokax.top/version/hexo', { headers: {
|
51
|
+
"User-Agent": "Mozilla/5.0 ShokaX Client (hexo-theme-shokax)"
|
52
|
+
} }).then((res) => {
|
53
|
+
res.json().then((resp) => {
|
54
|
+
try {
|
55
|
+
const latest = resp['version'];
|
56
|
+
const current = package_json_1.version.split('.');
|
57
|
+
let isOutdated = false;
|
58
|
+
for (let i = 0; i < Math.max(latest.length, current.length); i++) {
|
59
|
+
if (!current[i] || latest[i] > current[i]) {
|
60
|
+
isOutdated = true;
|
61
|
+
break;
|
62
|
+
}
|
63
|
+
if (latest[i] < current[i]) {
|
64
|
+
break;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
if (isOutdated) {
|
68
|
+
hexo.log.warn(`Your theme ShokaX is outdated. Current version: v${current.join('.')}, latest version: v${latest.join('.')}`);
|
69
|
+
hexo.log.warn('Visit https://github.com/theme-shoka-x/hexo-theme-shokaX/releases for more information.');
|
70
|
+
}
|
71
|
+
}
|
72
|
+
catch (e) {
|
73
|
+
hexo.log.warn('Failed to detect version info. Error message:');
|
74
|
+
hexo.log.warn(e);
|
75
|
+
}
|
76
|
+
}).catch((e) => {
|
77
|
+
hexo.log.warn('Failed to detect version info. Error message:');
|
78
|
+
hexo.log.warn(e);
|
79
|
+
});
|
80
|
+
});
|
81
|
+
});
|
@@ -0,0 +1,20 @@
|
|
1
|
+
'use strict';
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.default = {
|
4
|
+
views: [
|
5
|
+
'head',
|
6
|
+
'sidebar',
|
7
|
+
'rightNav',
|
8
|
+
'postMeta',
|
9
|
+
'postBodyEnd',
|
10
|
+
'footer',
|
11
|
+
'bodyEnd',
|
12
|
+
'comment',
|
13
|
+
'status'
|
14
|
+
],
|
15
|
+
styles: [
|
16
|
+
'variable',
|
17
|
+
'mixin',
|
18
|
+
'style'
|
19
|
+
]
|
20
|
+
};
|
@@ -0,0 +1,89 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
/*!
|
7
|
+
inject.js in next-theme/hexo-theme-next by next-theme
|
8
|
+
under GNU AFFERO GENERAL PUBLIC LICENSE v3.0 OR LATER
|
9
|
+
https://github.com/next-theme/hexo-theme-next/blob/master/LICENSE.md
|
10
|
+
*/
|
11
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
12
|
+
const node_path_1 = __importDefault(require("node:path"));
|
13
|
+
const injects_point_1 = __importDefault(require("./injects-point"));
|
14
|
+
const defaultExtname = '.pug';
|
15
|
+
class StylusInject {
|
16
|
+
files;
|
17
|
+
base_dir;
|
18
|
+
constructor(base_dir) {
|
19
|
+
this.base_dir = base_dir;
|
20
|
+
this.files = [];
|
21
|
+
}
|
22
|
+
push(file) {
|
23
|
+
this.files.push(node_path_1.default.resolve(this.base_dir, file));
|
24
|
+
}
|
25
|
+
}
|
26
|
+
// Defining view types
|
27
|
+
class ViewInject {
|
28
|
+
base_dir;
|
29
|
+
raws;
|
30
|
+
constructor(base_dir) {
|
31
|
+
this.base_dir = base_dir;
|
32
|
+
this.raws = [];
|
33
|
+
}
|
34
|
+
raw(name, raw, ...args) {
|
35
|
+
// Set default extname
|
36
|
+
if (node_path_1.default.extname(name) === '') {
|
37
|
+
name += defaultExtname;
|
38
|
+
}
|
39
|
+
this.raws.push({ name, raw, args });
|
40
|
+
}
|
41
|
+
file(name, file, ...args) {
|
42
|
+
// Set default extname from file's extname
|
43
|
+
if (node_path_1.default.extname(name) === '') {
|
44
|
+
name += node_path_1.default.extname(file);
|
45
|
+
}
|
46
|
+
// Get absolute path base on hexo dir
|
47
|
+
this.raw(name, node_fs_1.default.readFileSync(node_path_1.default.resolve(this.base_dir, file), 'utf8'), ...args);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
// Init injects
|
51
|
+
function initInject(base_dir) {
|
52
|
+
const injects = {};
|
53
|
+
injects_point_1.default.styles.forEach(item => {
|
54
|
+
injects[item] = new StylusInject(base_dir);
|
55
|
+
});
|
56
|
+
injects_point_1.default.views.forEach(item => {
|
57
|
+
injects[item] = new ViewInject(base_dir);
|
58
|
+
});
|
59
|
+
return injects;
|
60
|
+
}
|
61
|
+
exports.default = (hexo) => {
|
62
|
+
// Exec theme_inject filter
|
63
|
+
const injects = initInject(hexo.base_dir);
|
64
|
+
hexo.execFilterSync('theme_inject', injects);
|
65
|
+
hexo.theme.config.injects = {};
|
66
|
+
// Inject stylus
|
67
|
+
injects_point_1.default.styles.forEach(type => {
|
68
|
+
hexo.theme.config.injects[type] = injects[type].files;
|
69
|
+
});
|
70
|
+
// Inject views
|
71
|
+
injects_point_1.default.views.forEach(type => {
|
72
|
+
const configs = Object.create(null);
|
73
|
+
hexo.theme.config.injects[type] = [];
|
74
|
+
// Add or override view.
|
75
|
+
injects[type].raws.forEach((injectObj, index) => {
|
76
|
+
const name = `inject/${type}/${injectObj.name}`;
|
77
|
+
hexo.theme.setView(name, injectObj.raw);
|
78
|
+
configs[name] = {
|
79
|
+
layout: name,
|
80
|
+
locals: injectObj.args[0],
|
81
|
+
options: injectObj.args[1],
|
82
|
+
order: injectObj.args[2] || index
|
83
|
+
};
|
84
|
+
});
|
85
|
+
// Views sort.
|
86
|
+
hexo.theme.config.injects[type] = Object.values(configs)
|
87
|
+
.sort((x, y) => x.order - y.order);
|
88
|
+
});
|
89
|
+
};
|