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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. package/_config.yml +5 -4
  2. package/languages/README.md +22 -0
  3. package/languages/ar.yml +153 -0
  4. package/languages/de.yml +153 -0
  5. package/languages/es.yml +153 -0
  6. package/languages/fr.yml +153 -0
  7. package/languages/hi.yml +153 -0
  8. package/languages/id.yml +153 -0
  9. package/languages/it.yml +153 -0
  10. package/languages/ko.yml +153 -0
  11. package/languages/nl.yml +153 -0
  12. package/languages/pl.yml +153 -0
  13. package/languages/pt.yml +153 -0
  14. package/languages/ru.yml +153 -0
  15. package/languages/tr.yml +153 -0
  16. package/languages/vi.yml +153 -0
  17. package/layout/_mixin/comment.pug +2 -37
  18. package/layout/_partials/footer.pug +1 -1
  19. package/layout/_partials/head/head.pug +7 -3
  20. package/layout/_partials/header.pug +1 -1
  21. package/layout/_partials/layout.pug +1 -10
  22. package/layout/_partials/post/footer.pug +0 -9
  23. package/package.json +8 -2
  24. package/scripts/generaters/archive.js +1 -1
  25. package/scripts/generaters/script.js +63 -39
  26. package/scripts/helpers/asset.js +3 -72
  27. package/scripts/helpers/list_categories.js +0 -4
  28. package/scripts/plugin/lib/injects.js +1 -1
  29. package/source/js/_app/components/comments.ts +60 -0
  30. package/source/js/_app/components/sidebar.ts +7 -5
  31. package/source/js/_app/components/tcomments.ts +41 -0
  32. package/source/js/_app/globals/globalVars.ts +1 -0
  33. package/source/js/_app/globals/handles.ts +6 -5
  34. package/source/js/_app/globals/themeColor.ts +1 -1
  35. package/source/js/_app/globals/thirdparty.ts +1 -1
  36. package/source/js/_app/globals/tools.ts +3 -2
  37. package/source/js/_app/library/anime.ts +6 -5
  38. package/source/js/_app/library/declare.d.ts +25 -9
  39. package/source/js/_app/library/loadFile.ts +3 -1
  40. package/source/js/_app/library/proto.ts +75 -77
  41. package/source/js/_app/library/vue.ts +38 -48
  42. package/source/js/_app/page/fancybox.ts +2 -1
  43. package/source/js/_app/page/post.ts +4 -3
  44. package/source/js/_app/page/search.ts +17 -11
  45. package/source/js/_app/page/tab.ts +3 -2
  46. package/source/js/_app/pjax/domInit.ts +5 -4
  47. package/source/js/_app/pjax/refresh.ts +20 -2
  48. package/source/js/_app/pjax/siteInit.ts +12 -7
  49. package/source/js/_app/player.ts +16 -15
  50. package/scripts/filters/locals.d.ts +0 -1
  51. package/scripts/filters/locals.ts +0 -59
  52. package/scripts/filters/post.d.ts +0 -0
  53. package/scripts/filters/post.ts +0 -6
  54. package/scripts/generaters/archive.d.ts +0 -1
  55. package/scripts/generaters/archive.ts +0 -144
  56. package/scripts/generaters/config.d.ts +0 -1
  57. package/scripts/generaters/config.ts +0 -52
  58. package/scripts/generaters/images.d.ts +0 -1
  59. package/scripts/generaters/images.ts +0 -26
  60. package/scripts/generaters/index.d.ts +0 -1
  61. package/scripts/generaters/index.ts +0 -110
  62. package/scripts/generaters/pages.d.ts +0 -0
  63. package/scripts/generaters/pages.ts +0 -16
  64. package/scripts/generaters/script.d.ts +0 -1
  65. package/scripts/generaters/script.ts +0 -110
  66. package/scripts/helpers/asset.d.ts +0 -1
  67. package/scripts/helpers/asset.ts +0 -158
  68. package/scripts/helpers/engine.d.ts +0 -1
  69. package/scripts/helpers/engine.ts +0 -171
  70. package/scripts/helpers/list_categories.d.ts +0 -1
  71. package/scripts/helpers/list_categories.ts +0 -104
  72. package/scripts/helpers/summary_ai.d.ts +0 -1
  73. package/scripts/helpers/summary_ai.ts +0 -100
  74. package/scripts/helpers/symbols_count_time.d.ts +0 -1
  75. package/scripts/helpers/symbols_count_time.ts +0 -76
  76. package/scripts/plugin/check.d.ts +0 -1
  77. package/scripts/plugin/check.ts +0 -35
  78. package/scripts/plugin/index.d.ts +0 -6
  79. package/scripts/plugin/index.ts +0 -52
  80. package/scripts/plugin/lib/injects-point.d.ts +0 -5
  81. package/scripts/plugin/lib/injects-point.ts +0 -20
  82. package/scripts/plugin/lib/injects.d.ts +0 -2
  83. package/scripts/plugin/lib/injects.ts +0 -101
  84. package/scripts/tags/links.d.ts +0 -1
  85. package/scripts/tags/links.ts +0 -75
  86. package/scripts/tags/media.d.ts +0 -1
  87. package/scripts/tags/media.ts +0 -19
  88. package/source/assets/beian.webp +0 -0
  89. package/source/js/_app/library/libtype.d.ts +0 -4
@@ -1,171 +0,0 @@
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
- })
@@ -1 +0,0 @@
1
- declare const prepareQuery: (categories: any, parent: any) => any;
@@ -1,104 +0,0 @@
1
- 'use strict'
2
- /* global hexo */
3
-
4
- const prepareQuery = (categories, parent) => {
5
- const query = {
6
- parent: undefined
7
- }
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('_category_prev', function (name) {
66
- // let hexo = this
67
- const categories = this.site.categories
68
- if (!categories || !categories.length) return ''
69
-
70
- let result = ''
71
-
72
- categories.find({ name }).forEach((current) => {
73
- if (current.parent) {
74
- categories.find({ _id: current.parent }).forEach((cat, i) => {
75
- result += `<a href="${this.url_for(cat.path)}">${cat.name}</a>`
76
- })
77
- }
78
- })
79
-
80
- return result
81
- })
82
-
83
- hexo.extend.helper.register('_category_posts', function (page) {
84
- // let hexo = this
85
- const categories = this.site.categories
86
- if (!categories || !categories.length || !page.categories || !page.categories.length) return ''
87
-
88
- let result = ''
89
- const cat = page.categories.toArray()
90
-
91
- categories.find({ _id: cat[cat.length - 1]._id }).forEach((category) => {
92
- if (category.posts) {
93
- category.posts.sort('date', 1).forEach((post) => {
94
- let current = ''
95
- if (post.path === page.path) {
96
- current = ' class="active"'
97
- }
98
- result += `<li ${current}><a href="${this.url_for(post.path)}" rel="bookmark" title="${post.title}">${post.title}</a></li>`
99
- })
100
- }
101
- })
102
-
103
- return result
104
- })
@@ -1 +0,0 @@
1
- export {};
@@ -1,100 +0,0 @@
1
- import fs from 'node:fs'
2
-
3
- function getContent (post) {
4
- return post?.raw ?? post?._content ?? post.content
5
- }
6
-
7
- let db:object
8
- function postMessage (path:string, content:string, dbPath:string, startMessage:string) {
9
- if (fs.existsSync('summary.json')) {
10
- // @ts-ignore
11
- db = JSON.parse(fs.readFileSync('summary.json', { encoding: 'utf-8' }))
12
- } else {
13
- db = {}
14
- }
15
- const config = hexo.theme.config.summary
16
- if (config.enable) {
17
- if (typeof db?.[path] !== 'undefined' && typeof db?.[path]?.[dbPath] !== 'undefined') {
18
- return db[path][dbPath]
19
- } else {
20
- if (typeof db?.[path] === 'undefined') {
21
- db[path] = {}
22
- } else {
23
- db[path][dbPath] = ''
24
- }
25
- }
26
- if (config.mode === 'openai') {
27
- const request = () => {
28
- fetch(`${config.openai.remote}/v1/chat/completions`, {
29
- method: 'POST',
30
- headers: requestHeaders,
31
- body: JSON.stringify(requestBody)
32
- }).then((response) => {
33
- if (!response.ok) {
34
- throw Error('ERROR: Failed to get summary from Openai API')
35
- }
36
- response.json().then((data:object) => {
37
- // @ts-ignore
38
- const summary = data.choices[0].message.content
39
- try {
40
- db[path][dbPath] = summary
41
- } catch (e) {
42
- db ??= {}
43
- db[path] ??= {}
44
- db[path][dbPath] ??= ''
45
- db[path][dbPath] = summary
46
- }
47
- fs.writeFileSync('summary.json', JSON.stringify(db))
48
- if (fs.existsSync('requested.lock')) {
49
- fs.unlinkSync('requested.lock')
50
- }
51
- return summary
52
- })
53
- })
54
- }
55
-
56
- const checkTime = (waitTime:number) => {
57
- if (fs.existsSync('request.lock')) {
58
- if (fs.existsSync('requested.lock')) {
59
- setTimeout(checkTime, 1000 * waitTime)
60
- return
61
- }
62
- // Openai API 针对个人用户免费试用限制 3 RPM,这里是25s后发送请求
63
- fs.writeFileSync('requested.lock', '')
64
- setTimeout(request, 1000 * 2.5 * waitTime)
65
- fs.unlinkSync('request.lock')
66
- } else {
67
- fs.writeFileSync('request.lock', '')
68
- request()
69
- }
70
- }
71
- const requestHeaders = {
72
- 'Content-Type': 'application/json',
73
- Authorization: `Bearer ${config.openai.apikey}`
74
- }
75
- const requestBody = {
76
- model: 'gpt-3.5-turbo',
77
- messages: [{ role: 'user', content: `${startMessage} ${content}` }],
78
- temperature: 0.7
79
- }
80
- if (config.pricing === 'trial') {
81
- hexo.log.info('Requesting OpenAI API... (3 RPM mode)')
82
- hexo.log.info('It may take 20 minutes or more (depending on the number of articles, each one takes 25 seconds)')
83
- checkTime(10)
84
- } else {
85
- hexo.log.info('Requesting OpenAI API... (60 RPM mode)')
86
- checkTime(0.5)
87
- }
88
- } else {
89
- // custom尚未支持
90
- }
91
- }
92
- }
93
-
94
- hexo.extend.helper.register('get_summary', (post) => {
95
- return postMessage(post.path, getContent(post), 'summary', '请为下述文章提供一份200字以内的概括,使用中文回答且尽可能简洁: ')
96
- })
97
-
98
- hexo.extend.helper.register('get_introduce', () => {
99
- return hexo.theme.config.summary.introduce
100
- })
@@ -1 +0,0 @@
1
- export {};
@@ -1,76 +0,0 @@
1
- 'use strict'
2
- /* global hexo */
3
- /*!
4
- hexo-symbols-count-time by theme-next
5
- under GNU Lesser General Public License v3.0 or later
6
- https://github.com/theme-next/hexo-symbols-count-time/blob/master/LICENSE
7
- */
8
-
9
- import { stripHTML } from 'hexo-util'
10
-
11
- const config = hexo.config.symbols_count_time = Object.assign({
12
- symbols: true,
13
- time: true,
14
- total_symbols: true,
15
- total_time: true,
16
- exclude_codeblock: false,
17
- awl: 4,
18
- wpm: 275,
19
- suffix: 'mins.'
20
- }, hexo.config.symbols_count_time)
21
-
22
- function getSymbols (post) {
23
- return post?._content?.length ?? post?.content?.length ?? post.length
24
- }
25
-
26
- function getSymbolsTotal (site) {
27
- let symbolsResultCount = 0
28
- site.posts.forEach((post) => {
29
- symbolsResultCount += getSymbols(post)
30
- })
31
- return symbolsResultCount
32
- }
33
-
34
- function getFormatTime (minutes, suffix) {
35
- const fHours = Math.floor(minutes / 60)
36
- let fMinutes = Math.floor(minutes - (fHours * 60))
37
- if (fMinutes < 1) {
38
- fMinutes = 1 // 0 => 1
39
- }
40
- return fHours < 1
41
- ? fMinutes + ' ' + suffix // < 59 => 59 mins.
42
- : fHours + ':' + ('00' + fMinutes).slice(-2) // = 61 => 1:01
43
- }
44
-
45
- hexo.extend.helper.register('symbolsCount', function (post) {
46
- let symbolsResult = getSymbols(post)
47
- if (symbolsResult > 9999) {
48
- symbolsResult = Math.round(symbolsResult / 1000) + 'k' // > 9999 => 11k
49
- } else if (symbolsResult > 999) {
50
- symbolsResult = Math.round(symbolsResult / 100) / 10 + 'k' // > 999 => 1.1k
51
- } // < 999 => 111
52
- return symbolsResult
53
- })
54
-
55
- hexo.extend.helper.register('symbolsTime', function (post, awl = config.awl, wpm = config.wpm, suffix = config.suffix) {
56
- const minutes = Math.round(getSymbols(post) / (awl * wpm))
57
- return getFormatTime(minutes, suffix)
58
- })
59
-
60
- hexo.extend.helper.register('symbolsCountTotal', function (site) {
61
- const symbolsResultTotal = getSymbolsTotal(site)
62
- return symbolsResultTotal < 1000000
63
- ? Math.round(symbolsResultTotal / 1000) + 'k' // < 999k => 111k
64
- : Math.round(symbolsResultTotal / 100000) / 10 + 'm' // > 999k => 1.1m
65
- })
66
-
67
- hexo.extend.helper.register('symbolsTimeTotal', function (site, awl = config.awl, wpm = config.wpm, suffix = config.suffix) {
68
- const minutes = Math.round(getSymbolsTotal(site) / (awl * wpm))
69
- return getFormatTime(minutes, suffix)
70
- })
71
-
72
- hexo.extend.filter.register('after_post_render', (data) => {
73
- let { content } = data
74
- if (config.exclude_codeblock) content = content.replace(/<pre>.*?<\/pre>/g, '')
75
- data.length = stripHTML(content).replace(/\r?\n|\r/g, '').replace(/\s+/g, '').length
76
- }, 0)
@@ -1 +0,0 @@
1
- declare let findProblem: boolean;
@@ -1,35 +0,0 @@
1
- /* global hexo */
2
-
3
- let findProblem = false
4
-
5
- hexo.on('generateBefore', function () {
6
- if (hexo.config.syntax_highlighter) {
7
- findProblem = true
8
- hexo.log.error('[SXEC 101] Highlight.js or Prismjs enabled. The code block will render incomplete')
9
- }
10
- if (!hexo.config.markdown) {
11
- findProblem = true
12
- hexo.log.error(`[SXEC 102] Critical rendering plugins are missing or incorrectly configured.
13
- Some features will be disabled or render incorrectly`)
14
- }
15
- if (parseInt(process.version.match(/\d{2,3}/)[0]) < 18) {
16
- findProblem = true
17
- hexo.log.error('[SXEC 103] Too old Node.js version, install the latest LTS version')
18
- }
19
- if (!hexo.config.title || !hexo.config.description || !hexo.config.language || !hexo.config.timezone || !hexo.config.url) {
20
- findProblem = true
21
- hexo.log.warn('[SXEC 201] Essential information(title, desc, lang, etc) config incorrectly, Page will render incorrectly')
22
- }
23
- if (hexo.theme.config.gitalk?.clientID || hexo.theme.config.giscus?.repo) {
24
- findProblem = true
25
- hexo.log.warn('[SXEC 202] You are using an deprecated feature and it was removed in the v0.3.10')
26
- }
27
- })
28
-
29
- hexo.on('generateAfter', function () {
30
- if (findProblem) {
31
- hexo.log.warn(`The environment check found some problems that can lead to rendering errors, effect errors,
32
- performance degradation, not working correctly, etc`)
33
- hexo.log.warn('ShokaX has output them into console, read them to get more information. You can search error code in docs(For example, SXEC 101)')
34
- }
35
- })
@@ -1,6 +0,0 @@
1
- /*!
2
- index.js in next-theme/hexo-theme-next by next-theme
3
- under GNU AFFERO GENERAL PUBLIC LICENSE v3.0 OR LATER
4
- https://github.com/next-theme/hexo-theme-next/blob/master/LICENSE.md
5
- */
6
- export {};
@@ -1,52 +0,0 @@
1
- /*!
2
- index.js in next-theme/hexo-theme-next by next-theme
3
- under GNU AFFERO GENERAL PUBLIC LICENSE v3.0 OR LATER
4
- https://github.com/next-theme/hexo-theme-next/blob/master/LICENSE.md
5
- */
6
-
7
- import injects from './lib/injects'
8
- import { version } from '../../package.json'
9
- import * as fs from 'node:fs'
10
-
11
- hexo.on('generateBefore', () => {
12
- // 加载`theme_injects`过滤器
13
- injects(hexo)
14
- if (fs.existsSync('request.lock')) {
15
- fs.unlinkSync('request.lock')
16
- }
17
- if (fs.existsSync('requested.lock')) {
18
- fs.unlinkSync('requested.lock')
19
- }
20
- })
21
-
22
- hexo.on('generateAfter', () => {
23
- // 检查版本更新
24
- fetch('https://api.github.com/repos/theme-shoka-x/hexo-theme-shokaX/releases/latest').then((res) => {
25
- res.json().then((resp) => {
26
- try {
27
- const latest = resp.tag_name.replace('v', '').split('.')
28
- const current = version.split('.')
29
- let isOutdated = false
30
- for (let i = 0; i < Math.max(latest.length, current.length); i++) {
31
- if (!current[i] || latest[i] > current[i]) {
32
- isOutdated = true
33
- break
34
- }
35
- if (latest[i] < current[i]) {
36
- break
37
- }
38
- }
39
- if (isOutdated) {
40
- hexo.log.warn(`Your theme ShokaX is outdated. Current version: v${current.join('.')}, latest version: v${latest.join('.')}`)
41
- hexo.log.warn('Visit https://github.com/theme-shoka-x/hexo-theme-shokaX/releases for more information.')
42
- }
43
- } catch (e) {
44
- hexo.log.warn('Failed to detect version info. Error message:')
45
- hexo.log.warn(e)
46
- }
47
- }).catch((e) => {
48
- hexo.log.warn('Failed to detect version info. Error message:')
49
- hexo.log.warn(e)
50
- })
51
- })
52
- })
@@ -1,5 +0,0 @@
1
- declare const _default: {
2
- views: string[];
3
- styles: string[];
4
- };
5
- export default _default;
@@ -1,20 +0,0 @@
1
- 'use strict'
2
-
3
- export default {
4
- views: [
5
- 'head',
6
- 'sidebar',
7
- 'rightNav',
8
- 'postMeta',
9
- 'postBodyEnd',
10
- 'footer',
11
- 'bodyEnd',
12
- 'comment',
13
- 'status'
14
- ],
15
- styles: [
16
- 'variable',
17
- 'mixin',
18
- 'style'
19
- ]
20
- }
@@ -1,2 +0,0 @@
1
- declare const _default: (hexo: any) => void;
2
- export default _default;
@@ -1,101 +0,0 @@
1
- 'use strict'
2
-
3
- /*!
4
- inject.js in next-theme/hexo-theme-next by next-theme
5
- under GNU AFFERO GENERAL PUBLIC LICENSE v3.0 OR LATER
6
- https://github.com/next-theme/hexo-theme-next/blob/master/LICENSE.md
7
- */
8
- import fs from 'node:fs'
9
- import path from 'node:path'
10
- import points from './injects-point'
11
- const defaultExtname = '.pug'
12
-
13
- interface viewConfig {
14
- layout: string,
15
- locals: object,
16
- options: object,
17
- order: number
18
- }
19
- class StylusInject {
20
- files: Array<string>
21
- base_dir: string
22
- constructor (base_dir) {
23
- this.base_dir = base_dir
24
- this.files = []
25
- }
26
-
27
- push (file) {
28
- this.files.push(path.resolve(this.base_dir, file))
29
- }
30
- }
31
-
32
- // Defining view types
33
- class ViewInject {
34
- base_dir:string
35
- raws: Array<object>
36
- constructor (base_dir) {
37
- this.base_dir = base_dir
38
- this.raws = []
39
- }
40
-
41
- raw (name, raw, ...args) {
42
- // Set default extname
43
- if (path.extname(name) === '') {
44
- name += defaultExtname
45
- }
46
- this.raws.push({ name, raw, args })
47
- }
48
-
49
- file (name, file, ...args) {
50
- // Set default extname from file's extname
51
- if (path.extname(name) === '') {
52
- name += path.extname(file)
53
- }
54
- // Get absolute path base on hexo dir
55
- this.raw(name, fs.readFileSync(path.resolve(this.base_dir, file), 'utf8'), ...args)
56
- }
57
- }
58
-
59
- // Init injects
60
- function initInject (base_dir) {
61
- const injects = {}
62
- points.styles.forEach(item => {
63
- injects[item] = new StylusInject(base_dir)
64
- })
65
- points.views.forEach(item => {
66
- injects[item] = new ViewInject(base_dir)
67
- })
68
- return injects
69
- }
70
-
71
- export default (hexo) => {
72
- // Exec theme_inject filter
73
- const injects = initInject(hexo.base_dir)
74
- hexo.execFilterSync('theme_inject', injects)
75
- hexo.theme.config.injects = {}
76
-
77
- // Inject stylus
78
- points.styles.forEach(type => {
79
- hexo.theme.config.injects[type] = injects[type].files
80
- })
81
-
82
- // Inject views
83
- points.views.forEach(type => {
84
- const configs = Object.create(null)
85
- hexo.theme.config.injects[type] = []
86
- // Add or override view.
87
- injects[type].raws.forEach((injectObj, index) => {
88
- const name = `inject/${type}/${injectObj.name}`
89
- hexo.theme.setView(name, injectObj.raw)
90
- configs[name] = {
91
- layout: name,
92
- locals: injectObj.args[0],
93
- options: injectObj.args[1],
94
- order: injectObj.args[2] || index
95
- }
96
- })
97
- // Views sort.
98
- hexo.theme.config.injects[type] = Object.values(configs)
99
- .sort((x:viewConfig, y:viewConfig) => x.order - y.order)
100
- })
101
- }