hexo-theme-shokax 0.0.2-alpha2 → 0.0.2-alpha3
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/CODE_OF_CONDUCT.md +128 -0
- package/CONTRIBUTING.md +56 -0
- package/LICENSE +28 -28
- package/LICENSE-shoka +21 -21
- package/README.md +46 -55
- package/README_en.MD +25 -0
- package/_config.yml +392 -355
- package/_images.yml +100 -100
- package/languages/README.md +19 -19
- package/languages/default.yml +1 -1
- package/languages/en.yml +151 -151
- package/languages/ja.yml +146 -146
- package/languages/zh-CN.yml +154 -154
- package/languages/zh-HK.yml +146 -146
- package/languages/zh-TW.yml +146 -146
- 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 +37 -37
- package/layout/_mixin/comment.pug +66 -12
- package/layout/_mixin/postmeta.pug +30 -30
- package/layout/_mixin/segment.pug +32 -32
- package/layout/_mixin/sidebar.pug +36 -36
- package/layout/_mixin/widgets.pug +31 -29
- package/layout/_partials/footer.pug +40 -40
- package/layout/_partials/head/head.pug +51 -58
- package/layout/_partials/head/head_com.pug +17 -17
- package/layout/_partials/head/pwa.pug +18 -18
- package/layout/_partials/header.pug +18 -18
- package/layout/_partials/layout.pug +143 -153
- 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 +14 -14
- package/layout/_partials/post/nav.pug +13 -13
- package/layout/_partials/post/post.pug +28 -28
- package/layout/_partials/post/reward.pug +18 -18
- package/layout/_partials/sidebar/menu.pug +37 -37
- package/layout/_partials/sidebar/overview.pug +41 -42
- package/layout/_partials/third-party/baidu-analytics.pug +11 -11
- package/layout/_partials/third-party/clarity.pug +8 -8
- package/layout/archive.pug +118 -118
- package/layout/category.pug +63 -63
- package/layout/index.pug +33 -33
- package/layout/page.pug +56 -56
- package/layout/post.pug +35 -35
- package/layout/tag.pug +43 -43
- package/package.json +35 -35
- package/scripts/filters/locals.js +59 -59
- package/scripts/filters/post.js +23 -23
- package/scripts/generaters/archive.js +141 -141
- package/scripts/generaters/config.js +43 -43
- package/scripts/generaters/images.js +26 -26
- package/scripts/generaters/index.js +110 -110
- package/scripts/generaters/pages.js +19 -19
- package/scripts/generaters/script.js +89 -89
- package/scripts/helpers/asset.js +183 -237
- package/scripts/helpers/engine.js +190 -190
- package/scripts/helpers/list_categories.js +140 -140
- package/scripts/helpers/symbols_count_time.js +76 -76
- package/scripts/plugin/index.js +6 -6
- package/scripts/plugin/lib/injects-point.js +19 -19
- package/scripts/plugin/lib/injects.js +89 -88
- package/scripts/tags/links.js +86 -86
- package/scripts/tags/media.js +19 -19
- 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 +353 -353
- 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 +385 -385
- 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 +264 -264
- 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 +63 -63
- 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 +83 -83
- 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/valine.styl +548 -548
- package/source/css/_common/components/third-party/widgets.styl +57 -57
- package/source/css/_common/outline/footer/footer.styl +69 -69
- 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 +79 -79
- 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 +50 -50
- 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 +75 -75
- 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 +318 -318
- package/source/css/_common/scaffolding/base.styl +172 -172
- 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 +289 -289
- 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 +451 -451
- package/source/css/_mixins.styl +146 -146
- package/source/css/_variables.styl +89 -89
- package/source/css/app.styl +36 -36
- package/source/css/comment.styl +5 -5
- package/source/css/mermaid.styl +5 -5
- package/source/js/_app/components.js +330 -330
- package/source/js/_app/global.js +317 -317
- package/source/js/_app/library.js +302 -302
- package/source/js/_app/page.js +623 -623
- package/source/js/_app/player.js +748 -748
- package/source/js/_app/vue.js +43 -43
@@ -1,190 +1,190 @@
|
|
1
|
-
/* global hexo */
|
2
|
-
|
3
|
-
'use strict'
|
4
|
-
|
5
|
-
const { htmlTag, url_for } = require('hexo-util')
|
6
|
-
const url = require('url')
|
7
|
-
const crypto = require('crypto')
|
8
|
-
|
9
|
-
const randomServer = parseInt(Math.random() * 4, 10) + 1
|
10
|
-
|
11
|
-
const randomBG = function (count = 1, image_server = null, image_list = []) {
|
12
|
-
let i
|
13
|
-
if (image_server) {
|
14
|
-
if (count && count > 1) {
|
15
|
-
const arr = new Array(count)
|
16
|
-
for (i = 0; i < arr.length; i++) {
|
17
|
-
arr[i] = image_server + '?' + Math.floor(Math.random() * 999999)
|
18
|
-
}
|
19
|
-
|
20
|
-
return arr
|
21
|
-
}
|
22
|
-
|
23
|
-
return image_server + '?' + Math.floor(Math.random() * 999999)
|
24
|
-
}
|
25
|
-
|
26
|
-
const parseImage = function (img, size) {
|
27
|
-
if (img.startsWith('//') || img.startsWith('http')) {
|
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
|
32
|
-
}
|
33
|
-
}
|
34
|
-
|
35
|
-
if (count && count > 1) {
|
36
|
-
const shuffled = image_list.slice(0)
|
37
|
-
i = image_list.length
|
38
|
-
const min = i - count; let temp; 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
|
-
|
46
|
-
return shuffled.slice(min).map(function (img) {
|
47
|
-
return parseImage(img, 'large')
|
48
|
-
})
|
49
|
-
}
|
50
|
-
|
51
|
-
return parseImage(image_list[Math.floor(Math.random() * image_list.length)], 'mw690')
|
52
|
-
}
|
53
|
-
|
54
|
-
hexo.extend.helper.register('_url', function (path, text, options = {}) {
|
55
|
-
if (!path) { return }
|
56
|
-
|
57
|
-
const { config } = this
|
58
|
-
// eslint-disable-next-line n/no-deprecated-api
|
59
|
-
const data = url.parse(path)
|
60
|
-
// eslint-disable-next-line n/no-deprecated-api
|
61
|
-
const siteHost = url.parse(config.url).hostname || config.url
|
62
|
-
|
63
|
-
const theme = hexo.theme.config
|
64
|
-
let exturl = ''
|
65
|
-
let tag = 'a'
|
66
|
-
let attrs = { href: url_for.call(this, path) }
|
67
|
-
|
68
|
-
// If `exturl` enabled, set spanned links only on external links.
|
69
|
-
if (theme.exturl && data.protocol && data.hostname !== siteHost) {
|
70
|
-
tag = 'span'
|
71
|
-
exturl = 'exturl'
|
72
|
-
const encoded = Buffer.from(path).toString('base64')
|
73
|
-
attrs = {
|
74
|
-
class: exturl,
|
75
|
-
'data-url': encoded
|
76
|
-
}
|
77
|
-
}
|
78
|
-
|
79
|
-
for (const key in options) {
|
80
|
-
/**
|
81
|
-
* If option have `class` attribute, add it to
|
82
|
-
* 'exturl' class if `exturl` option enabled.
|
83
|
-
*/
|
84
|
-
if (exturl !== '' && key === 'class') {
|
85
|
-
attrs[key] += ' ' + options[key]
|
86
|
-
} else {
|
87
|
-
attrs[key] = options[key]
|
88
|
-
}
|
89
|
-
}
|
90
|
-
|
91
|
-
if (attrs.class && Array.isArray(attrs.class)) {
|
92
|
-
attrs.class = attrs.class.join(' ')
|
93
|
-
}
|
94
|
-
|
95
|
-
// If it's external link, rewrite attributes.
|
96
|
-
if (data.protocol && data.hostname !== siteHost) {
|
97
|
-
attrs.external = null
|
98
|
-
|
99
|
-
if (!theme.exturl) {
|
100
|
-
// Only for simple link need to rewrite/add attributes.
|
101
|
-
attrs.rel = 'noopener'
|
102
|
-
attrs.target = '_blank'
|
103
|
-
} else {
|
104
|
-
// Remove rel attributes for `exturl` in main menu.
|
105
|
-
attrs.rel = null
|
106
|
-
}
|
107
|
-
}
|
108
|
-
|
109
|
-
return htmlTag(tag, attrs, decodeURI(text), false)
|
110
|
-
})
|
111
|
-
|
112
|
-
hexo.extend.helper.register('_image_url', function (img, path = '') {
|
113
|
-
const { statics } = hexo.theme.config
|
114
|
-
const { post_asset_folder } = hexo.config
|
115
|
-
|
116
|
-
if (img.startsWith('//') || img.startsWith('http')) {
|
117
|
-
return img
|
118
|
-
} else {
|
119
|
-
return url_for.call(this, statics + (post_asset_folder ? path : '') + img)
|
120
|
-
}
|
121
|
-
})
|
122
|
-
|
123
|
-
hexo.extend.helper.register('_cover', function (item, num) {
|
124
|
-
const { statics, js, image_server, image_list } = hexo.theme.config
|
125
|
-
|
126
|
-
if (item.cover) {
|
127
|
-
return this._image_url(item.cover, item.path)
|
128
|
-
} else if (item.photos && item.photos.length > 0) {
|
129
|
-
return this._image_url(item.photos[0], item.path)
|
130
|
-
} else {
|
131
|
-
return randomBG(num || 1, image_server, image_list)
|
132
|
-
}
|
133
|
-
})
|
134
|
-
|
135
|
-
// TODO 此函数已被废弃
|
136
|
-
hexo.extend.helper.register('_md5', function (path) {
|
137
|
-
const str = url_for.call(this, path)
|
138
|
-
str.replace('index.html', '')
|
139
|
-
return crypto.createHash('md5').update(str).digest('hex')
|
140
|
-
})
|
141
|
-
|
142
|
-
hexo.extend.helper.register('_permapath', function (str) {
|
143
|
-
// https://support.google.com/webmasters/answer/139066
|
144
|
-
const { permalink } = hexo.config
|
145
|
-
let url = str.replace(/index\.html$/, '')
|
146
|
-
if (!permalink.endsWith('.html')) {
|
147
|
-
url = url.replace(/\.html$/, '')
|
148
|
-
}
|
149
|
-
return url
|
150
|
-
})
|
151
|
-
|
152
|
-
hexo.extend.helper.register('canonical', function () {
|
153
|
-
return `<link rel="canonical" href="${this._permapath(this.url)}">`
|
154
|
-
})
|
155
|
-
|
156
|
-
/**
|
157
|
-
* Get page path given a certain language tag
|
158
|
-
*/
|
159
|
-
hexo.extend.helper.register('i18n_path', function (language) {
|
160
|
-
const { path, lang } = this.page
|
161
|
-
const base = path.startsWith(lang) ? path.slice(lang.length + 1) : path
|
162
|
-
return url_for.call(this, `${this.languages.indexOf(language) === 0 ? '' : '/' + language}/${base}`)
|
163
|
-
})
|
164
|
-
|
165
|
-
/**
|
166
|
-
* Get the language name
|
167
|
-
*/
|
168
|
-
hexo.extend.helper.register('language_name', function (language) {
|
169
|
-
const name = hexo.theme.i18n.__(language)('name')
|
170
|
-
return name === 'name' ? language : name
|
171
|
-
})
|
172
|
-
|
173
|
-
hexo.extend.helper.register('random_color', function () {
|
174
|
-
const arr = []
|
175
|
-
for (let i = 0; i < 3; i++) {
|
176
|
-
arr.push(Math.floor(Math.random() * 128 + 128))
|
177
|
-
}
|
178
|
-
const [r, g, b] = arr
|
179
|
-
return `#${
|
180
|
-
r.toString(16).length > 1 ? r.toString(16) : '0' + r.toString(16)
|
181
|
-
}${g.toString(16).length > 1 ? g.toString(16) : '0' + g.toString(16)}${
|
182
|
-
b.toString(16).length > 1 ? b.toString(16) : '0' + b.toString(16)
|
183
|
-
}`
|
184
|
-
})
|
185
|
-
|
186
|
-
hexo.extend.helper.register('shokax_inject', function (point) {
|
187
|
-
return hexo.theme.config.injects[point]
|
188
|
-
.map(item => this.partial(item.layout, item.locals, item.options))
|
189
|
-
.join('')
|
190
|
-
})
|
1
|
+
/* global hexo */
|
2
|
+
|
3
|
+
'use strict'
|
4
|
+
|
5
|
+
const { htmlTag, url_for } = require('hexo-util')
|
6
|
+
const url = require('url')
|
7
|
+
const crypto = require('crypto')
|
8
|
+
|
9
|
+
const randomServer = parseInt(Math.random() * 4, 10) + 1
|
10
|
+
|
11
|
+
const randomBG = function (count = 1, image_server = null, image_list = []) {
|
12
|
+
let i
|
13
|
+
if (image_server) {
|
14
|
+
if (count && count > 1) {
|
15
|
+
const arr = new Array(count)
|
16
|
+
for (i = 0; i < arr.length; i++) {
|
17
|
+
arr[i] = image_server + '?' + Math.floor(Math.random() * 999999)
|
18
|
+
}
|
19
|
+
|
20
|
+
return arr
|
21
|
+
}
|
22
|
+
|
23
|
+
return image_server + '?' + Math.floor(Math.random() * 999999)
|
24
|
+
}
|
25
|
+
|
26
|
+
const parseImage = function (img, size) {
|
27
|
+
if (img.startsWith('//') || img.startsWith('http')) {
|
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
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
if (count && count > 1) {
|
36
|
+
const shuffled = image_list.slice(0)
|
37
|
+
i = image_list.length
|
38
|
+
const min = i - count; let temp; 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
|
+
|
46
|
+
return shuffled.slice(min).map(function (img) {
|
47
|
+
return parseImage(img, 'large')
|
48
|
+
})
|
49
|
+
}
|
50
|
+
|
51
|
+
return parseImage(image_list[Math.floor(Math.random() * image_list.length)], 'mw690')
|
52
|
+
}
|
53
|
+
|
54
|
+
hexo.extend.helper.register('_url', function (path, text, options = {}) {
|
55
|
+
if (!path) { return }
|
56
|
+
|
57
|
+
const { config } = this
|
58
|
+
// eslint-disable-next-line n/no-deprecated-api
|
59
|
+
const data = url.parse(path)
|
60
|
+
// eslint-disable-next-line n/no-deprecated-api
|
61
|
+
const siteHost = url.parse(config.url).hostname || config.url
|
62
|
+
|
63
|
+
const theme = hexo.theme.config
|
64
|
+
let exturl = ''
|
65
|
+
let tag = 'a'
|
66
|
+
let attrs = { href: url_for.call(this, path) }
|
67
|
+
|
68
|
+
// If `exturl` enabled, set spanned links only on external links.
|
69
|
+
if (theme.exturl && data.protocol && data.hostname !== siteHost) {
|
70
|
+
tag = 'span'
|
71
|
+
exturl = 'exturl'
|
72
|
+
const encoded = Buffer.from(path).toString('base64')
|
73
|
+
attrs = {
|
74
|
+
class: exturl,
|
75
|
+
'data-url': encoded
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
for (const key in options) {
|
80
|
+
/**
|
81
|
+
* If option have `class` attribute, add it to
|
82
|
+
* 'exturl' class if `exturl` option enabled.
|
83
|
+
*/
|
84
|
+
if (exturl !== '' && key === 'class') {
|
85
|
+
attrs[key] += ' ' + options[key]
|
86
|
+
} else {
|
87
|
+
attrs[key] = options[key]
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
if (attrs.class && Array.isArray(attrs.class)) {
|
92
|
+
attrs.class = attrs.class.join(' ')
|
93
|
+
}
|
94
|
+
|
95
|
+
// If it's external link, rewrite attributes.
|
96
|
+
if (data.protocol && data.hostname !== siteHost) {
|
97
|
+
attrs.external = null
|
98
|
+
|
99
|
+
if (!theme.exturl) {
|
100
|
+
// Only for simple link need to rewrite/add attributes.
|
101
|
+
attrs.rel = 'noopener'
|
102
|
+
attrs.target = '_blank'
|
103
|
+
} else {
|
104
|
+
// Remove rel attributes for `exturl` in main menu.
|
105
|
+
attrs.rel = null
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
return htmlTag(tag, attrs, decodeURI(text), false)
|
110
|
+
})
|
111
|
+
|
112
|
+
hexo.extend.helper.register('_image_url', function (img, path = '') {
|
113
|
+
const { statics } = hexo.theme.config
|
114
|
+
const { post_asset_folder } = hexo.config
|
115
|
+
|
116
|
+
if (img.startsWith('//') || img.startsWith('http')) {
|
117
|
+
return img
|
118
|
+
} else {
|
119
|
+
return url_for.call(this, statics + (post_asset_folder ? path : '') + img)
|
120
|
+
}
|
121
|
+
})
|
122
|
+
|
123
|
+
hexo.extend.helper.register('_cover', function (item, num) {
|
124
|
+
const { statics, js, image_server, image_list } = hexo.theme.config
|
125
|
+
|
126
|
+
if (item.cover) {
|
127
|
+
return this._image_url(item.cover, item.path)
|
128
|
+
} else if (item.photos && item.photos.length > 0) {
|
129
|
+
return this._image_url(item.photos[0], item.path)
|
130
|
+
} else {
|
131
|
+
return randomBG(num || 1, image_server, image_list)
|
132
|
+
}
|
133
|
+
})
|
134
|
+
|
135
|
+
// TODO 此函数已被废弃
|
136
|
+
hexo.extend.helper.register('_md5', function (path) {
|
137
|
+
const str = url_for.call(this, path)
|
138
|
+
str.replace('index.html', '')
|
139
|
+
return crypto.createHash('md5').update(str).digest('hex')
|
140
|
+
})
|
141
|
+
|
142
|
+
hexo.extend.helper.register('_permapath', function (str) {
|
143
|
+
// https://support.google.com/webmasters/answer/139066
|
144
|
+
const { permalink } = hexo.config
|
145
|
+
let url = str.replace(/index\.html$/, '')
|
146
|
+
if (!permalink.endsWith('.html')) {
|
147
|
+
url = url.replace(/\.html$/, '')
|
148
|
+
}
|
149
|
+
return url
|
150
|
+
})
|
151
|
+
|
152
|
+
hexo.extend.helper.register('canonical', function () {
|
153
|
+
return `<link rel="canonical" href="${this._permapath(this.url)}">`
|
154
|
+
})
|
155
|
+
|
156
|
+
/**
|
157
|
+
* Get page path given a certain language tag
|
158
|
+
*/
|
159
|
+
hexo.extend.helper.register('i18n_path', function (language) {
|
160
|
+
const { path, lang } = this.page
|
161
|
+
const base = path.startsWith(lang) ? path.slice(lang.length + 1) : path
|
162
|
+
return url_for.call(this, `${this.languages.indexOf(language) === 0 ? '' : '/' + language}/${base}`)
|
163
|
+
})
|
164
|
+
|
165
|
+
/**
|
166
|
+
* Get the language name
|
167
|
+
*/
|
168
|
+
hexo.extend.helper.register('language_name', function (language) {
|
169
|
+
const name = hexo.theme.i18n.__(language)('name')
|
170
|
+
return name === 'name' ? language : name
|
171
|
+
})
|
172
|
+
|
173
|
+
hexo.extend.helper.register('random_color', function () {
|
174
|
+
const arr = []
|
175
|
+
for (let i = 0; i < 3; i++) {
|
176
|
+
arr.push(Math.floor(Math.random() * 128 + 128))
|
177
|
+
}
|
178
|
+
const [r, g, b] = arr
|
179
|
+
return `#${
|
180
|
+
r.toString(16).length > 1 ? r.toString(16) : '0' + r.toString(16)
|
181
|
+
}${g.toString(16).length > 1 ? g.toString(16) : '0' + g.toString(16)}${
|
182
|
+
b.toString(16).length > 1 ? b.toString(16) : '0' + b.toString(16)
|
183
|
+
}`
|
184
|
+
})
|
185
|
+
|
186
|
+
hexo.extend.helper.register('shokax_inject', function (point) {
|
187
|
+
return hexo.theme.config.injects[point]
|
188
|
+
.map(item => this.partial(item.layout, item.locals, item.options))
|
189
|
+
.join('')
|
190
|
+
})
|
@@ -1,140 +1,140 @@
|
|
1
|
-
'use strict'
|
2
|
-
/* global hexo */
|
3
|
-
|
4
|
-
const fs = require('hexo-fs')
|
5
|
-
|
6
|
-
const prepareQuery = (categories, parent) => {
|
7
|
-
const query = {}
|
8
|
-
|
9
|
-
if (parent) {
|
10
|
-
query.parent = parent
|
11
|
-
} else {
|
12
|
-
query.parent = { $exists: false }
|
13
|
-
}
|
14
|
-
|
15
|
-
return categories.find(query).sort('name', 1).filter(cat => cat.length)
|
16
|
-
}
|
17
|
-
|
18
|
-
hexo.extend.helper.register('_list_categories', function (depth = 0) {
|
19
|
-
// let hexo = this
|
20
|
-
const categories = this.site.categories
|
21
|
-
|
22
|
-
if (!categories || !categories.length) return ''
|
23
|
-
|
24
|
-
const hierarchicalList = (level, parent) => {
|
25
|
-
let result = ''
|
26
|
-
|
27
|
-
prepareQuery(categories, parent).forEach((cat, i) => {
|
28
|
-
let child
|
29
|
-
|
30
|
-
if (level + 1 < depth) {
|
31
|
-
child = hierarchicalList(level + 1, cat._id)
|
32
|
-
}
|
33
|
-
|
34
|
-
const catname = `<a itemprop="url" href="${this.url_for(cat.path)}">${cat.name}</a><small>( ${cat.length} )</small>`
|
35
|
-
|
36
|
-
switch (level) {
|
37
|
-
case 0:
|
38
|
-
result += `<div><h2 class="item header">${catname}</h2>`
|
39
|
-
break
|
40
|
-
|
41
|
-
case 1:
|
42
|
-
result += `<h3 class="item section">${catname}</h3>`
|
43
|
-
break
|
44
|
-
|
45
|
-
case 2:
|
46
|
-
result += `<div class="item normal"><div class="title">${catname}</div></div>`
|
47
|
-
break
|
48
|
-
}
|
49
|
-
|
50
|
-
if (child) {
|
51
|
-
result += `${child}`
|
52
|
-
}
|
53
|
-
|
54
|
-
if (level === 0) {
|
55
|
-
result += '</div>'
|
56
|
-
}
|
57
|
-
})
|
58
|
-
|
59
|
-
return result
|
60
|
-
}
|
61
|
-
|
62
|
-
return hierarchicalList(0)
|
63
|
-
})
|
64
|
-
|
65
|
-
hexo.extend.helper.register('_categories', function () {
|
66
|
-
// let hexo = this
|
67
|
-
const categories = this.site.categories
|
68
|
-
if (!categories || !categories.length) return ''
|
69
|
-
|
70
|
-
const pangu = this.theme.pangu
|
71
|
-
? require('pangu')
|
72
|
-
: {
|
73
|
-
spacing: data => {
|
74
|
-
return data
|
75
|
-
}
|
76
|
-
}
|
77
|
-
|
78
|
-
const result = {}
|
79
|
-
|
80
|
-
categories.forEach((cat, i) => {
|
81
|
-
const child = prepareQuery(categories, cat._id)
|
82
|
-
const cover = 'source/_posts' + cat.path.replace(this.config.category_dir, '') + 'cover.jpg'
|
83
|
-
|
84
|
-
if (fs.existsSync(cover)) {
|
85
|
-
const className = cat.slug.split('/')
|
86
|
-
className.pop()
|
87
|
-
cat.class = className.join(' ')
|
88
|
-
cat.name = pangu.spacing(cat.name)
|
89
|
-
|
90
|
-
if (child.length !== 0) {
|
91
|
-
cat.child = child
|
92
|
-
}
|
93
|
-
|
94
|
-
result[cat._id] = cat
|
95
|
-
}
|
96
|
-
})
|
97
|
-
|
98
|
-
return result
|
99
|
-
})
|
100
|
-
|
101
|
-
hexo.extend.helper.register('_category_prev', function (name) {
|
102
|
-
// let hexo = this
|
103
|
-
const categories = this.site.categories
|
104
|
-
if (!categories || !categories.length) return ''
|
105
|
-
|
106
|
-
let result = ''
|
107
|
-
|
108
|
-
categories.find({ name }).forEach((current) => {
|
109
|
-
if (current.parent) {
|
110
|
-
categories.find({ _id: current.parent }).forEach((cat, i) => {
|
111
|
-
result += `<a href="${this.url_for(cat.path)}">${cat.name}</a>`
|
112
|
-
})
|
113
|
-
}
|
114
|
-
})
|
115
|
-
|
116
|
-
return result
|
117
|
-
})
|
118
|
-
|
119
|
-
hexo.extend.helper.register('_category_posts', function (page) {
|
120
|
-
// let hexo = this
|
121
|
-
const categories = this.site.categories
|
122
|
-
if (!categories || !categories.length || !page.categories || !page.categories.length) return ''
|
123
|
-
|
124
|
-
let result = ''
|
125
|
-
const cat = page.categories.toArray()
|
126
|
-
|
127
|
-
categories.find({ _id: cat[cat.length - 1]._id }).forEach((category) => {
|
128
|
-
if (category.posts) {
|
129
|
-
category.posts.sort('date', 1).forEach((post) => {
|
130
|
-
let current = ''
|
131
|
-
if (post.path === page.path) {
|
132
|
-
current = ' class="active"'
|
133
|
-
}
|
134
|
-
result += `<li ${current}><a href="${this.url_for(post.path)}" rel="bookmark" title="${post.title}">${post.title}</a></li>`
|
135
|
-
})
|
136
|
-
}
|
137
|
-
})
|
138
|
-
|
139
|
-
return result
|
140
|
-
})
|
1
|
+
'use strict'
|
2
|
+
/* global hexo */
|
3
|
+
|
4
|
+
const fs = require('hexo-fs')
|
5
|
+
|
6
|
+
const prepareQuery = (categories, parent) => {
|
7
|
+
const query = {}
|
8
|
+
|
9
|
+
if (parent) {
|
10
|
+
query.parent = parent
|
11
|
+
} else {
|
12
|
+
query.parent = { $exists: false }
|
13
|
+
}
|
14
|
+
|
15
|
+
return categories.find(query).sort('name', 1).filter(cat => cat.length)
|
16
|
+
}
|
17
|
+
|
18
|
+
hexo.extend.helper.register('_list_categories', function (depth = 0) {
|
19
|
+
// let hexo = this
|
20
|
+
const categories = this.site.categories
|
21
|
+
|
22
|
+
if (!categories || !categories.length) return ''
|
23
|
+
|
24
|
+
const hierarchicalList = (level, parent) => {
|
25
|
+
let result = ''
|
26
|
+
|
27
|
+
prepareQuery(categories, parent).forEach((cat, i) => {
|
28
|
+
let child
|
29
|
+
|
30
|
+
if (level + 1 < depth) {
|
31
|
+
child = hierarchicalList(level + 1, cat._id)
|
32
|
+
}
|
33
|
+
|
34
|
+
const catname = `<a itemprop="url" href="${this.url_for(cat.path)}">${cat.name}</a><small>( ${cat.length} )</small>`
|
35
|
+
|
36
|
+
switch (level) {
|
37
|
+
case 0:
|
38
|
+
result += `<div><h2 class="item header">${catname}</h2>`
|
39
|
+
break
|
40
|
+
|
41
|
+
case 1:
|
42
|
+
result += `<h3 class="item section">${catname}</h3>`
|
43
|
+
break
|
44
|
+
|
45
|
+
case 2:
|
46
|
+
result += `<div class="item normal"><div class="title">${catname}</div></div>`
|
47
|
+
break
|
48
|
+
}
|
49
|
+
|
50
|
+
if (child) {
|
51
|
+
result += `${child}`
|
52
|
+
}
|
53
|
+
|
54
|
+
if (level === 0) {
|
55
|
+
result += '</div>'
|
56
|
+
}
|
57
|
+
})
|
58
|
+
|
59
|
+
return result
|
60
|
+
}
|
61
|
+
|
62
|
+
return hierarchicalList(0)
|
63
|
+
})
|
64
|
+
|
65
|
+
hexo.extend.helper.register('_categories', function () {
|
66
|
+
// let hexo = this
|
67
|
+
const categories = this.site.categories
|
68
|
+
if (!categories || !categories.length) return ''
|
69
|
+
|
70
|
+
const pangu = this.theme.pangu
|
71
|
+
? require('pangu')
|
72
|
+
: {
|
73
|
+
spacing: data => {
|
74
|
+
return data
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
const result = {}
|
79
|
+
|
80
|
+
categories.forEach((cat, i) => {
|
81
|
+
const child = prepareQuery(categories, cat._id)
|
82
|
+
const cover = 'source/_posts' + cat.path.replace(this.config.category_dir, '') + 'cover.jpg'
|
83
|
+
|
84
|
+
if (fs.existsSync(cover)) {
|
85
|
+
const className = cat.slug.split('/')
|
86
|
+
className.pop()
|
87
|
+
cat.class = className.join(' ')
|
88
|
+
cat.name = pangu.spacing(cat.name)
|
89
|
+
|
90
|
+
if (child.length !== 0) {
|
91
|
+
cat.child = child
|
92
|
+
}
|
93
|
+
|
94
|
+
result[cat._id] = cat
|
95
|
+
}
|
96
|
+
})
|
97
|
+
|
98
|
+
return result
|
99
|
+
})
|
100
|
+
|
101
|
+
hexo.extend.helper.register('_category_prev', function (name) {
|
102
|
+
// let hexo = this
|
103
|
+
const categories = this.site.categories
|
104
|
+
if (!categories || !categories.length) return ''
|
105
|
+
|
106
|
+
let result = ''
|
107
|
+
|
108
|
+
categories.find({ name }).forEach((current) => {
|
109
|
+
if (current.parent) {
|
110
|
+
categories.find({ _id: current.parent }).forEach((cat, i) => {
|
111
|
+
result += `<a href="${this.url_for(cat.path)}">${cat.name}</a>`
|
112
|
+
})
|
113
|
+
}
|
114
|
+
})
|
115
|
+
|
116
|
+
return result
|
117
|
+
})
|
118
|
+
|
119
|
+
hexo.extend.helper.register('_category_posts', function (page) {
|
120
|
+
// let hexo = this
|
121
|
+
const categories = this.site.categories
|
122
|
+
if (!categories || !categories.length || !page.categories || !page.categories.length) return ''
|
123
|
+
|
124
|
+
let result = ''
|
125
|
+
const cat = page.categories.toArray()
|
126
|
+
|
127
|
+
categories.find({ _id: cat[cat.length - 1]._id }).forEach((category) => {
|
128
|
+
if (category.posts) {
|
129
|
+
category.posts.sort('date', 1).forEach((post) => {
|
130
|
+
let current = ''
|
131
|
+
if (post.path === page.path) {
|
132
|
+
current = ' class="active"'
|
133
|
+
}
|
134
|
+
result += `<li ${current}><a href="${this.url_for(post.path)}" rel="bookmark" title="${post.title}">${post.title}</a></li>`
|
135
|
+
})
|
136
|
+
}
|
137
|
+
})
|
138
|
+
|
139
|
+
return result
|
140
|
+
})
|