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
package/package.json
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
// @ts-ignore
|
2
|
+
const fmtNum = (num) => {
|
3
|
+
return num < 10 ? '0' + num : num;
|
4
|
+
};
|
5
|
+
hexo.extend.filter.register('template_locals', (locals) => {
|
6
|
+
const { config } = hexo;
|
7
|
+
const { __, theme } = locals;
|
8
|
+
// @ts-ignore
|
9
|
+
const { i18n } = hexo.theme;
|
10
|
+
const pangu = {
|
11
|
+
spacing: (data) => {
|
12
|
+
return data;
|
13
|
+
}
|
14
|
+
};
|
15
|
+
// Language & Config
|
16
|
+
// 根据主题配置的 Creative Commons 许可证生成链接
|
17
|
+
locals.alternate = theme.alternate;
|
18
|
+
locals.title = pangu.spacing(__('title') !== 'title' ? __('title') : config.title);
|
19
|
+
locals.subtitle = pangu.spacing(__('subtitle') !== 'subtitle' ? __('subtitle') : config.subtitle);
|
20
|
+
locals.author = __('author') !== 'author' ? __('author') : config.author;
|
21
|
+
locals.description = pangu.spacing(__('description') !== 'description' ? __('description') : config.description);
|
22
|
+
locals.languages = [...i18n.languages];
|
23
|
+
locals.languages.splice(locals.languages.indexOf('default'), 1);
|
24
|
+
locals.page.lang = locals.page.lang || locals.page.language;
|
25
|
+
locals.hostname = new URL(config.url).hostname || config.url;
|
26
|
+
// Creative Commons
|
27
|
+
// 根据主题配置的 Creative Commons 许可证生成链接
|
28
|
+
if (theme.creative_commons.license === 'zero') {
|
29
|
+
locals.ccURL = 'https://creativecommons.org/' + 'publicdomain/zero/1.0/' + (theme.creative_commons.language || '');
|
30
|
+
}
|
31
|
+
else {
|
32
|
+
locals.ccURL = 'https://creativecommons.org/' + 'licenses/' + theme.creative_commons.license + '/4.0/' + (theme.creative_commons.language || '');
|
33
|
+
}
|
34
|
+
if (locals.page.title) {
|
35
|
+
locals.page.title = pangu.spacing(locals.page.title);
|
36
|
+
}
|
37
|
+
locals.page.lastcat = '';
|
38
|
+
if (locals.page.categories) {
|
39
|
+
locals.page.categories.map((cat) => {
|
40
|
+
if (cat.name) {
|
41
|
+
cat.name = locals.page.lastcat = pangu.spacing(cat.name);
|
42
|
+
}
|
43
|
+
return cat;
|
44
|
+
});
|
45
|
+
}
|
46
|
+
if (locals.page.category) {
|
47
|
+
locals.page.title = pangu.spacing(locals.page.category);
|
48
|
+
}
|
49
|
+
if (locals.page.month) {
|
50
|
+
locals.page.month = fmtNum(locals.page.month);
|
51
|
+
}
|
52
|
+
});
|
@@ -0,0 +1,133 @@
|
|
1
|
+
/* global hexo */
|
2
|
+
'use strict';
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
5
|
+
};
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
7
|
+
// @ts-ignore
|
8
|
+
const hexo_pagination_1 = __importDefault(require("hexo-pagination"));
|
9
|
+
// @ts-ignore
|
10
|
+
const fmtNum = num => {
|
11
|
+
return num < 10 ? '0' + num : num;
|
12
|
+
};
|
13
|
+
if (!(hexo.config.archive && hexo.config.archive.enabled === false)) {
|
14
|
+
// when archive disabled pagination, per_page should be 0.
|
15
|
+
let per_page;
|
16
|
+
if (hexo.config.archive === 1) {
|
17
|
+
per_page = 0;
|
18
|
+
}
|
19
|
+
else if (typeof hexo.config.per_page === 'undefined') {
|
20
|
+
per_page = 10;
|
21
|
+
}
|
22
|
+
else {
|
23
|
+
per_page = hexo.config.per_page;
|
24
|
+
}
|
25
|
+
hexo.config.archive_generator = Object.assign({
|
26
|
+
per_page,
|
27
|
+
yearly: true,
|
28
|
+
monthly: true,
|
29
|
+
daily: false
|
30
|
+
}, hexo.config.archive_generator);
|
31
|
+
hexo.extend.generator.register('archive', function (locals) {
|
32
|
+
const config = hexo.config;
|
33
|
+
let archiveDir = config.archive_dir;
|
34
|
+
const paginationDir = config.pagination_dir || 'page';
|
35
|
+
// @ts-ignore
|
36
|
+
const allPosts = locals.posts.sort(config.archive_generator.order_by || '-date');
|
37
|
+
const perPage = config.archive_generator.per_page;
|
38
|
+
let result = [];
|
39
|
+
if (!allPosts.length)
|
40
|
+
return;
|
41
|
+
if (archiveDir[archiveDir.length - 1] !== '/')
|
42
|
+
archiveDir += '/';
|
43
|
+
function generate(path, posts, options) {
|
44
|
+
options = options || {};
|
45
|
+
options.archive = true;
|
46
|
+
result = result.concat((0, hexo_pagination_1.default)(path, posts, {
|
47
|
+
perPage: path === archiveDir ? 0 : perPage,
|
48
|
+
layout: ['archive', 'index'],
|
49
|
+
format: paginationDir + '/%d/',
|
50
|
+
data: options
|
51
|
+
}));
|
52
|
+
}
|
53
|
+
generate(archiveDir, allPosts);
|
54
|
+
if (!config.archive_generator.yearly)
|
55
|
+
return result;
|
56
|
+
const posts = {};
|
57
|
+
// 按日期对文章进行分类
|
58
|
+
allPosts.forEach(post => {
|
59
|
+
const date = post.date;
|
60
|
+
const year = date.year();
|
61
|
+
const month = date.month() + 1; // month is started from 0
|
62
|
+
if (!Object.prototype.hasOwnProperty.call(posts, year)) {
|
63
|
+
// 13个数组. 第一个数组是给这一年的文章准备的
|
64
|
+
// 其他则是各个月份的文章
|
65
|
+
posts[year] = [
|
66
|
+
[],
|
67
|
+
[],
|
68
|
+
[],
|
69
|
+
[],
|
70
|
+
[],
|
71
|
+
[],
|
72
|
+
[],
|
73
|
+
[],
|
74
|
+
[],
|
75
|
+
[],
|
76
|
+
[],
|
77
|
+
[],
|
78
|
+
[]
|
79
|
+
];
|
80
|
+
}
|
81
|
+
posts[year][0].push(post);
|
82
|
+
posts[year][month].push(post);
|
83
|
+
// Daily
|
84
|
+
if (config.archive_generator.daily) {
|
85
|
+
const day = date.date();
|
86
|
+
if (!Object.prototype.hasOwnProperty.call(posts[year][month], 'day')) {
|
87
|
+
posts[year][month].day = {};
|
88
|
+
}
|
89
|
+
(posts[year][month].day[day] || (posts[year][month].day[day] = [])).push(post);
|
90
|
+
}
|
91
|
+
});
|
92
|
+
const Query = this.model('Post').Query;
|
93
|
+
const years = Object.keys(posts);
|
94
|
+
let year, data, month, monthData, url;
|
95
|
+
// Yearly
|
96
|
+
for (let i = 0, len = years.length; i < len; i++) {
|
97
|
+
year = +years[i];
|
98
|
+
data = posts[year];
|
99
|
+
url = archiveDir + year + '/';
|
100
|
+
if (!data[0].length)
|
101
|
+
continue;
|
102
|
+
generate(url, new Query(data[0]), { year });
|
103
|
+
if (!config.archive_generator.monthly && !config.archive_generator.daily)
|
104
|
+
continue;
|
105
|
+
// Monthly
|
106
|
+
for (month = 1; month <= 12; month++) {
|
107
|
+
monthData = data[month];
|
108
|
+
if (!monthData.length)
|
109
|
+
continue;
|
110
|
+
if (config.archive_generator.monthly) {
|
111
|
+
generate(url + fmtNum(month) + '/', new Query(monthData), {
|
112
|
+
year,
|
113
|
+
month
|
114
|
+
});
|
115
|
+
}
|
116
|
+
if (!config.archive_generator.daily)
|
117
|
+
continue;
|
118
|
+
// Daily
|
119
|
+
for (let day = 1; day <= 31; day++) {
|
120
|
+
const dayData = monthData.day[day];
|
121
|
+
if (!dayData || !dayData.length)
|
122
|
+
continue;
|
123
|
+
generate(url + fmtNum(month) + '/' + fmtNum(day) + '/', new Query(dayData), {
|
124
|
+
year,
|
125
|
+
month,
|
126
|
+
day
|
127
|
+
});
|
128
|
+
}
|
129
|
+
}
|
130
|
+
}
|
131
|
+
return result;
|
132
|
+
});
|
133
|
+
}
|
@@ -0,0 +1,48 @@
|
|
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
|
+
/* global hexo */
|
7
|
+
const hexo_util_1 = require("hexo-util");
|
8
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
9
|
+
const path_1 = __importDefault(require("path"));
|
10
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
11
|
+
hexo.extend.filter.register('before_generate', () => {
|
12
|
+
if (hexo.config.theme_config) {
|
13
|
+
// @ts-ignore
|
14
|
+
hexo.theme.config = (0, hexo_util_1.deepMerge)(hexo.theme.config, hexo.config.theme_config);
|
15
|
+
}
|
16
|
+
const data = hexo.locals.get('data');
|
17
|
+
if (data.languages) {
|
18
|
+
// @ts-ignore
|
19
|
+
const { i18n } = hexo.theme;
|
20
|
+
const mergeLang = lang => {
|
21
|
+
if (data.languages[lang]) { // @ts-ignore
|
22
|
+
i18n.set(lang, (0, hexo_util_1.deepMerge)(i18n.get([lang]), data.languages[lang]));
|
23
|
+
}
|
24
|
+
};
|
25
|
+
for (const lang of ['en', 'ja', 'zh-CN', 'zh-HK', 'zh-TW']) {
|
26
|
+
mergeLang(lang);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
hexo.theme.config.style = {};
|
30
|
+
for (const style of ['iconfont', 'colors', 'custom']) {
|
31
|
+
const custom_file = 'source/_data/' + style + '.styl';
|
32
|
+
if (node_fs_1.default.existsSync(custom_file)) {
|
33
|
+
hexo.theme.config.style[style] = path_1.default.resolve(hexo.base_dir, custom_file);
|
34
|
+
}
|
35
|
+
}
|
36
|
+
if (data.images && data.images.length > 0) {
|
37
|
+
hexo.theme.config.image_list = data.images;
|
38
|
+
}
|
39
|
+
else {
|
40
|
+
hexo.theme.config.image_list = js_yaml_1.default.load(node_fs_1.default.readFileSync(path_1.default.join(__dirname, '../../_images.yml'), { encoding: 'utf-8' }));
|
41
|
+
}
|
42
|
+
if (node_fs_1.default.existsSync(path_1.default.join(__dirname, '../../_images_index.yml'))) {
|
43
|
+
hexo.theme.config.index_images = js_yaml_1.default.load(node_fs_1.default.readFileSync(path_1.default.join(__dirname, '../../_images_index.yml'), { encoding: 'utf-8' }));
|
44
|
+
}
|
45
|
+
else {
|
46
|
+
hexo.theme.config.index_images = data.index_images || [];
|
47
|
+
}
|
48
|
+
});
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/* global hexo */
|
2
|
+
'use strict';
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
// @ts-ignore
|
5
|
+
const fs = require("hexo-fs");
|
6
|
+
hexo.extend.generator.register('images', function (locals) {
|
7
|
+
const theme = hexo.theme.config;
|
8
|
+
const dir = 'source/_data/' + theme.assets + '/';
|
9
|
+
if (!fs.existsSync(dir)) {
|
10
|
+
return;
|
11
|
+
}
|
12
|
+
const result = [];
|
13
|
+
const files = fs.listDirSync(dir);
|
14
|
+
files.forEach((file) => {
|
15
|
+
result.push({
|
16
|
+
path: theme.assets + '/' + file,
|
17
|
+
data: function () {
|
18
|
+
return fs.createReadStream(dir + file);
|
19
|
+
}
|
20
|
+
});
|
21
|
+
});
|
22
|
+
return result;
|
23
|
+
});
|
@@ -0,0 +1,107 @@
|
|
1
|
+
// @ts-nocheck
|
2
|
+
/* global hexo */
|
3
|
+
'use strict';
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
6
|
+
};
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
8
|
+
const fs = require("hexo-fs");
|
9
|
+
const hexo_pagination_1 = __importDefault(require("hexo-pagination"));
|
10
|
+
hexo.config.index_generator = Object.assign({
|
11
|
+
per_page: typeof hexo.config.per_page === 'undefined' ? 10 : hexo.config.per_page,
|
12
|
+
order_by: '-date'
|
13
|
+
}, hexo.config.index_generator);
|
14
|
+
hexo.extend.generator.register('index', function (locals) {
|
15
|
+
const covers = [];
|
16
|
+
const catlist = [];
|
17
|
+
let pages;
|
18
|
+
const config = hexo.config;
|
19
|
+
const sticky = locals.posts.find({ sticky: true }).sort(config.index_generator.order_by);
|
20
|
+
const posts = locals.posts.find({ sticky: { $in: [false, undefined] } }).sort(config.index_generator.order_by);
|
21
|
+
const paginationDir = config.pagination_dir || 'page';
|
22
|
+
const path = config.index_generator.path || '';
|
23
|
+
const categories = locals.categories;
|
24
|
+
const getTopcat = function (cat) {
|
25
|
+
if (cat.parent) {
|
26
|
+
const pCat = categories.findOne({ _id: cat.parent });
|
27
|
+
return getTopcat(pCat);
|
28
|
+
}
|
29
|
+
else {
|
30
|
+
return cat;
|
31
|
+
}
|
32
|
+
};
|
33
|
+
if (categories && categories.length) {
|
34
|
+
categories.forEach((cat) => {
|
35
|
+
const cover = `source/_posts/${cat.slug}`;
|
36
|
+
if (fs.existsSync(cover + '/cover.avif')) {
|
37
|
+
covers.push({
|
38
|
+
path: cat.slug + '/cover.avif',
|
39
|
+
data: function () {
|
40
|
+
return fs.createReadStream(cover + '/cover.avif');
|
41
|
+
}
|
42
|
+
});
|
43
|
+
}
|
44
|
+
else if (fs.existsSync(cover + '/cover.webp')) {
|
45
|
+
covers.push({
|
46
|
+
path: cat.slug + '/cover.webp',
|
47
|
+
data: function () {
|
48
|
+
return fs.createReadStream(cover + '/cover.webp');
|
49
|
+
}
|
50
|
+
});
|
51
|
+
}
|
52
|
+
else if (fs.existsSync(cover + '/cover.jpg')) {
|
53
|
+
covers.push({
|
54
|
+
path: cat.slug + '/cover.jpg',
|
55
|
+
data: function () {
|
56
|
+
return fs.createReadStream(cover + '/cover.jpg');
|
57
|
+
}
|
58
|
+
});
|
59
|
+
const topcat = getTopcat(cat);
|
60
|
+
if (topcat._id !== cat._id) {
|
61
|
+
cat.top = topcat;
|
62
|
+
}
|
63
|
+
const child = categories.find({ parent: cat._id });
|
64
|
+
let pl = 6;
|
65
|
+
if (child.length !== 0) {
|
66
|
+
cat.child = child.length;
|
67
|
+
cat.subs = child.sort({ name: 1 }).limit(6).toArray();
|
68
|
+
pl = Math.max(0, pl - child.length);
|
69
|
+
if (pl > 0) {
|
70
|
+
cat.subs.push(...cat.posts.sort({ title: 1 })
|
71
|
+
.filter(function (item, i) { return item.categories.last()._id === cat._id; })
|
72
|
+
.limit(pl).toArray());
|
73
|
+
}
|
74
|
+
}
|
75
|
+
else {
|
76
|
+
cat.subs = cat.posts.sort({ title: 1 }).limit(6).toArray();
|
77
|
+
}
|
78
|
+
catlist.push(cat);
|
79
|
+
}
|
80
|
+
});
|
81
|
+
}
|
82
|
+
if (posts.length > 0) {
|
83
|
+
pages = (0, hexo_pagination_1.default)(path, posts, {
|
84
|
+
perPage: config.index_generator.per_page,
|
85
|
+
layout: ['index', 'archive'],
|
86
|
+
format: paginationDir + '/%d/',
|
87
|
+
data: {
|
88
|
+
__index: true,
|
89
|
+
catlist,
|
90
|
+
sticky
|
91
|
+
}
|
92
|
+
});
|
93
|
+
}
|
94
|
+
else {
|
95
|
+
pages = [{
|
96
|
+
path,
|
97
|
+
layout: ['index', 'archive'],
|
98
|
+
data: {
|
99
|
+
__index: true,
|
100
|
+
catlist,
|
101
|
+
sticky,
|
102
|
+
current: 1,
|
103
|
+
}
|
104
|
+
}];
|
105
|
+
}
|
106
|
+
return [...covers, ...pages];
|
107
|
+
});
|
@@ -0,0 +1,15 @@
|
|
1
|
+
hexo.extend.generator.register('pages', function () {
|
2
|
+
const config = hexo.config;
|
3
|
+
return [
|
4
|
+
{
|
5
|
+
path: config.category_dir + '/index.html',
|
6
|
+
data: { type: 'categories' },
|
7
|
+
layout: 'page'
|
8
|
+
},
|
9
|
+
{
|
10
|
+
path: config.tag_dir + '/index.html',
|
11
|
+
data: { type: 'tags' },
|
12
|
+
layout: 'page'
|
13
|
+
}
|
14
|
+
];
|
15
|
+
});
|
@@ -0,0 +1,118 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
|
+
};
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
+
/* global hexo */
|
30
|
+
const package_json_1 = __importDefault(require("../../package.json"));
|
31
|
+
const fs = __importStar(require("hexo-fs"));
|
32
|
+
const esbuild_1 = require("esbuild");
|
33
|
+
const utils_1 = require("../utils");
|
34
|
+
hexo.extend.generator.register('script', function (locals) {
|
35
|
+
const config = hexo.config;
|
36
|
+
const theme = hexo.theme.config;
|
37
|
+
const siteConfig = {
|
38
|
+
version: package_json_1.default.version,
|
39
|
+
hostname: config.url,
|
40
|
+
root: config.root,
|
41
|
+
statics: theme.statics,
|
42
|
+
favicon: {
|
43
|
+
normal: theme.assets + '/favicon.ico',
|
44
|
+
hidden: theme.assets + '/failure.ico'
|
45
|
+
},
|
46
|
+
darkmode: theme.darkmode,
|
47
|
+
auto_dark: theme.auto_dark,
|
48
|
+
auto_scroll: theme.auto_scroll,
|
49
|
+
js: {
|
50
|
+
copy_tex: (0, utils_1.getVendorLink)(hexo, theme.vendors.async_js.copy_tex),
|
51
|
+
fancybox: (0, utils_1.getVendorLink)(hexo, theme.vendors.async_js.fancybox)
|
52
|
+
},
|
53
|
+
css: {
|
54
|
+
katex: (0, utils_1.getVendorLink)(hexo, theme.vendors.css.katex),
|
55
|
+
mermaid: theme.css + '/mermaid.css',
|
56
|
+
fancybox: (0, utils_1.getVendorLink)(hexo, theme.vendors.css.fancybox),
|
57
|
+
justifiedGallery: (0, utils_1.getVendorLink)(hexo, theme.vendors.css.justifiedGallery)
|
58
|
+
},
|
59
|
+
loader: theme.loader,
|
60
|
+
search: null,
|
61
|
+
outime: {
|
62
|
+
enable: theme.outime.enable,
|
63
|
+
days: theme.outime.days
|
64
|
+
},
|
65
|
+
quicklink: {
|
66
|
+
timeout: theme.quicklink.timeout,
|
67
|
+
priority: theme.quicklink.priority
|
68
|
+
},
|
69
|
+
playerAPI: theme.playerAPI,
|
70
|
+
disableVL: theme.disableVL,
|
71
|
+
noPlayer: theme.experiments?.noPlayer,
|
72
|
+
audio: undefined,
|
73
|
+
fireworks: (theme.fireworks && theme.fireworks.enable && theme.fireworks.options)
|
74
|
+
? theme.fireworks.options
|
75
|
+
: undefined
|
76
|
+
};
|
77
|
+
if (config?.algolia) {
|
78
|
+
siteConfig.search = {
|
79
|
+
appID: config.algolia.appId,
|
80
|
+
apiKey: config.algolia.apiKey,
|
81
|
+
indexName: config.algolia.indexName,
|
82
|
+
hits: theme.search.hits
|
83
|
+
};
|
84
|
+
}
|
85
|
+
if (theme?.audio) {
|
86
|
+
siteConfig.audio = theme.audio;
|
87
|
+
}
|
88
|
+
let text;
|
89
|
+
let enterPoint;
|
90
|
+
if (fs.existsSync('themes/shokaX/source/js/_app/pjax/siteInit.js')) {
|
91
|
+
enterPoint = 'themes/shokaX/source/js/_app/pjax/siteInit.js';
|
92
|
+
}
|
93
|
+
else {
|
94
|
+
enterPoint = 'node_modules/hexo-theme-shokax/source/js/_app/pjax/siteInit.js';
|
95
|
+
}
|
96
|
+
text = 'const CONFIG = ' + JSON.stringify(siteConfig) + ';';
|
97
|
+
(0, esbuild_1.buildSync)({
|
98
|
+
entryPoints: [enterPoint],
|
99
|
+
bundle: true,
|
100
|
+
outfile: 'shokax_temp.js',
|
101
|
+
platform: 'browser',
|
102
|
+
format: 'iife',
|
103
|
+
target: ['es2022'],
|
104
|
+
minify: true,
|
105
|
+
define: {
|
106
|
+
__UNLAZY_LOGGING__: 'false'
|
107
|
+
}
|
108
|
+
});
|
109
|
+
text += fs.readFileSync('shokax_temp.js');
|
110
|
+
const result = hexo.render.renderSync({ text, engine: 'js' });
|
111
|
+
fs.unlinkSync('shokax_temp.js');
|
112
|
+
return {
|
113
|
+
path: theme.js + '/app.js',
|
114
|
+
data: function () {
|
115
|
+
return result;
|
116
|
+
}
|
117
|
+
};
|
118
|
+
});
|
@@ -0,0 +1,147 @@
|
|
1
|
+
"use strict";
|
2
|
+
/* global hexo */
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
5
|
+
};
|
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('_new_comments', function (mode) {
|
11
|
+
const root = this.config.url.replace(/^(https?:\/\/)?[^\/]*/, '');
|
12
|
+
if (mode === 'twikoo') {
|
13
|
+
return `<script data-pjax type="module">
|
14
|
+
let comments = []
|
15
|
+
twikoo.getRecentComments({
|
16
|
+
envId: "${hexo.theme.config?.twikoo?.envId}",
|
17
|
+
pageSize: 10
|
18
|
+
}).then(function (res) {
|
19
|
+
res.forEach(function (item) {
|
20
|
+
let cText = item.commentText
|
21
|
+
if (item.commentText.length > 50) {
|
22
|
+
cText = item.commentText.substring(0,50)+'...'
|
23
|
+
}
|
24
|
+
const siteLink = item.url + "#" + item.id
|
25
|
+
comments.push({
|
26
|
+
href: siteLink,
|
27
|
+
nick: item.nick,
|
28
|
+
time: item.relativeTime,
|
29
|
+
text: cText
|
30
|
+
})
|
31
|
+
});
|
32
|
+
Vue.createApp({
|
33
|
+
data() {
|
34
|
+
return {
|
35
|
+
coms: comments,
|
36
|
+
root: '${root}'
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}).mount('#new-comment')
|
40
|
+
}).catch(function (err) {
|
41
|
+
console.error(err)
|
42
|
+
})
|
43
|
+
</script>`;
|
44
|
+
}
|
45
|
+
else if (mode === 'waline') {
|
46
|
+
return `
|
47
|
+
<script type="module" data-pjax>
|
48
|
+
let items = []
|
49
|
+
import { RecentComments } from 'https://npm.webcache.cn/@waline/client@v2/dist/waline.mjs'
|
50
|
+
RecentComments({
|
51
|
+
serverURL: '${hexo.theme.config.waline.serverURL.replace(/\/+$/, '')}',
|
52
|
+
count: 10,
|
53
|
+
}).then(({ comments }) => {
|
54
|
+
comments.forEach(function (item) {
|
55
|
+
let cText = (item.orig.length > 50) ? item.orig.substring(0,50)+'...' : item.orig
|
56
|
+
item.url = item.url.startsWith('/') ? item.url : '/' + item.url;
|
57
|
+
const siteLink = item.url + "#" + item.objectId
|
58
|
+
items.push({
|
59
|
+
href: siteLink,
|
60
|
+
nick: item.nick,
|
61
|
+
time: item.insertedAt.split('T').shift(),
|
62
|
+
text: cText
|
63
|
+
})
|
64
|
+
})
|
65
|
+
Vue.createApp({
|
66
|
+
data() {
|
67
|
+
return {
|
68
|
+
coms: items,
|
69
|
+
root: '${root}'
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}).mount('#new-comment')
|
73
|
+
}).catch(function (err) {
|
74
|
+
console.error(err)
|
75
|
+
})
|
76
|
+
</script>
|
77
|
+
`;
|
78
|
+
}
|
79
|
+
else {
|
80
|
+
console.log(`${mode} is not supported recent comment`);
|
81
|
+
}
|
82
|
+
});
|
83
|
+
hexo.extend.helper.register('_safedump', (source) => {
|
84
|
+
return JSON.stringify(source);
|
85
|
+
});
|
86
|
+
hexo.extend.helper.register('hexo_env', function (type) {
|
87
|
+
return this.env[type];
|
88
|
+
});
|
89
|
+
hexo.extend.helper.register('theme_env', function (type) {
|
90
|
+
return package_json_1.default[type];
|
91
|
+
});
|
92
|
+
hexo.extend.helper.register('_vendor_font', () => {
|
93
|
+
const config = hexo.theme.config.font;
|
94
|
+
if (!config || !config.enable)
|
95
|
+
return '';
|
96
|
+
const fontDisplay = '&display=swap';
|
97
|
+
const fontSubset = '&subset=latin,latin-ext';
|
98
|
+
const fontStyles = ':300,300italic,400,400italic,700,700italic';
|
99
|
+
const fontHost = 'https://fonts.googleapis.com';
|
100
|
+
// Get a font list from config
|
101
|
+
let fontFamilies = ['global', 'logo', 'title', 'headings', 'posts', 'codes'].map(item => {
|
102
|
+
if (config[item] && config[item].family && config[item].external) {
|
103
|
+
return config[item].family + fontStyles;
|
104
|
+
}
|
105
|
+
return '';
|
106
|
+
});
|
107
|
+
fontFamilies = fontFamilies.filter(item => item !== '');
|
108
|
+
// @ts-ignore
|
109
|
+
fontFamilies = [...new Set(fontFamilies)];
|
110
|
+
// @ts-ignore
|
111
|
+
fontFamilies = fontFamilies.join('|');
|
112
|
+
// Merge extra parameters to the final processed font string
|
113
|
+
return fontFamilies
|
114
|
+
? (0, hexo_util_1.htmlTag)('link', {
|
115
|
+
rel: 'stylesheet',
|
116
|
+
href: `${fontHost}/css?family=${fontFamilies.concat(fontDisplay, fontSubset)}`
|
117
|
+
})
|
118
|
+
: '';
|
119
|
+
});
|
120
|
+
hexo.extend.helper.register('_css', function (...urls) {
|
121
|
+
const { statics, css } = hexo.theme.config;
|
122
|
+
return urls.map(url => (0, hexo_util_1.htmlTag)('link', {
|
123
|
+
rel: 'stylesheet',
|
124
|
+
href: hexo_util_1.url_for.call(this, `${statics}${css}/${url}?v=${package_json_1.default.version}`)
|
125
|
+
})).join('');
|
126
|
+
});
|
127
|
+
hexo.extend.helper.register('_js', function (...urls) {
|
128
|
+
const { statics, js } = hexo.theme.config;
|
129
|
+
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}`) }, '')).join('');
|
130
|
+
});
|
131
|
+
hexo.extend.helper.register('vendor_js', function () {
|
132
|
+
const vendors = hexo.theme.config.vendors;
|
133
|
+
let res = '';
|
134
|
+
for (const jsSync in vendors.js) {
|
135
|
+
res += (0, hexo_util_1.htmlTag)('script', { src: (0, utils_1.getVendorLink)(hexo, vendors.js[jsSync]) }, '');
|
136
|
+
}
|
137
|
+
// for (const jsAsync in vendors.async_js) {
|
138
|
+
// res += htmlTag('script', { src: getVendorLink(hexo, vendors.async_js[jsAsync]), async: true }, '')
|
139
|
+
// }
|
140
|
+
return res;
|
141
|
+
});
|
142
|
+
hexo.extend.helper.register('_striptags', function (data) {
|
143
|
+
return (0, hexo_util_1.stripHTML)(data);
|
144
|
+
});
|
145
|
+
hexo.extend.helper.register('_truncate', function (data, end) {
|
146
|
+
return data.substring(0, end);
|
147
|
+
});
|