hexo-theme-shokax 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +30 -0
- package/README.md +6 -5
- package/_config.yml +2 -1
- package/_images.yml +1 -92
- package/layout/_partials/footer.pug +1 -1
- package/package.json +5 -2
- package/scripts/filters/locals.js +44 -57
- package/scripts/filters/post.js +13 -19
- package/scripts/generaters/archive.js +115 -135
- package/scripts/generaters/config.js +35 -38
- package/scripts/generaters/images.js +23 -24
- package/scripts/generaters/index.js +100 -105
- package/scripts/generaters/pages.js +15 -18
- package/scripts/generaters/script.js +91 -90
- package/scripts/helpers/asset.js +128 -134
- package/scripts/helpers/engine.js +128 -185
- package/scripts/helpers/list_categories.js +103 -132
- package/scripts/helpers/symbols_count_time.js +54 -67
- package/scripts/plugin/index.js +47 -46
- package/scripts/plugin/lib/injects-point.js +20 -20
- package/scripts/plugin/lib/injects.js +63 -82
- package/scripts/tags/links.js +52 -75
- package/scripts/tags/media.js +17 -18
- package/source/css/_common/components/highlight/highlight.styl +4 -0
- package/source/css/_common/outline/header/image.styl +4 -0
- package/source/css/_common/outline/header/waves.styl +4 -0
- package/source/css/_common/scaffolding/animate.styl +4 -0
- package/source/css/_mixins.styl +5 -3
- package/source/css/app.styl +9 -6
- package/source/js/_app/fireworks.js +11 -1
- package/source/js/_app/global.js +6 -2
- package/source/js/_app/page.js +66 -0
package/scripts/helpers/asset.js
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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 package_json_1 = __importDefault(require("../../package.json"));
|
7
|
+
const hexo_util_1 = require("hexo-util");
|
7
8
|
hexo.extend.helper.register('_new_comments', function (mode) {
|
8
|
-
|
9
|
-
|
9
|
+
if (mode === 'twikoo') {
|
10
|
+
return `<script data-pjax type="module">
|
10
11
|
let comments = []
|
11
12
|
twikoo.getRecentComments({
|
12
13
|
envId: "${hexo.theme.config?.twikoo?.envId}",
|
@@ -35,9 +36,10 @@ hexo.extend.helper.register('_new_comments', function (mode) {
|
|
35
36
|
}).catch(function (err) {
|
36
37
|
console.error(err)
|
37
38
|
})
|
38
|
-
</script
|
39
|
-
|
40
|
-
|
39
|
+
</script>`;
|
40
|
+
}
|
41
|
+
else if (mode === 'waline') {
|
42
|
+
return `
|
41
43
|
<script type="module" data-pjax>
|
42
44
|
import { RecentComments } from 'https://unpkg.com/@waline/client@v2/dist/waline.mjs'
|
43
45
|
RecentComments({
|
@@ -46,138 +48,130 @@ hexo.extend.helper.register('_new_comments', function (mode) {
|
|
46
48
|
count: 10,
|
47
49
|
});
|
48
50
|
</script>
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
}
|
54
|
-
|
51
|
+
`;
|
52
|
+
}
|
53
|
+
else {
|
54
|
+
console.log(`${mode} is not supported recent comment`);
|
55
|
+
}
|
56
|
+
});
|
55
57
|
hexo.extend.helper.register('_safedump', (source) => {
|
56
|
-
|
57
|
-
})
|
58
|
-
|
58
|
+
return JSON.stringify(source);
|
59
|
+
});
|
59
60
|
hexo.extend.helper.register('hexo_env', function (type) {
|
60
|
-
|
61
|
-
})
|
62
|
-
|
61
|
+
return this.env[type];
|
62
|
+
});
|
63
63
|
hexo.extend.helper.register('theme_env', function (type) {
|
64
|
-
|
65
|
-
})
|
66
|
-
|
64
|
+
return package_json_1.default[type];
|
65
|
+
});
|
67
66
|
hexo.extend.helper.register('_vendor_font', () => {
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
? htmlTag('link', {
|
92
|
-
rel: 'stylesheet',
|
93
|
-
href: `${fontHost}/css?family=${fontFamilies.concat(fontDisplay, fontSubset)}`
|
94
|
-
})
|
95
|
-
: ''
|
96
|
-
})
|
97
|
-
|
98
|
-
// TODO 废弃方法
|
67
|
+
const config = hexo.theme.config.font;
|
68
|
+
if (!config || !config.enable)
|
69
|
+
return '';
|
70
|
+
const fontDisplay = '&display=swap';
|
71
|
+
const fontSubset = '&subset=latin,latin-ext';
|
72
|
+
const fontStyles = ':300,300italic,400,400italic,700,700italic';
|
73
|
+
const fontHost = '//fonts.geekzu.org';
|
74
|
+
let fontFamilies = ['global', 'logo', 'title', 'headings', 'posts', 'codes'].map(item => {
|
75
|
+
if (config[item] && config[item].family && config[item].external) {
|
76
|
+
return config[item].family + fontStyles;
|
77
|
+
}
|
78
|
+
return '';
|
79
|
+
});
|
80
|
+
fontFamilies = fontFamilies.filter(item => item !== '');
|
81
|
+
fontFamilies = [...new Set(fontFamilies)];
|
82
|
+
fontFamilies = fontFamilies.join('|');
|
83
|
+
return fontFamilies
|
84
|
+
? (0, hexo_util_1.htmlTag)('link', {
|
85
|
+
rel: 'stylesheet',
|
86
|
+
href: `${fontHost}/css?family=${fontFamilies.concat(fontDisplay, fontSubset)}`
|
87
|
+
})
|
88
|
+
: '';
|
89
|
+
});
|
99
90
|
hexo.extend.helper.register('_vendor_js', () => {
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
}
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
vendorJs = vendorJs.join(',')
|
115
|
-
return vendorJs ? htmlTag('script', { src: `https://cdn.jsdelivr.net/combine/${vendorJs}` }, '') : ''
|
116
|
-
})
|
117
|
-
|
91
|
+
const config = hexo.theme.config.vendors.js;
|
92
|
+
if (!config)
|
93
|
+
return '';
|
94
|
+
let vendorJs = ['pace', 'pjax', 'fetch', 'anime', 'algolia', 'instantsearch', 'lazyload', 'quicklink'].map(item => {
|
95
|
+
if (config[item]) {
|
96
|
+
return config[item];
|
97
|
+
}
|
98
|
+
return '';
|
99
|
+
});
|
100
|
+
vendorJs = vendorJs.filter(item => item !== '');
|
101
|
+
vendorJs = [...new Set(vendorJs)];
|
102
|
+
vendorJs = vendorJs.join(',');
|
103
|
+
return vendorJs ? (0, hexo_util_1.htmlTag)('script', { src: `https://cdn.jsdelivr.net/combine/${vendorJs}` }, '') : '';
|
104
|
+
});
|
118
105
|
hexo.extend.helper.register('_css', function (...urls) {
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
})
|
126
|
-
|
106
|
+
const { statics, css } = hexo.theme.config;
|
107
|
+
return urls.map(url => (0, hexo_util_1.htmlTag)('link', {
|
108
|
+
rel: 'stylesheet',
|
109
|
+
href: hexo_util_1.url_for.call(this, `${statics}${css}/${url}?v=${package_json_1.default.version}`)
|
110
|
+
})).join('');
|
111
|
+
});
|
127
112
|
hexo.extend.helper.register('_js', function (...urls) {
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
})
|
113
|
+
const { statics, js } = hexo.theme.config;
|
114
|
+
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('');
|
115
|
+
});
|
132
116
|
hexo.extend.helper.register('_list_vendor_js', () => {
|
133
|
-
|
134
|
-
})
|
135
|
-
|
117
|
+
return hexo.theme.config.vendorsList.js;
|
118
|
+
});
|
136
119
|
hexo.extend.helper.register('_adv_vendor_js', function (js_name) {
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
120
|
+
const srcHelpers = (src) => { return src.endsWith('/') ? src : src + '/'; };
|
121
|
+
const config = hexo.theme.config.advVendors.js[js_name];
|
122
|
+
const themeConfig = hexo.theme.config;
|
123
|
+
const src = config.src;
|
124
|
+
const publicCdns = {
|
125
|
+
npm: srcHelpers(themeConfig.advVendors.npm),
|
126
|
+
gh: srcHelpers(themeConfig.advVendors.github),
|
127
|
+
combine: srcHelpers(themeConfig.advVendors.combine),
|
128
|
+
bytedance: 'https://lf9-cdn-tos.bytecdntp.com/cdn/expire-6-M/',
|
129
|
+
baomitu: 'https://lib.baomitu.com/'
|
130
|
+
};
|
131
|
+
let result;
|
132
|
+
if (src.startsWith('http')) {
|
133
|
+
result = src;
|
134
|
+
}
|
135
|
+
else if (src.startsWith('combine:')) {
|
136
|
+
hexo.log.info('The combine feature is not recommended!');
|
137
|
+
result = publicCdns.combine + src;
|
138
|
+
}
|
139
|
+
else if (src.startsWith('npm:')) {
|
140
|
+
result = publicCdns.npm + src.substring(4);
|
141
|
+
}
|
142
|
+
else if (src.startsWith('gh:')) {
|
143
|
+
result = publicCdns.gh + src.substring(3);
|
144
|
+
}
|
145
|
+
else if (src.startsWith('bytedance:')) {
|
146
|
+
result = publicCdns.bytedance + src.substring(10);
|
147
|
+
}
|
148
|
+
else if (src.startsWith('baomitu:')) {
|
149
|
+
result = publicCdns.baomitu + src.substring(8);
|
150
|
+
}
|
151
|
+
else {
|
152
|
+
result = '/' + src;
|
153
|
+
}
|
154
|
+
const attr = {
|
155
|
+
src: result,
|
156
|
+
integrity: undefined,
|
157
|
+
async: undefined
|
158
|
+
};
|
159
|
+
if (config.async)
|
160
|
+
attr.async = 'async';
|
161
|
+
if (config['data-pjax'])
|
162
|
+
attr['data-pjax'] = 'data-pjax';
|
163
|
+
if (config['hash-value'])
|
164
|
+
attr.integrity = config['hash-value'];
|
165
|
+
if (config.deferLoad) {
|
166
|
+
return (0, hexo_util_1.htmlTag)('script', { 'data-pjax': true }, `
|
171
167
|
const script=document.createElement("script");script.src="${result}",script.async=true,document.body.appendChild(script)
|
172
|
-
`)
|
173
|
-
|
174
|
-
|
175
|
-
})
|
176
|
-
|
168
|
+
`);
|
169
|
+
}
|
170
|
+
return (0, hexo_util_1.htmlTag)('script', attr, '');
|
171
|
+
});
|
177
172
|
hexo.extend.helper.register('_striptags', function (data) {
|
178
|
-
|
179
|
-
})
|
180
|
-
|
173
|
+
return (0, hexo_util_1.stripHTML)(data);
|
174
|
+
});
|
181
175
|
hexo.extend.helper.register('_truncate', function (data, end) {
|
182
|
-
|
183
|
-
})
|
176
|
+
return data.substring(0, end);
|
177
|
+
});
|
@@ -1,201 +1,144 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
const { htmlTag, url_for } = require('hexo-util')
|
6
|
-
|
7
|
-
const randomServer = parseInt(String(Math.random() * 4), 10) + 1
|
8
|
-
|
1
|
+
'use strict';
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const hexo_util_1 = require("hexo-util");
|
4
|
+
const randomServer = parseInt(String(Math.random() * 4), 10) + 1;
|
9
5
|
const randomBG = function (count = 1, image_server = null, image_list = []) {
|
10
|
-
|
11
|
-
|
6
|
+
let i;
|
7
|
+
if (image_server) {
|
8
|
+
if (count && count > 1) {
|
9
|
+
const arr = new Array(count);
|
10
|
+
for (i = 0; i < arr.length; i++) {
|
11
|
+
arr[i] = image_server + '?' + Math.floor(Math.random() * 999999);
|
12
|
+
}
|
13
|
+
return arr;
|
14
|
+
}
|
15
|
+
return image_server + '?' + Math.floor(Math.random() * 999999);
|
16
|
+
}
|
17
|
+
const parseImage = function (img, size) {
|
18
|
+
if (img.startsWith('//') || img.startsWith('http')) {
|
19
|
+
return img;
|
20
|
+
}
|
21
|
+
else if (hexo.theme.config.experiments?.usingRelative) {
|
22
|
+
return img;
|
23
|
+
}
|
24
|
+
else {
|
25
|
+
console.warn("sinaimg blocked all request from outside website,so don't use this format");
|
26
|
+
return `https://tva${randomServer}.sinaimg.cn/` + size + '/' + img;
|
27
|
+
}
|
28
|
+
};
|
12
29
|
if (count && count > 1) {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
30
|
+
const shuffled = image_list.slice(0);
|
31
|
+
i = image_list.length;
|
32
|
+
const min = i - count;
|
33
|
+
let temp;
|
34
|
+
let index;
|
35
|
+
while (i-- > min) {
|
36
|
+
index = Math.floor((i + 1) * Math.random());
|
37
|
+
temp = shuffled[index];
|
38
|
+
shuffled[index] = shuffled[i];
|
39
|
+
shuffled[i] = temp;
|
40
|
+
}
|
41
|
+
return shuffled.slice(min).map(function (img) {
|
42
|
+
return parseImage(img, 'large');
|
43
|
+
});
|
19
44
|
}
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
if (img.startsWith('//') || img.startsWith('http')) {
|
26
|
-
return img
|
27
|
-
} else if (hexo.theme.config.experiments?.usingRelative) { // support relative url
|
28
|
-
return img
|
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
|
45
|
+
return parseImage(image_list[Math.floor(Math.random() * image_list.length)], 'mw690');
|
46
|
+
};
|
47
|
+
hexo.extend.helper.register('_url', function (path, text, options = {}) {
|
48
|
+
if (!path) {
|
49
|
+
return;
|
32
50
|
}
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
const
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
51
|
+
const { config } = this;
|
52
|
+
const data = new URL(path, hexo.config.url);
|
53
|
+
const siteHost = new URL(config.url).hostname || config.url;
|
54
|
+
const theme = hexo.theme.config;
|
55
|
+
let exturl = '';
|
56
|
+
let tag = 'a';
|
57
|
+
let attrs = { href: hexo_util_1.url_for.call(this, path), class: undefined, external: undefined, rel: undefined, 'data-url': undefined };
|
58
|
+
if (theme.exturl && data.protocol && data.hostname !== siteHost) {
|
59
|
+
tag = 'span';
|
60
|
+
exturl = 'exturl';
|
61
|
+
const encoded = Buffer.from(path).toString('base64');
|
62
|
+
attrs = {
|
63
|
+
class: exturl,
|
64
|
+
'data-url': encoded
|
65
|
+
};
|
44
66
|
}
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
}
|
53
|
-
|
54
|
-
// 注册hexo主题中的URL帮助方法
|
55
|
-
hexo.extend.helper.register('_url', function (path, text, options = {}) {
|
56
|
-
// 如果未提供URL路径,则返回
|
57
|
-
if (!path) { return }
|
58
|
-
|
59
|
-
// 获取hexo配置和URL路径信息
|
60
|
-
const { config } = this
|
61
|
-
const data = new URL(path, hexo.config.url)
|
62
|
-
const siteHost = new URL(config.url).hostname || config.url
|
63
|
-
|
64
|
-
// 获取主题配置
|
65
|
-
const theme = hexo.theme.config
|
66
|
-
let exturl = ''
|
67
|
-
let tag = 'a'
|
68
|
-
let attrs = { href: url_for.call(this, path) }
|
69
|
-
|
70
|
-
// 如果启用了 `exturl`,则只为外部链接设置spanned链接。
|
71
|
-
if (theme.exturl && data.protocol && data.hostname !== siteHost) {
|
72
|
-
tag = 'span'
|
73
|
-
exturl = 'exturl'
|
74
|
-
// 编码URL字符串,并将其存储在数据属性中。
|
75
|
-
const encoded = Buffer.from(path).toString('base64')
|
76
|
-
attrs = {
|
77
|
-
class: exturl,
|
78
|
-
'data-url': encoded
|
67
|
+
for (const key in options) {
|
68
|
+
if (exturl !== '' && key === 'class') {
|
69
|
+
attrs[key] += ' ' + options[key];
|
70
|
+
}
|
71
|
+
else {
|
72
|
+
attrs[key] = options[key];
|
73
|
+
}
|
79
74
|
}
|
80
|
-
|
81
|
-
|
82
|
-
for (const key in options) {
|
83
|
-
/**
|
84
|
-
* 如果选项包含 `class` 属性,则将其添加到 `exturl` 类中(如果启用了 `exturl` 选项)。
|
85
|
-
* 否则,将其添加到属性集中。
|
86
|
-
*/
|
87
|
-
if (exturl !== '' && key === 'class') {
|
88
|
-
attrs[key] += ' ' + options[key]
|
89
|
-
} else {
|
90
|
-
attrs[key] = options[key]
|
75
|
+
if (attrs.class && Array.isArray(attrs.class)) {
|
76
|
+
attrs.class = attrs.class.join(' ');
|
91
77
|
}
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
if (!theme.exturl) {
|
103
|
-
// 仅需要为简单链接重写/添加属性。
|
104
|
-
attrs.rel = 'noopener'
|
105
|
-
attrs.target = '_blank'
|
106
|
-
} else {
|
107
|
-
// 在主菜单中移除 `exturl` 的 rel 属性。
|
108
|
-
attrs.rel = null
|
78
|
+
if (data.protocol && data.hostname !== siteHost) {
|
79
|
+
attrs.external = null;
|
80
|
+
if (!theme.exturl) {
|
81
|
+
attrs.rel = 'noopener';
|
82
|
+
attrs.target = '_blank';
|
83
|
+
}
|
84
|
+
else {
|
85
|
+
attrs.rel = null;
|
86
|
+
}
|
109
87
|
}
|
110
|
-
|
111
|
-
|
112
|
-
// 返回HTML标记字符串
|
113
|
-
return htmlTag(tag, attrs, decodeURI(text), false)
|
114
|
-
})
|
115
|
-
|
88
|
+
return (0, hexo_util_1.htmlTag)(tag, attrs, decodeURI(text), false);
|
89
|
+
});
|
116
90
|
hexo.extend.helper.register('_image_url', function (img, path = '') {
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
})
|
126
|
-
|
91
|
+
const { statics } = hexo.theme.config;
|
92
|
+
const { post_asset_folder } = hexo.config;
|
93
|
+
if (img.startsWith('//') || img.startsWith('http')) {
|
94
|
+
return img;
|
95
|
+
}
|
96
|
+
else {
|
97
|
+
return hexo_util_1.url_for.call(this, statics + (post_asset_folder ? path : '') + img);
|
98
|
+
}
|
99
|
+
});
|
127
100
|
hexo.extend.helper.register('_cover', function (item, num) {
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
}
|
138
|
-
|
139
|
-
// 注册hexo主题的永久链接帮助方法
|
101
|
+
const { image_server, image_list } = hexo.theme.config;
|
102
|
+
if (item.cover) {
|
103
|
+
return this._image_url(item.cover, item.path);
|
104
|
+
}
|
105
|
+
else if (item.photos && item.photos.length > 0) {
|
106
|
+
return this._image_url(item.photos[0], item.path);
|
107
|
+
}
|
108
|
+
else {
|
109
|
+
return randomBG(num || 1, image_server, image_list);
|
110
|
+
}
|
111
|
+
});
|
140
112
|
hexo.extend.helper.register('_permapath', function (str) {
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
}
|
149
|
-
// 返回处理后的URL字符串
|
150
|
-
return url
|
151
|
-
})
|
152
|
-
|
113
|
+
const { permalink } = hexo.config;
|
114
|
+
let url = str.replace(/index\.html$/, '');
|
115
|
+
if (!permalink.endsWith('.html')) {
|
116
|
+
url = url.replace(/\.html$/, '');
|
117
|
+
}
|
118
|
+
return url;
|
119
|
+
});
|
153
120
|
hexo.extend.helper.register('canonical', function () {
|
154
|
-
|
155
|
-
})
|
156
|
-
|
157
|
-
/**
|
158
|
-
* Get page path given a certain language tag
|
159
|
-
*/
|
160
|
-
// 注册hexo主题的国际化路径帮助方法
|
121
|
+
return `<link rel="canonical" href="${this._permapath(this.url)}">`;
|
122
|
+
});
|
161
123
|
hexo.extend.helper.register('i18n_path', function (language) {
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
// 通过调用url_for方法,生成国际化路径
|
167
|
-
return url_for.call(this, `${this.languages.indexOf(language) === 0 ? '' : '/' + language}/${base}`)
|
168
|
-
})
|
169
|
-
|
170
|
-
/**
|
171
|
-
* Get the language name
|
172
|
-
*/
|
173
|
-
// 注册hexo主题的语言名称帮助方法
|
124
|
+
const { path, lang } = this.page;
|
125
|
+
const base = path.startsWith(lang) ? path.slice(lang.length + 1) : path;
|
126
|
+
return hexo_util_1.url_for.call(this, `${this.languages.indexOf(language) === 0 ? '' : '/' + language}/${base}`);
|
127
|
+
});
|
174
128
|
hexo.extend.helper.register('language_name', function (language) {
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
return name === 'name' ? language : name
|
179
|
-
})
|
180
|
-
|
129
|
+
const name = hexo.theme.i18n.__(language)('name');
|
130
|
+
return name === 'name' ? language : name;
|
131
|
+
});
|
181
132
|
hexo.extend.helper.register('random_color', function () {
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
const [r, g, b] = arr
|
190
|
-
return `#${
|
191
|
-
r.toString(16).length > 1 ? r.toString(16) : '0' + r.toString(16)
|
192
|
-
}${g.toString(16).length > 1 ? g.toString(16) : '0' + g.toString(16)}${
|
193
|
-
b.toString(16).length > 1 ? b.toString(16) : '0' + b.toString(16)
|
194
|
-
}`
|
195
|
-
})
|
196
|
-
|
133
|
+
const arr = [];
|
134
|
+
for (let i = 0; i < 3; i++) {
|
135
|
+
arr.push(Math.floor(Math.random() * 128 + 128));
|
136
|
+
}
|
137
|
+
const [r, g, b] = arr;
|
138
|
+
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)}`;
|
139
|
+
});
|
197
140
|
hexo.extend.helper.register('shokax_inject', function (point) {
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
})
|
141
|
+
return hexo.theme.config.injects[point]
|
142
|
+
.map(item => this.partial(item.layout, item.locals, item.options))
|
143
|
+
.join('');
|
144
|
+
});
|