hexo-theme-shokax 0.3.14 → 0.3.15
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- 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 +48 -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 +118 -0
- package/scripts/helpers/asset.js +147 -0
- package/scripts/helpers/engine.js +153 -0
- package/scripts/helpers/list_categories.js +84 -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 +78 -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 +14 -0
- package/source/js/_app/components/sidebar.js +209 -0
- package/source/js/_app/fireworks.js +10 -0
- package/source/js/_app/globals/globalVars.js +80 -0
- package/source/js/_app/globals/handles.js +98 -0
- package/source/js/_app/globals/themeColor.js +62 -0
- package/source/js/_app/globals/thirdparty.js +62 -0
- package/source/js/_app/globals/tools.js +66 -0
- package/source/js/_app/library/anime.js +106 -0
- package/source/js/_app/library/dom.js +34 -0
- package/source/js/_app/library/loadFile.js +36 -0
- package/source/js/_app/library/proto.js +163 -0
- package/source/js/_app/library/scriptPjax.js +70 -0
- package/source/js/_app/library/storage.js +12 -0
- package/source/js/_app/library/vue.js +53 -0
- package/source/js/_app/page/comment.js +23 -0
- package/source/js/_app/page/common.js +41 -0
- package/source/js/_app/page/fancybox.js +65 -0
- package/source/js/_app/page/post.js +244 -0
- package/source/js/_app/page/search.js +118 -0
- package/source/js/_app/page/tab.js +53 -0
- package/source/js/_app/pjax/domInit.js +76 -0
- package/source/js/_app/pjax/refresh.js +52 -0
- package/source/js/_app/pjax/siteInit.js +51 -0
- package/source/js/_app/player.js +771 -0
@@ -0,0 +1,153 @@
|
|
1
|
+
'use strict';
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
// @ts-ignore
|
4
|
+
const hexo_util_1 = require("hexo-util");
|
5
|
+
const randomServer = parseInt(String(Math.random() * 4), 10) + 1;
|
6
|
+
const randomBG = function (count = 1, image_server = null, image_list = []) {
|
7
|
+
let i;
|
8
|
+
if (image_server) {
|
9
|
+
if (count && count > 1) {
|
10
|
+
const arr = new Array(count);
|
11
|
+
for (i = 0; i < arr.length; i++) {
|
12
|
+
arr[i] = image_server + '?' + Math.floor(Math.random() * 999999);
|
13
|
+
}
|
14
|
+
return arr;
|
15
|
+
}
|
16
|
+
return image_server + '?' + Math.floor(Math.random() * 999999);
|
17
|
+
}
|
18
|
+
const parseImage = function (img, size) {
|
19
|
+
if (img.startsWith('//') || img.startsWith('http')) {
|
20
|
+
return img;
|
21
|
+
}
|
22
|
+
else if (hexo.theme.config.experiments?.usingRelative) { // support relative url
|
23
|
+
return img;
|
24
|
+
}
|
25
|
+
else {
|
26
|
+
console.warn("sinaimg blocked all request from outside website,so don't use this format");
|
27
|
+
return `https://tva${randomServer}.sinaimg.cn/` + size + '/' + img;
|
28
|
+
}
|
29
|
+
};
|
30
|
+
if (count && count > 1) {
|
31
|
+
let shuffled = image_list.slice(0);
|
32
|
+
while (shuffled.length <= 6) {
|
33
|
+
shuffled = shuffled.concat(image_list.slice(0));
|
34
|
+
}
|
35
|
+
i = shuffled.length;
|
36
|
+
const min = i - count;
|
37
|
+
let temp;
|
38
|
+
let index;
|
39
|
+
while (i-- > min) {
|
40
|
+
index = Math.floor((i + 1) * Math.random());
|
41
|
+
temp = shuffled[index];
|
42
|
+
shuffled[index] = shuffled[i];
|
43
|
+
shuffled[i] = temp;
|
44
|
+
}
|
45
|
+
return shuffled.slice(min).map(function (img) {
|
46
|
+
return parseImage(img, 'large');
|
47
|
+
});
|
48
|
+
}
|
49
|
+
return parseImage(image_list[Math.floor(Math.random() * image_list.length)], 'mw690');
|
50
|
+
};
|
51
|
+
// 注册hexo主题中的URL帮助方法
|
52
|
+
hexo.extend.helper.register('_url', function (path, text, options = {}) {
|
53
|
+
// 如果未提供URL路径,则返回
|
54
|
+
if (!path) {
|
55
|
+
return;
|
56
|
+
}
|
57
|
+
let tag = 'a';
|
58
|
+
let attrs = { href: hexo_util_1.url_for.call(this, path), class: undefined, external: undefined, rel: undefined, 'data-url': undefined };
|
59
|
+
for (const key in options) {
|
60
|
+
attrs[key] = options[key];
|
61
|
+
}
|
62
|
+
if (attrs.class && Array.isArray(attrs.class)) {
|
63
|
+
attrs.class = attrs.class.join(' ');
|
64
|
+
}
|
65
|
+
// 返回HTML标记字符串
|
66
|
+
return (0, hexo_util_1.htmlTag)(tag, attrs, decodeURI(text), false);
|
67
|
+
});
|
68
|
+
hexo.extend.helper.register('_image_url', function (img, path = '') {
|
69
|
+
const { statics } = hexo.theme.config;
|
70
|
+
const { post_asset_folder } = hexo.config;
|
71
|
+
if (img.startsWith('//') || img.startsWith('http')) {
|
72
|
+
return img;
|
73
|
+
}
|
74
|
+
else {
|
75
|
+
return hexo_util_1.url_for.call(this, statics + (post_asset_folder ? path : '') + img);
|
76
|
+
}
|
77
|
+
});
|
78
|
+
hexo.extend.helper.register('_cover', function (item, num) {
|
79
|
+
const { image_server, image_list } = hexo.theme.config;
|
80
|
+
if (item.cover) {
|
81
|
+
return this._image_url(item.cover, item.path);
|
82
|
+
}
|
83
|
+
else if (item.photos && item.photos.length > 0) {
|
84
|
+
return this._image_url(item.photos[0], item.path);
|
85
|
+
}
|
86
|
+
else {
|
87
|
+
return randomBG(num || 1, image_server, image_list);
|
88
|
+
}
|
89
|
+
});
|
90
|
+
hexo.extend.helper.register('_cover_index', function (item) {
|
91
|
+
const { index_images, image_list, image_server } = hexo.theme.config;
|
92
|
+
if (item.cover) {
|
93
|
+
return this._image_url(item.cover, item.path);
|
94
|
+
}
|
95
|
+
else if (item.photos && item.photos.length > 0) {
|
96
|
+
return this._image_url(item.photos[0], item.path);
|
97
|
+
}
|
98
|
+
else {
|
99
|
+
return randomBG(1, image_server, index_images.length === 0 ? image_list : index_images);
|
100
|
+
}
|
101
|
+
});
|
102
|
+
// 注册hexo主题的永久链接帮助方法
|
103
|
+
hexo.extend.helper.register('_permapath', function (str) {
|
104
|
+
// 获取hexo的永久链接配置
|
105
|
+
const { permalink } = hexo.config;
|
106
|
+
// 将输入字符串中的'index.html'替换为空字符串
|
107
|
+
let url = str.replace(/index\.html$/, '');
|
108
|
+
// 如果永久链接不以'.html'结尾,将输入字符串中的'.html'替换为空字符串
|
109
|
+
if (!permalink.endsWith('.html')) {
|
110
|
+
url = url.replace(/\.html$/, '');
|
111
|
+
}
|
112
|
+
// 返回处理后的URL字符串
|
113
|
+
return url;
|
114
|
+
});
|
115
|
+
hexo.extend.helper.register('canonical', function () {
|
116
|
+
return `<link rel="canonical" href="${this._permapath(this.url)}">`;
|
117
|
+
});
|
118
|
+
/**
|
119
|
+
* Get page path given a certain language tag
|
120
|
+
*/
|
121
|
+
// 注册hexo主题的国际化路径帮助方法
|
122
|
+
hexo.extend.helper.register('i18n_path', function (language) {
|
123
|
+
// 获取当前页面的path和lang
|
124
|
+
const { path, lang } = this.page;
|
125
|
+
// 如果path以lang开头,则截取掉lang部分,作为基础路径
|
126
|
+
const base = path.startsWith(lang) ? path.slice(lang.length + 1) : path;
|
127
|
+
// 通过调用url_for方法,生成国际化路径
|
128
|
+
return hexo_util_1.url_for.call(this, `${this.languages.indexOf(language) === 0 ? '' : '/' + language}/${base}`);
|
129
|
+
});
|
130
|
+
/**
|
131
|
+
* Get the language name
|
132
|
+
*/
|
133
|
+
// 注册hexo主题的语言名称帮助方法
|
134
|
+
hexo.extend.helper.register('language_name', function (language) {
|
135
|
+
// 从主题配置中获取指定语言的名称
|
136
|
+
// @ts-ignore
|
137
|
+
const name = hexo.theme.i18n.__(language)('name');
|
138
|
+
// 如果名称为默认值'name',则返回语言代码,否则返回语言名称
|
139
|
+
return name === 'name' ? language : name;
|
140
|
+
});
|
141
|
+
hexo.extend.helper.register('random_color', function () {
|
142
|
+
const arr = [];
|
143
|
+
for (let i = 0; i < 3; i++) {
|
144
|
+
arr.push(Math.floor(Math.random() * 128 + 128));
|
145
|
+
}
|
146
|
+
const [r, g, b] = arr;
|
147
|
+
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)}`;
|
148
|
+
});
|
149
|
+
hexo.extend.helper.register('shokax_inject', function (point) {
|
150
|
+
return hexo.theme.config.injects[point]
|
151
|
+
.map(item => this.partial(item.layout, item.locals, item.options))
|
152
|
+
.join('');
|
153
|
+
});
|
@@ -0,0 +1,84 @@
|
|
1
|
+
'use strict';
|
2
|
+
/* global hexo */
|
3
|
+
const prepareQuery = (categories, parent) => {
|
4
|
+
const query = {
|
5
|
+
parent: undefined
|
6
|
+
};
|
7
|
+
if (parent) {
|
8
|
+
query.parent = parent;
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
query.parent = { $exists: false };
|
12
|
+
}
|
13
|
+
return categories.find(query).sort('name', 1).filter(cat => cat.length);
|
14
|
+
};
|
15
|
+
hexo.extend.helper.register('_list_categories', function (depth = 0) {
|
16
|
+
// let hexo = this
|
17
|
+
const categories = this.site.categories;
|
18
|
+
if (!categories || !categories.length)
|
19
|
+
return '';
|
20
|
+
const hierarchicalList = (level, parent) => {
|
21
|
+
let result = '';
|
22
|
+
prepareQuery(categories, parent).forEach((cat, i) => {
|
23
|
+
let child;
|
24
|
+
if (level + 1 < depth) {
|
25
|
+
child = hierarchicalList(level + 1, cat._id);
|
26
|
+
}
|
27
|
+
const catname = `<a itemprop="url" href="${this.url_for(cat.path)}">${cat.name}</a><small>( ${cat.length} )</small>`;
|
28
|
+
switch (level) {
|
29
|
+
case 0:
|
30
|
+
result += `<div><h2 class="item header">${catname}</h2>`;
|
31
|
+
break;
|
32
|
+
case 1:
|
33
|
+
result += `<h3 class="item section">${catname}</h3>`;
|
34
|
+
break;
|
35
|
+
case 2:
|
36
|
+
result += `<div class="item normal"><div class="title">${catname}</div></div>`;
|
37
|
+
break;
|
38
|
+
}
|
39
|
+
if (child) {
|
40
|
+
result += `${child}`;
|
41
|
+
}
|
42
|
+
if (level === 0) {
|
43
|
+
result += '</div>';
|
44
|
+
}
|
45
|
+
});
|
46
|
+
return result;
|
47
|
+
};
|
48
|
+
return hierarchicalList(0);
|
49
|
+
});
|
50
|
+
hexo.extend.helper.register('_category_prev', function (name) {
|
51
|
+
// let hexo = this
|
52
|
+
const categories = this.site.categories;
|
53
|
+
if (!categories || !categories.length)
|
54
|
+
return '';
|
55
|
+
let result = '';
|
56
|
+
categories.find({ name }).forEach((current) => {
|
57
|
+
if (current.parent) {
|
58
|
+
categories.find({ _id: current.parent }).forEach((cat, i) => {
|
59
|
+
result += `<a href="${this.url_for(cat.path)}">${cat.name}</a>`;
|
60
|
+
});
|
61
|
+
}
|
62
|
+
});
|
63
|
+
return result;
|
64
|
+
});
|
65
|
+
hexo.extend.helper.register('_category_posts', function (page) {
|
66
|
+
// let hexo = this
|
67
|
+
const categories = this.site.categories;
|
68
|
+
if (!categories || !categories.length || !page.categories || !page.categories.length)
|
69
|
+
return '';
|
70
|
+
let result = '';
|
71
|
+
const cat = page.categories.toArray();
|
72
|
+
categories.find({ _id: cat[cat.length - 1]._id }).forEach((category) => {
|
73
|
+
if (category.posts) {
|
74
|
+
category.posts.sort('date', 1).forEach((post) => {
|
75
|
+
let current = '';
|
76
|
+
if (post.path === page.path) {
|
77
|
+
current = ' class="active"';
|
78
|
+
}
|
79
|
+
result += `<li ${current}><a href="${this.url_for(post.path)}" rel="bookmark" title="${post.title}">${post.title}</a></li>`;
|
80
|
+
});
|
81
|
+
}
|
82
|
+
});
|
83
|
+
return result;
|
84
|
+
});
|
@@ -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,78 @@
|
|
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
|
+
if (fs.existsSync('request.lock')) {
|
41
|
+
fs.unlinkSync('request.lock');
|
42
|
+
}
|
43
|
+
if (fs.existsSync('requested.lock')) {
|
44
|
+
fs.unlinkSync('requested.lock');
|
45
|
+
}
|
46
|
+
});
|
47
|
+
hexo.on('generateAfter', () => {
|
48
|
+
// 检查版本更新
|
49
|
+
fetch('https://api.github.com/repos/theme-shoka-x/hexo-theme-shokaX/releases/latest').then((res) => {
|
50
|
+
res.json().then((resp) => {
|
51
|
+
try {
|
52
|
+
const latest = resp.tag_name.replace('v', '').split('.');
|
53
|
+
const current = package_json_1.version.split('.');
|
54
|
+
let isOutdated = false;
|
55
|
+
for (let i = 0; i < Math.max(latest.length, current.length); i++) {
|
56
|
+
if (!current[i] || latest[i] > current[i]) {
|
57
|
+
isOutdated = true;
|
58
|
+
break;
|
59
|
+
}
|
60
|
+
if (latest[i] < current[i]) {
|
61
|
+
break;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
if (isOutdated) {
|
65
|
+
hexo.log.warn(`Your theme ShokaX is outdated. Current version: v${current.join('.')}, latest version: v${latest.join('.')}`);
|
66
|
+
hexo.log.warn('Visit https://github.com/theme-shoka-x/hexo-theme-shokaX/releases for more information.');
|
67
|
+
}
|
68
|
+
}
|
69
|
+
catch (e) {
|
70
|
+
hexo.log.warn('Failed to detect version info. Error message:');
|
71
|
+
hexo.log.warn(e);
|
72
|
+
}
|
73
|
+
}).catch((e) => {
|
74
|
+
hexo.log.warn('Failed to detect version info. Error message:');
|
75
|
+
hexo.log.warn(e);
|
76
|
+
});
|
77
|
+
});
|
78
|
+
});
|
@@ -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
|
+
};
|
@@ -0,0 +1,44 @@
|
|
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
|
+
const node_path_1 = __importDefault(require("node:path"));
|
8
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
9
|
+
function linkGrid(args, content) {
|
10
|
+
const theme = hexo.theme.config;
|
11
|
+
if (!args[0] && !content) {
|
12
|
+
return;
|
13
|
+
}
|
14
|
+
if (args[0]) {
|
15
|
+
const filepath = node_path_1.default.join(hexo.source_dir, args[0]);
|
16
|
+
if (node_fs_1.default.existsSync(filepath)) {
|
17
|
+
content = node_fs_1.default.readFileSync(filepath, { encoding: 'utf-8' });
|
18
|
+
}
|
19
|
+
}
|
20
|
+
if (!content) {
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
const list = js_yaml_1.default.load(content);
|
24
|
+
let result = '';
|
25
|
+
list.forEach((item) => {
|
26
|
+
if (!item.url || !item.site) {
|
27
|
+
return;
|
28
|
+
}
|
29
|
+
let item_image = item.image || theme.assets + '/404.png';
|
30
|
+
if (!item_image.startsWith('//') && !item_image.startsWith('http')) {
|
31
|
+
item_image = theme.statics + item_image;
|
32
|
+
}
|
33
|
+
item.color = item.color ? ` style="--block-color:${item.color};"` : '';
|
34
|
+
result += `<div class="item" title="${item.owner || item.site}"${item.color}>`;
|
35
|
+
result += `<a href="${item.url}" class="image" data-background-image="${item_image}"></a>
|
36
|
+
<div class="info">
|
37
|
+
<a href="${item.url}" class="title">${item.site}</a>
|
38
|
+
<p class="desc">${item.desc || item.url}</p>
|
39
|
+
</div></div>`;
|
40
|
+
});
|
41
|
+
return `<div class="links">${result}</div>`;
|
42
|
+
}
|
43
|
+
hexo.extend.tag.register('links', linkGrid, { ends: true });
|
44
|
+
hexo.extend.tag.register('linksfile', linkGrid, { ends: false, async: true });
|