hexo-theme-shokax 0.3.12 → 0.4.0-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. package/README.md +10 -3
  2. package/README_en.MD +13 -5
  3. package/_config.yml +19 -16
  4. package/layout/_mixin/comment.pug +4 -4
  5. package/layout/_mixin/segment.pug +1 -1
  6. package/layout/_partials/head/head.pug +0 -1
  7. package/layout/_partials/post/post.pug +1 -1
  8. package/layout/_partials/post/reward.pug +1 -1
  9. package/layout/_partials/sidebar/overview.pug +1 -1
  10. package/package.json +11 -11
  11. package/scripts/filters/locals.d.ts +1 -0
  12. package/scripts/filters/locals.ts +59 -0
  13. package/scripts/filters/post.d.ts +0 -0
  14. package/scripts/filters/post.js +1 -1
  15. package/scripts/filters/post.ts +6 -0
  16. package/scripts/generaters/archive.d.ts +1 -0
  17. package/scripts/generaters/archive.ts +144 -0
  18. package/scripts/generaters/config.d.ts +1 -0
  19. package/scripts/generaters/config.ts +52 -0
  20. package/scripts/generaters/images.d.ts +1 -0
  21. package/scripts/generaters/images.ts +26 -0
  22. package/scripts/generaters/index.d.ts +1 -0
  23. package/scripts/generaters/index.ts +110 -0
  24. package/scripts/generaters/pages.d.ts +0 -0
  25. package/scripts/generaters/pages.ts +16 -0
  26. package/scripts/generaters/script.d.ts +1 -0
  27. package/scripts/generaters/script.js +25 -6
  28. package/scripts/generaters/script.ts +110 -0
  29. package/scripts/helpers/asset.d.ts +1 -0
  30. package/scripts/helpers/asset.ts +158 -0
  31. package/scripts/helpers/engine.d.ts +1 -0
  32. package/scripts/helpers/engine.ts +171 -0
  33. package/scripts/helpers/list_categories.d.ts +1 -0
  34. package/scripts/helpers/list_categories.ts +104 -0
  35. package/scripts/helpers/summary_ai.d.ts +1 -0
  36. package/scripts/helpers/summary_ai.js +1 -1
  37. package/scripts/helpers/summary_ai.ts +100 -0
  38. package/scripts/helpers/symbols_count_time.d.ts +1 -0
  39. package/scripts/helpers/symbols_count_time.ts +76 -0
  40. package/scripts/plugin/check.d.ts +1 -0
  41. package/scripts/plugin/check.ts +35 -0
  42. package/scripts/plugin/index.d.ts +6 -0
  43. package/scripts/plugin/index.ts +52 -0
  44. package/scripts/plugin/lib/injects-point.d.ts +5 -0
  45. package/scripts/plugin/lib/injects-point.ts +20 -0
  46. package/scripts/plugin/lib/injects.d.ts +2 -0
  47. package/scripts/plugin/lib/injects.ts +101 -0
  48. package/scripts/tags/links.d.ts +1 -0
  49. package/scripts/tags/links.ts +75 -0
  50. package/scripts/tags/media.d.ts +1 -0
  51. package/scripts/tags/media.ts +19 -0
  52. package/source/css/_common/components/tags/tabs.styl +3 -1
  53. package/source/css/_common/scaffolding/base.styl +6 -6
  54. package/source/css/_iconfont.styl +4 -0
  55. package/source/js/_app/components/sidebar.ts +237 -0
  56. package/source/js/_app/globals/globalVars.ts +98 -0
  57. package/source/js/_app/globals/handles.ts +122 -0
  58. package/source/js/_app/globals/themeColor.ts +64 -0
  59. package/source/js/_app/globals/thirdparty.ts +63 -0
  60. package/source/js/_app/globals/tools.ts +74 -0
  61. package/source/js/_app/library/anime.ts +109 -0
  62. package/source/js/_app/library/declare.d.ts +117 -0
  63. package/source/js/_app/library/dom.ts +26 -0
  64. package/source/js/_app/library/libtype.d.ts +4 -0
  65. package/source/js/_app/library/loadFile.ts +41 -0
  66. package/source/js/_app/library/proto.ts +143 -0
  67. package/source/js/_app/library/scriptPjax.ts +72 -0
  68. package/source/js/_app/library/storage.ts +12 -0
  69. package/source/js/_app/library/vue.ts +60 -0
  70. package/source/js/_app/page/common.ts +42 -0
  71. package/source/js/_app/page/fancybox.ts +70 -0
  72. package/source/js/_app/page/post.ts +265 -0
  73. package/source/js/_app/page/search.ts +129 -0
  74. package/source/js/_app/page/tab.ts +59 -0
  75. package/source/js/_app/pjax/domInit.ts +95 -0
  76. package/source/js/_app/pjax/refresh.ts +75 -0
  77. package/source/js/_app/pjax/siteInit.ts +67 -0
  78. package/source/js/_app/player.ts +798 -0
  79. package/source/css/twikoo.css +0 -2002
  80. package/source/js/_app/components/sidebar.js +0 -210
  81. package/source/js/_app/fireworks.js +0 -10
  82. package/source/js/_app/globals/globalVars.js +0 -80
  83. package/source/js/_app/globals/handles.js +0 -138
  84. package/source/js/_app/globals/themeColor.js +0 -62
  85. package/source/js/_app/globals/thirdparty.js +0 -71
  86. package/source/js/_app/globals/tools.js +0 -92
  87. package/source/js/_app/library/anime.js +0 -109
  88. package/source/js/_app/library/dom.js +0 -34
  89. package/source/js/_app/library/loadFile.js +0 -36
  90. package/source/js/_app/library/proto.js +0 -163
  91. package/source/js/_app/library/scriptPjax.js +0 -70
  92. package/source/js/_app/library/storage.js +0 -12
  93. package/source/js/_app/library/vue.js +0 -53
  94. package/source/js/_app/page/comment.js +0 -23
  95. package/source/js/_app/page/common.js +0 -41
  96. package/source/js/_app/page/fancybox.js +0 -65
  97. package/source/js/_app/page/post.js +0 -244
  98. package/source/js/_app/page/search.js +0 -118
  99. package/source/js/_app/page/tab.js +0 -53
  100. package/source/js/_app/pjax/domInit.js +0 -76
  101. package/source/js/_app/pjax/refresh.js +0 -53
  102. package/source/js/_app/pjax/siteInit.js +0 -49
  103. package/source/js/_app/player.js +0 -774
@@ -0,0 +1,110 @@
1
+ // @ts-nocheck
2
+ /* global hexo */
3
+ 'use strict'
4
+
5
+ import fs = require('hexo-fs')
6
+ import pagination from 'hexo-pagination'
7
+
8
+ hexo.config.index_generator = Object.assign({
9
+ per_page: typeof hexo.config.per_page === 'undefined' ? 10 : hexo.config.per_page,
10
+ order_by: '-date'
11
+ }, hexo.config.index_generator)
12
+
13
+ hexo.extend.generator.register('index', function (locals) {
14
+ const covers = []
15
+ const catlist = []
16
+ let pages
17
+ const config = hexo.config
18
+ const sticky = locals.posts.find({ sticky: true }).sort(config.index_generator.order_by)
19
+ const posts = locals.posts.find({ sticky: {$in: [false, undefined]} }).sort(config.index_generator.order_by)
20
+ const paginationDir = config.pagination_dir || 'page'
21
+ const path = config.index_generator.path || ''
22
+ const categories = locals.categories
23
+
24
+ const getTopcat = function (cat) {
25
+ if (cat.parent) {
26
+ const pCat = categories.findOne({ _id: cat.parent })
27
+ return getTopcat(pCat)
28
+ } else {
29
+ return cat
30
+ }
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
+ } else if (fs.existsSync(cover + '/cover.webp')) {
44
+ covers.push({
45
+ path: cat.slug + '/cover.webp',
46
+ data: function () {
47
+ return fs.createReadStream(cover + '/cover.webp')
48
+ }
49
+ })
50
+ } else if (fs.existsSync(cover + '/cover.jpg')) {
51
+ covers.push({
52
+ path: cat.slug + '/cover.jpg',
53
+ data: function () {
54
+ return fs.createReadStream(cover + '/cover.jpg')
55
+ }
56
+ })
57
+
58
+ const topcat = getTopcat(cat)
59
+
60
+ if (topcat._id !== cat._id) {
61
+ cat.top = topcat
62
+ }
63
+
64
+ const child = categories.find({ parent: cat._id })
65
+ let pl = 6
66
+
67
+ if (child.length !== 0) {
68
+ cat.child = child.length
69
+ cat.subs = child.sort({ name: 1 }).limit(6).toArray()
70
+ pl = Math.max(0, pl - child.length)
71
+ if (pl > 0) {
72
+ cat.subs.push(...cat.posts.sort({ title: 1 })
73
+ .filter(function (item, i) { return item.categories.last()._id === cat._id })
74
+ .limit(pl).toArray())
75
+ }
76
+ } else {
77
+ cat.subs = cat.posts.sort({ title: 1 }).limit(6).toArray()
78
+ }
79
+
80
+ catlist.push(cat)
81
+ }
82
+ })
83
+ }
84
+
85
+ if (posts.length > 0) {
86
+ pages = pagination(path, posts, {
87
+ perPage: config.index_generator.per_page,
88
+ layout: ['index', 'archive'],
89
+ format: paginationDir + '/%d/',
90
+ data: {
91
+ __index: true,
92
+ catlist,
93
+ sticky
94
+ }
95
+ })
96
+ } else {
97
+ pages = [{
98
+ path,
99
+ layout: ['index', 'archive'],
100
+ data: {
101
+ __index: true,
102
+ catlist,
103
+ sticky,
104
+ current: 1,
105
+ }
106
+ }]
107
+ }
108
+
109
+ return [...covers, ...pages]
110
+ })
File without changes
@@ -0,0 +1,16 @@
1
+ hexo.extend.generator.register('pages', function () {
2
+ const config = hexo.config
3
+
4
+ return [
5
+ {
6
+ path: config.category_dir + '/index.html',
7
+ data: { type: 'categories' },
8
+ layout: 'page'
9
+ },
10
+ {
11
+ path: config.tag_dir + '/index.html',
12
+ data: { type: 'tags' },
13
+ layout: 'page'
14
+ }
15
+ ]
16
+ })
@@ -0,0 +1 @@
1
+ export {};
@@ -67,8 +67,6 @@ hexo.extend.generator.register('script', function (locals) {
67
67
  priority: theme.quicklink.priority
68
68
  },
69
69
  playerAPI: theme.playerAPI,
70
- disableVL: theme.disableVL,
71
- noPlayer: theme.experiments?.noPlayer,
72
70
  audio: undefined,
73
71
  fireworks: (theme.fireworks && theme.fireworks.enable && theme.fireworks.options)
74
72
  ? theme.fireworks.options
@@ -87,21 +85,42 @@ hexo.extend.generator.register('script', function (locals) {
87
85
  }
88
86
  let text;
89
87
  let enterPoint;
90
- if (fs.existsSync('themes/shokaX/source/js/_app/pjax/siteInit.js')) {
91
- enterPoint = 'themes/shokaX/source/js/_app/pjax/siteInit.js';
88
+ if (fs.existsSync('themes/shokaX/source/js/_app/pjax/siteInit.ts')) {
89
+ enterPoint = 'themes/shokaX/source/js/_app/pjax/siteInit.ts';
92
90
  }
93
91
  else {
94
- enterPoint = 'node_modules/hexo-theme-shokax/source/js/_app/pjax/siteInit.js';
92
+ enterPoint = 'node_modules/hexo-theme-shokax/source/js/_app/pjax/siteInit.ts';
95
93
  }
96
94
  text = 'const CONFIG = ' + JSON.stringify(siteConfig) + ';';
97
95
  (0, esbuild_1.buildSync)({
98
96
  entryPoints: [enterPoint],
99
97
  bundle: true,
100
98
  outfile: 'shokax_temp.js',
99
+ tsconfigRaw: {
100
+ compilerOptions: {
101
+ target: 'ES2022',
102
+ esModuleInterop: true,
103
+ module: 'ESNext',
104
+ moduleResolution: 'Node',
105
+ skipLibCheck: true
106
+ }
107
+ },
101
108
  platform: 'browser',
102
109
  format: 'iife',
103
110
  target: ['es2022'],
104
- minify: true
111
+ minify: true,
112
+ define: {
113
+ __UNLAZY_LOGGING__: 'false',
114
+ __UNLAZY_HASH_DECODING__: theme.modules.unlazyHash ? 'true' : 'false',
115
+ __shokax_player__: theme.modules.player ? 'true' : 'false',
116
+ __shokax_VL__: theme.modules.visibilityListener ? 'true' : 'false',
117
+ __shokax_fireworks__: (theme.fireworks && theme.fireworks.enable && theme.fireworks.options && theme.modules.fireworks) ? 'true' : 'false',
118
+ __shokax_search__: config?.algolia ? 'true' : 'false',
119
+ __shokax_outime__: theme.outime.enable ? 'true' : 'false',
120
+ __shokax_tabs__: theme.modules.tabs ? 'true' : 'false',
121
+ __shokax_quiz__: theme.modules.quiz ? 'true' : 'false',
122
+ __shokax_fancybox__: theme.modules.fancybox ? 'true' : 'false'
123
+ }
105
124
  });
106
125
  text += fs.readFileSync('shokax_temp.js');
107
126
  const result = hexo.render.renderSync({ text, engine: 'js' });
@@ -0,0 +1,110 @@
1
+ /* global hexo */
2
+ import env from '../../package.json'
3
+ import * as fs from 'hexo-fs'
4
+ import { buildSync } from 'esbuild'
5
+ import { getVendorLink } from '../utils'
6
+
7
+ hexo.extend.generator.register('script', function (locals) {
8
+ const config = hexo.config
9
+ const theme = hexo.theme.config
10
+
11
+ const siteConfig = {
12
+ version: env.version,
13
+ hostname: config.url,
14
+ root: config.root,
15
+ statics: theme.statics,
16
+ favicon: {
17
+ normal: theme.assets + '/favicon.ico',
18
+ hidden: theme.assets + '/failure.ico'
19
+ },
20
+ darkmode: theme.darkmode,
21
+ auto_dark: theme.auto_dark,
22
+ auto_scroll: theme.auto_scroll,
23
+ js: {
24
+ copy_tex: getVendorLink(hexo, theme.vendors.async_js.copy_tex),
25
+ fancybox: getVendorLink(hexo, theme.vendors.async_js.fancybox)
26
+ },
27
+ css: {
28
+ katex: getVendorLink(hexo, theme.vendors.css.katex),
29
+ mermaid: theme.css + '/mermaid.css',
30
+ fancybox: getVendorLink(hexo, theme.vendors.css.fancybox),
31
+ justifiedGallery: getVendorLink(hexo, theme.vendors.css.justifiedGallery)
32
+ },
33
+ loader: theme.loader,
34
+ search: null,
35
+ outime: {
36
+ enable: theme.outime.enable,
37
+ days: theme.outime.days
38
+ },
39
+ quicklink: {
40
+ timeout: theme.quicklink.timeout,
41
+ priority: theme.quicklink.priority
42
+ },
43
+ playerAPI: theme.playerAPI,
44
+ audio: undefined,
45
+ fireworks: (theme.fireworks && theme.fireworks.enable && theme.fireworks.options)
46
+ ? theme.fireworks.options
47
+ : undefined
48
+ }
49
+
50
+ if (config?.algolia) {
51
+ siteConfig.search = {
52
+ appID: config.algolia.appId,
53
+ apiKey: config.algolia.apiKey,
54
+ indexName: config.algolia.indexName,
55
+ hits: theme.search.hits
56
+ }
57
+ }
58
+
59
+ if (theme?.audio) {
60
+ siteConfig.audio = theme.audio
61
+ }
62
+
63
+ let text: string
64
+ let enterPoint: string
65
+ if (fs.existsSync('themes/shokaX/source/js/_app/pjax/siteInit.ts')) {
66
+ enterPoint = 'themes/shokaX/source/js/_app/pjax/siteInit.ts'
67
+ } else {
68
+ enterPoint = 'node_modules/hexo-theme-shokax/source/js/_app/pjax/siteInit.ts'
69
+ }
70
+ text = 'const CONFIG = ' + JSON.stringify(siteConfig) + ';'
71
+ buildSync({
72
+ entryPoints: [enterPoint],
73
+ bundle: true,
74
+ outfile: 'shokax_temp.js',
75
+ tsconfigRaw: {
76
+ compilerOptions: {
77
+ target: 'ES2022',
78
+ esModuleInterop: true,
79
+ module: 'ESNext',
80
+ moduleResolution: 'Node',
81
+ skipLibCheck: true
82
+ }
83
+ },
84
+ platform: 'browser',
85
+ format: 'iife',
86
+ target: ['es2022'],
87
+ minify: true,
88
+ define: {
89
+ __UNLAZY_LOGGING__: 'false',
90
+ __UNLAZY_HASH_DECODING__: theme.modules.unlazyHash ? 'true' : 'false',
91
+ __shokax_player__: theme.modules.player ? 'true' : 'false',
92
+ __shokax_VL__: theme.modules.visibilityListener ? 'true' : 'false',
93
+ __shokax_fireworks__: (theme.fireworks && theme.fireworks.enable && theme.fireworks.options && theme.modules.fireworks) ? 'true' : 'false',
94
+ __shokax_search__: config?.algolia ? 'true' : 'false',
95
+ __shokax_outime__: theme.outime.enable ? 'true' : 'false',
96
+ __shokax_tabs__: theme.modules.tabs ? 'true' : 'false',
97
+ __shokax_quiz__: theme.modules.quiz ? 'true' : 'false',
98
+ __shokax_fancybox__: theme.modules.fancybox ? 'true' : 'false'
99
+ }
100
+ })
101
+ text += fs.readFileSync('shokax_temp.js')
102
+ const result = hexo.render.renderSync({ text, engine: 'js' })
103
+ fs.unlinkSync('shokax_temp.js')
104
+ return {
105
+ path: theme.js + '/app.js',
106
+ data: function () {
107
+ return result
108
+ }
109
+ }
110
+ })
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,158 @@
1
+ /* global hexo */
2
+
3
+ import type { VendorsConfig } from '../utils'
4
+ import theme_env from '../../package.json'
5
+ import { htmlTag, url_for, stripHTML } from 'hexo-util'
6
+ import { getVendorLink } from '../utils'
7
+
8
+ hexo.extend.helper.register('_new_comments', function (mode) {
9
+ const root = this.config.url.replace(/^(https?:\/\/)?[^\/]*/, '')
10
+ if (mode === 'twikoo') {
11
+ return `<script data-pjax type="module">
12
+ let comments = []
13
+ twikoo.getRecentComments({
14
+ envId: "${hexo.theme.config?.twikoo?.envId}",
15
+ pageSize: 10
16
+ }).then(function (res) {
17
+ res.forEach(function (item) {
18
+ let cText = item.commentText
19
+ if (item.commentText.length > 50) {
20
+ cText = item.commentText.substring(0,50)+'...'
21
+ }
22
+ const siteLink = item.url + "#" + item.id
23
+ comments.push({
24
+ href: siteLink,
25
+ nick: item.nick,
26
+ time: item.relativeTime,
27
+ text: cText
28
+ })
29
+ });
30
+ Vue.createApp({
31
+ data() {
32
+ return {
33
+ coms: comments,
34
+ root: '${root}'
35
+ }
36
+ }
37
+ }).mount('#new-comment')
38
+ }).catch(function (err) {
39
+ console.error(err)
40
+ })
41
+ </script>`
42
+ } else if (mode === 'waline') {
43
+ return `
44
+ <script type="module" data-pjax>
45
+ let items = []
46
+ import { RecentComments } from 'https://npm.webcache.cn/@waline/client@v2/dist/waline.mjs'
47
+ RecentComments({
48
+ serverURL: '${hexo.theme.config.waline.serverURL.replace(/\/+$/, '')}',
49
+ count: 10,
50
+ }).then(({ comments }) => {
51
+ comments.forEach(function (item) {
52
+ let cText = (item.orig.length > 50) ? item.orig.substring(0,50)+'...' : item.orig
53
+ item.url = item.url.startsWith('/') ? item.url : '/' + item.url;
54
+ const siteLink = item.url + "#" + item.objectId
55
+ items.push({
56
+ href: siteLink,
57
+ nick: item.nick,
58
+ time: item.insertedAt.split('T').shift(),
59
+ text: cText
60
+ })
61
+ })
62
+ Vue.createApp({
63
+ data() {
64
+ return {
65
+ coms: items,
66
+ root: '${root}'
67
+ }
68
+ }
69
+ }).mount('#new-comment')
70
+ }).catch(function (err) {
71
+ console.error(err)
72
+ })
73
+ </script>
74
+ `
75
+ } else {
76
+ console.log(`${mode} is not supported recent comment`)
77
+ }
78
+ })
79
+
80
+ hexo.extend.helper.register('_safedump', (source) => {
81
+ return JSON.stringify(source)
82
+ })
83
+
84
+ hexo.extend.helper.register('hexo_env', function (type) {
85
+ return this.env[type]
86
+ })
87
+
88
+ hexo.extend.helper.register('theme_env', function (type) {
89
+ return theme_env[type]
90
+ })
91
+
92
+ hexo.extend.helper.register('_vendor_font', () => {
93
+ const config = hexo.theme.config.font
94
+
95
+ if (!config || !config.enable) return ''
96
+
97
+ const fontDisplay = '&display=swap'
98
+ const fontSubset = '&subset=latin,latin-ext'
99
+ const fontStyles = ':300,300italic,400,400italic,700,700italic'
100
+ const fontHost = 'https://fonts.googleapis.com'
101
+
102
+ // Get a font list from config
103
+ let fontFamilies = ['global', 'logo', 'title', 'headings', 'posts', 'codes'].map(item => {
104
+ if (config[item] && config[item].family && config[item].external) {
105
+ return config[item].family + fontStyles
106
+ }
107
+ return ''
108
+ })
109
+
110
+ fontFamilies = fontFamilies.filter(item => item !== '')
111
+ // @ts-ignore
112
+ fontFamilies = [...new Set(fontFamilies)]
113
+ // @ts-ignore
114
+ fontFamilies = fontFamilies.join('|')
115
+
116
+ // Merge extra parameters to the final processed font string
117
+ return fontFamilies
118
+ ? htmlTag('link', {
119
+ rel: 'stylesheet',
120
+ href: `${fontHost}/css?family=${fontFamilies.concat(fontDisplay, fontSubset)}`
121
+ })
122
+ : ''
123
+ })
124
+
125
+ hexo.extend.helper.register('_css', function (...urls) {
126
+ const { statics, css } = hexo.theme.config
127
+
128
+ return urls.map(url => htmlTag('link', {
129
+ rel: 'stylesheet',
130
+ href: url_for.call(this, `${statics}${css}/${url}?v=${theme_env.version}`)
131
+ })).join('')
132
+ })
133
+
134
+ hexo.extend.helper.register('_js', function (...urls) {
135
+ const { statics, js } = hexo.theme.config
136
+
137
+ return urls.map(url => htmlTag('script', { src: url_for.call(this, `${statics}${js}/${url}?v=${theme_env.version}`) }, '')).join('')
138
+ })
139
+
140
+ hexo.extend.helper.register('vendor_js', function () {
141
+ const vendors = hexo.theme.config.vendors as VendorsConfig
142
+ let res = ''
143
+ for (const jsSync in vendors.js) {
144
+ res += htmlTag('script', { src: getVendorLink(hexo, vendors.js[jsSync]) }, '')
145
+ }
146
+ // for (const jsAsync in vendors.async_js) {
147
+ // res += htmlTag('script', { src: getVendorLink(hexo, vendors.async_js[jsAsync]), async: true }, '')
148
+ // }
149
+ return res
150
+ })
151
+
152
+ hexo.extend.helper.register('_striptags', function (data) {
153
+ return stripHTML(data)
154
+ })
155
+
156
+ hexo.extend.helper.register('_truncate', function (data, end) {
157
+ return data.substring(0, end)
158
+ })
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,171 @@
1
+ 'use strict'
2
+
3
+ // @ts-ignore
4
+ import { htmlTag, url_for } from 'hexo-util'
5
+
6
+ const randomServer = parseInt(String(Math.random() * 4), 10) + 1
7
+
8
+ const randomBG = function (count = 1, image_server:string = null, image_list:string[] = []) {
9
+ let i
10
+ if (image_server) {
11
+ if (count && count > 1) {
12
+ const arr = new Array(count)
13
+ for (i = 0; i < arr.length; i++) {
14
+ arr[i] = image_server + '?' + Math.floor(Math.random() * 999999)
15
+ }
16
+
17
+ return arr
18
+ }
19
+
20
+ return image_server + '?' + Math.floor(Math.random() * 999999)
21
+ }
22
+
23
+ const parseImage = function (img:string, size:string) {
24
+ if (img.startsWith('//') || img.startsWith('http')) {
25
+ return img
26
+ } else if (hexo.theme.config.experiments?.usingRelative) { // support relative url
27
+ return img
28
+ } else {
29
+ console.warn("sinaimg blocked all request from outside website,so don't use this format")
30
+ return `https://tva${randomServer}.sinaimg.cn/` + size + '/' + img
31
+ }
32
+ }
33
+
34
+ if (count && count > 1) {
35
+ let shuffled = image_list.slice(0)
36
+ while (shuffled.length <= 6) {
37
+ shuffled = shuffled.concat(image_list.slice(0))
38
+ }
39
+ i = shuffled.length
40
+ const min = i - count; let temp; let index
41
+ while (i-- > min) {
42
+ index = Math.floor((i + 1) * Math.random())
43
+ temp = shuffled[index]
44
+ shuffled[index] = shuffled[i]
45
+ shuffled[i] = temp
46
+ }
47
+
48
+ return shuffled.slice(min).map(function (img) {
49
+ return parseImage(img, 'large')
50
+ })
51
+ }
52
+
53
+ return parseImage(image_list[Math.floor(Math.random() * image_list.length)], 'mw690')
54
+ }
55
+
56
+ // 注册hexo主题中的URL帮助方法
57
+ hexo.extend.helper.register('_url', function (path, text, options = {}) {
58
+ // 如果未提供URL路径,则返回
59
+ if (!path) { return }
60
+
61
+ let tag = 'a'
62
+ let attrs: { class: string; 'data-url': any; [index:string]:any } = { href: url_for.call(this, path), class: undefined, external: undefined, rel: undefined, 'data-url': undefined }
63
+
64
+ for (const key in options) {
65
+ attrs[key] = options[key]
66
+ }
67
+
68
+ if (attrs.class && Array.isArray(attrs.class)) {
69
+ attrs.class = attrs.class.join(' ')
70
+ }
71
+
72
+ // 返回HTML标记字符串
73
+ return htmlTag(tag, attrs, decodeURI(text), false)
74
+ })
75
+
76
+ hexo.extend.helper.register('_image_url', function (img, path = '') {
77
+ const { statics } = hexo.theme.config
78
+ const { post_asset_folder } = hexo.config
79
+
80
+ if (img.startsWith('//') || img.startsWith('http')) {
81
+ return img
82
+ } else {
83
+ return url_for.call(this, statics + (post_asset_folder ? path : '') + img)
84
+ }
85
+ })
86
+
87
+ hexo.extend.helper.register('_cover', function (item, num?) {
88
+ const { image_server, image_list } = hexo.theme.config
89
+
90
+ if (item.cover) {
91
+ return this._image_url(item.cover, item.path)
92
+ } else if (item.photos && item.photos.length > 0) {
93
+ return this._image_url(item.photos[0], item.path)
94
+ } else {
95
+ return randomBG(num || 1, image_server, image_list)
96
+ }
97
+ })
98
+
99
+ hexo.extend.helper.register('_cover_index', function (item) {
100
+ const { index_images, image_list, image_server } = hexo.theme.config
101
+
102
+ if (item.cover) {
103
+ return this._image_url(item.cover, item.path)
104
+ } else if (item.photos && item.photos.length > 0) {
105
+ return this._image_url(item.photos[0], item.path)
106
+ } else {
107
+ return randomBG(1, image_server, index_images.length === 0 ? image_list : index_images)
108
+ }
109
+ })
110
+
111
+ // 注册hexo主题的永久链接帮助方法
112
+ hexo.extend.helper.register('_permapath', function (str) {
113
+ // 获取hexo的永久链接配置
114
+ const { permalink } = hexo.config
115
+ // 将输入字符串中的'index.html'替换为空字符串
116
+ let url = str.replace(/index\.html$/, '')
117
+ // 如果永久链接不以'.html'结尾,将输入字符串中的'.html'替换为空字符串
118
+ if (!permalink.endsWith('.html')) {
119
+ url = url.replace(/\.html$/, '')
120
+ }
121
+ // 返回处理后的URL字符串
122
+ return url
123
+ })
124
+
125
+ hexo.extend.helper.register('canonical', function () {
126
+ return `<link rel="canonical" href="${this._permapath(this.url)}">`
127
+ })
128
+
129
+ /**
130
+ * Get page path given a certain language tag
131
+ */
132
+ // 注册hexo主题的国际化路径帮助方法
133
+ hexo.extend.helper.register('i18n_path', function (language) {
134
+ // 获取当前页面的path和lang
135
+ const { path, lang } = this.page
136
+ // 如果path以lang开头,则截取掉lang部分,作为基础路径
137
+ const base = path.startsWith(lang) ? path.slice(lang.length + 1) : path
138
+ // 通过调用url_for方法,生成国际化路径
139
+ return url_for.call(this, `${this.languages.indexOf(language) === 0 ? '' : '/' + language}/${base}`)
140
+ })
141
+
142
+ /**
143
+ * Get the language name
144
+ */
145
+ // 注册hexo主题的语言名称帮助方法
146
+ hexo.extend.helper.register('language_name', function (language) {
147
+ // 从主题配置中获取指定语言的名称
148
+ // @ts-ignore
149
+ const name = hexo.theme.i18n.__(language)('name')
150
+ // 如果名称为默认值'name',则返回语言代码,否则返回语言名称
151
+ return name === 'name' ? language : name
152
+ })
153
+
154
+ hexo.extend.helper.register('random_color', function () {
155
+ const arr:number[] = []
156
+ for (let i = 0; i < 3; i++) {
157
+ arr.push(Math.floor(Math.random() * 128 + 128))
158
+ }
159
+ const [r, g, b] = arr
160
+ return `#${
161
+ r.toString(16).length > 1 ? r.toString(16) : '0' + r.toString(16)
162
+ }${g.toString(16).length > 1 ? g.toString(16) : '0' + g.toString(16)}${
163
+ b.toString(16).length > 1 ? b.toString(16) : '0' + b.toString(16)
164
+ }`
165
+ })
166
+
167
+ hexo.extend.helper.register('shokax_inject', function (point) {
168
+ return hexo.theme.config.injects[point]
169
+ .map(item => this.partial(item.layout, item.locals, item.options))
170
+ .join('')
171
+ })
@@ -0,0 +1 @@
1
+ declare const prepareQuery: (categories: any, parent: any) => any;