hexo-theme-shokax 0.0.1-alpha5 → 0.0.2-alpha1

Sign up to get free protection for your applications and to get access to all the features.
package/LICENSE CHANGED
@@ -1,21 +1,28 @@
1
- MIT License
1
+ BSD 3-Clause License
2
2
 
3
- Copyright (c) 2022 zkz098
3
+ Copyright (c) 2022, zkz098
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
11
7
 
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
14
10
 
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -17,8 +17,7 @@
17
17
  - [x] 注入js和css支持
18
18
  - [x] 自定义font
19
19
  - [x] 部分功能调整为可关闭
20
- - [ ] 重构lib方法(长期计划)
21
- - [ ] 异步化js
20
+ - [ ] 插件系统
22
21
 
23
22
  ## 和shoka的区别
24
23
  原先shoka使用了javascript+Native+nunjucks的技术 \
@@ -35,7 +34,8 @@ SXC install shokaX
35
34
  ```
36
35
 
37
36
  # 许可证
38
- 许可证: MIT \
37
+ 许可证: BSD-3-Clause \
38
+ 请注意: `0.0.1-alpha6`版本开始,shokaX使用BSD协议,这意味着删除页脚处的shokaX标识是违反许可证的
39
39
  [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fzkz098%2Fhexo-theme-shokaX.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fzkz098%2Fhexo-theme-shokaX?ref=badge_large)
40
40
 
41
41
  # 致谢名单
package/_config.yml CHANGED
@@ -47,11 +47,6 @@ auto_dark: # 自动亮/暗模式
47
47
  start: 20 #开始时间
48
48
  end: 7 #结束时间
49
49
 
50
- plugin:
51
- enable: false
52
- load:
53
- # - example
54
-
55
50
  auto_scroll: true
56
51
 
57
52
  loader:
@@ -1,4 +1,5 @@
1
1
  mixin CommentRender()
2
+ != shokax_inject('comment')
2
3
  - var tk = theme?.twikoo?.enable,wl = theme?.waline?.enable
3
4
  if page.comment !== false
4
5
  if tk
@@ -8,3 +9,4 @@ mixin CommentRender()
8
9
  div(class="warp" id="wcomments")
9
10
  != _init_comments("waline")
10
11
 
12
+
@@ -36,5 +36,5 @@ div(class="status")
36
36
  img(src=theme.statics + theme.assets + '/' + theme.footer.icp.icon style="max-width: 2em;display:inline;")
37
37
  != beianN
38
38
 
39
- != insert_footer()
39
+ != shokax_inject('footer')
40
40
 
@@ -14,6 +14,7 @@ nav(id="nav")
14
14
  i(class="ic" :class="{'i-sun': !themeStatus,'i-moon': themeStatus}")
15
15
  li(class="item search")
16
16
  i(class="ic i-search")
17
+ != shokax_inject('rightNav')
17
18
  li(class="item weather")
18
19
  div(id="he-plugin-simple")
19
20
 
@@ -7,6 +7,7 @@ html(lang=page.language?page.language:config.language, style=theme.grayMode ? 'f
7
7
  head
8
8
  != partial('_partials/head/head.pug', {}, {cache: true})
9
9
  != partial('_partials/head/head_com.pug')
10
+ != shokax_inject('head')
10
11
  title
11
12
  block title
12
13
  != `${alternate?alternate + " = ":""}${title}${subtitle?" = "+subtitle:""}`
@@ -133,10 +134,11 @@ html(lang=page.language?page.language:config.language, style=theme.grayMode ? 'f
133
134
  != _vendor_js()
134
135
  != _js('app.js')
135
136
  != partial('_partials/third-party/baidu-analytics.pug', {}, {cache: true})
136
- != partial('_partials/third-party/qweather.pug', {}, {cache: true})
137
+ if theme.qweather.enable
138
+ != partial('_partials/third-party/qweather.pug', {}, {cache: true})
137
139
  != partial('_partials/third-party/clarity.pug', {}, {cache: true})
138
140
  != _new_comments('twikoo')
139
- if theme.qweather.enable
141
+
140
142
 
141
143
  - var jsInjects = theme?.inject?.body?.js,cssInjects = theme?.inject?.body?.css
142
144
  if cssInjects
@@ -145,5 +147,7 @@ html(lang=page.language?page.language:config.language, style=theme.grayMode ? 'f
145
147
  if jsInjects
146
148
  != js(jsInjects)
147
149
 
150
+ != shokax_inject('bodyEnd')
151
+
148
152
 
149
153
 
@@ -11,3 +11,4 @@ div(class="meta")
11
11
  != __('post.edited')
12
12
  time(title=__('post.modified') + __('symbol.colon') + full_date(post.updated) itemprop="dateModified" datetime=moment(post.updated).format())
13
13
  != date(post.updated)
14
+ != shokax_inject('postMeta')
@@ -24,3 +24,4 @@ article(itemscope itemtype="http://schema.org/Article" class="post block" lang="
24
24
  != partial('_partials/post/reward.pug', {}, {cache: true})
25
25
  if theme.creative_commons.license
26
26
  != partial('_partials/post/copyright.pug')
27
+ != shokax_inject('postBodyEnd')
@@ -35,6 +35,8 @@ div(class="social")
35
35
  - var sidebarIcon = '<i class="ic i-' + link.split('||')[1].trim() + '"></i>'
36
36
  != _url(sidebarURL, sidebarIcon, {title: sidebarURL, class: 'item ' + name})
37
37
 
38
+ != shokax_inject('sidebar')
39
+
38
40
  div(class="menu")
39
41
  //!= partial('_partials/sidebar/menu.pug', {}, {cache: true})
40
42
  != partial('_partials/sidebar/menu.pug')
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "hexo-theme-shokax",
3
- "version": "0.0.1-alpha5",
3
+ "version": "0.0.2-alpha1",
4
4
  "description": "a hexo theme based on shoka",
5
5
  "main": "index.js",
6
6
  "repository": "https://github.com/zkz098/hexo-theme-shokaX",
7
7
  "author": "Chou kaitaku",
8
- "license": "MIT",
8
+ "license": "BSD-3-Clause",
9
9
  "scripts": {
10
10
  "test": "cd ./source/js && tsc"
11
11
  },
@@ -182,3 +182,9 @@ hexo.extend.helper.register('random_color', function () {
182
182
  b.toString(16).length > 1 ? b.toString(16) : '0' + b.toString(16)
183
183
  }`
184
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,58 +1,6 @@
1
1
  /* global hexo */
2
- 'use strict'
3
2
 
4
- /** @type {Map<string, string[]>} */
5
- const insertions = new Map()
6
- class TemplateBlock {
7
- constructor (text, type = 'raw') {
8
- this.text = text
9
- this.type = type
10
- this.result = ''
11
- }
12
-
13
- render () {
14
- if (this.type === 'raw' || this.type === 'html') {
15
- this.result = this.text
16
- }
17
- this.result = hexo.render.renderSync({ text: this.text, engine: this.type })
18
- }
19
-
20
- repalceTag (...tag) {
21
- tag.forEach((item) => {
22
- this.text = this.text.replace(item.tag, item.value)
23
- })
24
- }
25
-
26
- insert (location) {
27
- if (insertions.get(location)) {
28
- insertions.get(location).push(this.result)
29
- } else {
30
- insertions.set(location, [])
31
- }
32
- }
33
- }
34
-
35
- const toolpack = {
36
- TemplateBlock
37
- }
38
-
39
- hexo.extend.helper.register('insert_footer', () => {
40
- if (hexo.theme.config?.plugin?.enable && insertions.get('footer')) {
41
- let res = ''
42
- insertions.get('footer').forEach((item) => {
43
- res += item
44
- })
45
- return res
46
- }
3
+ hexo.on('generateBefore', () => {
4
+ // 加载`theme_injects`过滤器
5
+ require('./lib/injects')(hexo)
47
6
  })
48
-
49
- if (hexo.theme.config?.plugin?.enable) {
50
- hexo.theme.config.plugin.load.forEach((item) => {
51
- const p = require(item)
52
- console.log(p)
53
- if (p.prepare) {
54
- p.prepare(hexo, this)
55
- }
56
- p.main(hexo, this, toolpack)
57
- })
58
- }
@@ -0,0 +1,19 @@
1
+ 'use strict'
2
+
3
+ module.exports = {
4
+ views: [
5
+ 'head',
6
+ 'sidebar',
7
+ 'rightNav',
8
+ 'postMeta',
9
+ 'postBodyEnd',
10
+ 'footer',
11
+ 'bodyEnd',
12
+ 'comment'
13
+ ],
14
+ styles: [
15
+ 'variable',
16
+ 'mixin',
17
+ 'style'
18
+ ]
19
+ }
@@ -0,0 +1,88 @@
1
+ 'use strict'
2
+
3
+ const fs = require('fs')
4
+ const path = require('path')
5
+ const points = require('./injects-point')
6
+ const defaultExtname = '.pug'
7
+
8
+ // Defining stylus types
9
+ class StylusInject {
10
+ constructor (base_dir) {
11
+ this.base_dir = base_dir
12
+ this.files = []
13
+ }
14
+
15
+ push (file) {
16
+ // Get absolute path base on hexo dir
17
+ this.files.push(path.resolve(this.base_dir, file))
18
+ }
19
+ }
20
+
21
+ // Defining view types
22
+ class ViewInject {
23
+ constructor (base_dir) {
24
+ this.base_dir = base_dir
25
+ this.raws = []
26
+ }
27
+
28
+ raw (name, raw, ...args) {
29
+ // Set default extname
30
+ if (path.extname(name) === '') {
31
+ name += defaultExtname
32
+ }
33
+ this.raws.push({ name, raw, args })
34
+ }
35
+
36
+ file (name, file, ...args) {
37
+ // Set default extname from file's extname
38
+ if (path.extname(name) === '') {
39
+ name += path.extname(file)
40
+ }
41
+ // Get absolute path base on hexo dir
42
+ this.raw(name, fs.readFileSync(path.resolve(this.base_dir, file), 'utf8'), ...args)
43
+ }
44
+ }
45
+
46
+ // Init injects
47
+ function initInject (base_dir) {
48
+ const injects = {}
49
+ points.styles.forEach(item => {
50
+ injects[item] = new StylusInject(base_dir)
51
+ })
52
+ points.views.forEach(item => {
53
+ injects[item] = new ViewInject(base_dir)
54
+ })
55
+ return injects
56
+ }
57
+
58
+ module.exports = (hexo) => {
59
+ // Exec theme_inject filter
60
+ const injects = initInject(hexo.base_dir)
61
+ hexo.execFilterSync('theme_inject', injects)
62
+ hexo.theme.config.injects = {}
63
+
64
+ // Inject stylus
65
+ points.styles.forEach(type => {
66
+ hexo.theme.config.injects[type] = injects[type].files
67
+ })
68
+
69
+ // Inject views
70
+ points.views.forEach(type => {
71
+ const configs = Object.create(null)
72
+ hexo.theme.config.injects[type] = []
73
+ // Add or override view.
74
+ injects[type].raws.forEach((injectObj, index) => {
75
+ const name = `inject/${type}/${injectObj.name}`
76
+ hexo.theme.setView(name, injectObj.raw)
77
+ configs[name] = {
78
+ layout: name,
79
+ locals: injectObj.args[0],
80
+ options: injectObj.args[1],
81
+ order: injectObj.args[2] || index
82
+ }
83
+ })
84
+ // Views sort.
85
+ hexo.theme.config.injects[type] = Object.values(configs)
86
+ .sort((x, y) => x.order - y.order)
87
+ })
88
+ }
@@ -1,7 +1,13 @@
1
1
  @import "_variables";
2
2
 
3
+ for $inject_variable in hexo-config('injects.variable')
4
+ @import $inject_variable;
5
+
3
6
  @import "_mixins";
4
7
 
8
+ for $inject_mixin in hexo-config('injects.mixin')
9
+ @import $inject_mixin;
10
+
5
11
  if $colors = hexo-config('style.colors')
6
12
  @import $colors;
7
13
  else
@@ -25,3 +31,8 @@ if $custom = hexo-config('style.custom')
25
31
  @import $custom;
26
32
 
27
33
  @import "plugin.styl"
34
+
35
+ for $inject_style in hexo-config('injects.style')
36
+ @import $inject_style;
37
+
38
+