hexo-adsense 1.0.21 → 1.0.25

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.
Files changed (99) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +20 -6
  3. package/lib/index.js +8 -1
  4. package/lib/source/adblock.css +2 -83
  5. package/lib/source/adblock.js +1 -31
  6. package/lib/source/article-ads.css +2 -11
  7. package/lib/source/article-ads.js +1 -270
  8. package/lib/source/blogger-redirect.html +1 -14
  9. package/lib/source/https.js +1 -4
  10. package/lib/src/article-ads.d.ts +1 -1
  11. package/lib/src/article-ads.js +6 -6
  12. package/lib/src/config.d.ts +12 -19
  13. package/lib/src/config.js +3 -5
  14. package/lib/src/utils.d.ts +9 -1
  15. package/lib/src/utils.js +2 -2
  16. package/package.json +20 -5
  17. package/packages/hexo-cli-extras/.eslintrc +13 -0
  18. package/packages/hexo-cli-extras/LICENSE.md +20 -0
  19. package/packages/hexo-cli-extras/README.md +146 -0
  20. package/packages/hexo-cli-extras/docs/basic.gif +0 -0
  21. package/packages/hexo-cli-extras/docs/gui.gif +0 -0
  22. package/packages/hexo-cli-extras/docs/remove.png +0 -0
  23. package/packages/hexo-cli-extras/docs/rename.png +0 -0
  24. package/packages/hexo-cli-extras/index.js +48 -0
  25. package/packages/hexo-cli-extras/lib/edit.js +209 -0
  26. package/packages/hexo-cli-extras/lib/env.js +52 -0
  27. package/packages/hexo-cli-extras/lib/extensions.js +23 -0
  28. package/packages/hexo-cli-extras/lib/integrate.js +87 -0
  29. package/packages/hexo-cli-extras/lib/isolate.js +179 -0
  30. package/packages/hexo-cli-extras/lib/remove.js +145 -0
  31. package/packages/hexo-cli-extras/lib/rename.js +171 -0
  32. package/packages/hexo-cli-extras/package.json +34 -0
  33. package/packages/hexo-extend-injector2/.eslintrc +4 -0
  34. package/packages/hexo-extend-injector2/.github/workflows/linter.yml +27 -0
  35. package/packages/hexo-extend-injector2/.github/workflows/tester.yml +24 -0
  36. package/packages/hexo-extend-injector2/.vscode/settings.json +10 -0
  37. package/packages/hexo-extend-injector2/LICENSE +165 -0
  38. package/packages/hexo-extend-injector2/README-ZH.md +189 -0
  39. package/packages/hexo-extend-injector2/README.md +191 -0
  40. package/packages/hexo-extend-injector2/USAGE.md +38 -0
  41. package/packages/hexo-extend-injector2/index.js +13 -0
  42. package/packages/hexo-extend-injector2/lib/bundle/css-bundle.js +79 -0
  43. package/packages/hexo-extend-injector2/lib/bundle/css-generator.js +13 -0
  44. package/packages/hexo-extend-injector2/lib/bundle/handle-data-pre.js +29 -0
  45. package/packages/hexo-extend-injector2/lib/bundle/js-bundle.js +42 -0
  46. package/packages/hexo-extend-injector2/lib/bundle/js-generator.js +10 -0
  47. package/packages/hexo-extend-injector2/lib/default-config.js +52 -0
  48. package/packages/hexo-extend-injector2/lib/filter.js +24 -0
  49. package/packages/hexo-extend-injector2/lib/helper/injector.js +6 -0
  50. package/packages/hexo-extend-injector2/lib/helper/next-inject.js +14 -0
  51. package/packages/hexo-extend-injector2/lib/injector.js +128 -0
  52. package/packages/hexo-extend-injector2/lib/load.js +45 -0
  53. package/packages/hexo-extend-injector2/lib/next-point.js +19 -0
  54. package/packages/hexo-extend-injector2/lib/next.js +87 -0
  55. package/packages/hexo-extend-injector2/lib/order.js +9 -0
  56. package/packages/hexo-extend-injector2/package.json +49 -0
  57. package/packages/hexo-extend-injector2/renovate.json +6 -0
  58. package/packages/hexo-extend-injector2/test/.eslintrc +3 -0
  59. package/packages/hexo-extend-injector2/test/index.js +18 -0
  60. package/packages/hexo-extend-injector2/test/lib/bundle/bundle-css.js +86 -0
  61. package/packages/hexo-extend-injector2/test/lib/bundle/bundle-js.js +36 -0
  62. package/packages/hexo-extend-injector2/test/lib/bundle/test.css +3 -0
  63. package/packages/hexo-extend-injector2/test/lib/bundle/test.js +5 -0
  64. package/packages/hexo-extend-injector2/test/lib/helper/injector.js +45 -0
  65. package/packages/hexo-extend-injector2/test/lib/helper/next-inject.js +69 -0
  66. package/packages/hexo-extend-injector2/test/lib/hexo-compatible.js +250 -0
  67. package/packages/hexo-extend-injector2/test/lib/hexo-injector.js +37 -0
  68. package/packages/hexo-extend-injector2/test/lib/injector.js +93 -0
  69. package/packages/memoize/CHANGELOG.md +82 -0
  70. package/packages/memoize/CHANGES +124 -0
  71. package/packages/memoize/LICENSE +15 -0
  72. package/packages/memoize/README.md +503 -0
  73. package/packages/memoize/ext/async.js +154 -0
  74. package/packages/memoize/ext/dispose.js +33 -0
  75. package/packages/memoize/ext/max-age.js +90 -0
  76. package/packages/memoize/ext/max.js +27 -0
  77. package/packages/memoize/ext/promise.js +147 -0
  78. package/packages/memoize/ext/ref-counter.js +48 -0
  79. package/packages/memoize/index.js +34 -0
  80. package/packages/memoize/lib/configure-map.js +182 -0
  81. package/packages/memoize/lib/methods.js +32 -0
  82. package/packages/memoize/lib/registered-extensions.js +1 -0
  83. package/packages/memoize/lib/resolve-length.js +15 -0
  84. package/packages/memoize/lib/resolve-normalize.js +17 -0
  85. package/packages/memoize/lib/resolve-resolve.js +21 -0
  86. package/packages/memoize/lib/weak.js +134 -0
  87. package/packages/memoize/methods-plain.js +3 -0
  88. package/packages/memoize/methods.js +3 -0
  89. package/packages/memoize/normalizers/get-1.js +29 -0
  90. package/packages/memoize/normalizers/get-fixed.js +71 -0
  91. package/packages/memoize/normalizers/get-primitive-fixed.js +16 -0
  92. package/packages/memoize/normalizers/get.js +90 -0
  93. package/packages/memoize/normalizers/primitive.js +9 -0
  94. package/packages/memoize/package.json +60 -0
  95. package/packages/memoize/plain.js +37 -0
  96. package/packages/memoize/profile.js +107 -0
  97. package/packages/memoize/repository.md +1 -0
  98. package/packages/memoize/weak-plain.js +3 -0
  99. package/packages/memoize/weak.js +3 -0
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,189 @@
1
+ # hexo-extend-injector2
2
+
3
+ 为插件或者主题提供扩展,能将代码注入到指定位置(如果主题提供相应的注入点)
4
+
5
+ ![npm](https://img.shields.io/npm/v/hexo-extend-injector2.svg)
6
+
7
+ 这个插件的功能借鉴了原生injector的设计,但由于其无法兼容原本的NexT插件方案,重新设计以提供更多扩展能力,详细见[这个PR](https://github.com/jiangtj/hexo-theme-cake/pull/39)
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ yarn add hexo-extend-injector2
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ 首先,你需要获取injector实例通过require,下面的API中injector都是这样获取
18
+
19
+ ```js
20
+ const injector = require('hexo-extend-injector2')(hexo);
21
+ ```
22
+
23
+ ### 注册
24
+
25
+ injector 有两种注册的写法
26
+
27
+ ```js
28
+ injector.register(entry, value, predicate, priority, isRun);
29
+ injector.register(entry, {
30
+ value: value,
31
+ predicate: predicate,
32
+ priority: priority,
33
+ isRun: true/false
34
+ });
35
+ ```
36
+
37
+ #### 参数
38
+
39
+ | 属性名 | 类型 | 描述 | 默认值 |
40
+ | :----- | :----- | :----- | :----- |
41
+ | entry | String | 注入点,它忽略大小写以及` ` `-` `_`,即 'bodybegin' = 'bodyBegin' = 'body-begin' = 'body_begin' | - |
42
+ | value | String/Function | 注入的内容,如果是函数,会传递上下文及配置参数 | - |
43
+ | predicate | String/Function | 生效条件,详见例子 | `() => true` |
44
+ | priority | Number | 优先级 | 10 |
45
+ | isRun | Boolean | 特别定义的参数,hexo部分内容在文件更改之后重新加载,重新加载时会清空isRun为true的内容,避免重复加载 | false |
46
+
47
+
48
+ #### 例子
49
+
50
+ 1. 最简单的使用,在你的站点的head中添加fontawesome css,下面三种写法是等效的
51
+ ```js
52
+ injector.register('head-end', '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.11.2/css/all.min.css" crossorigin="anonymous">');
53
+ injector.register('head-end', () => '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.11.2/css/all.min.css" crossorigin="anonymous">');
54
+ injector.register('head-end', {
55
+ value: '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.11.2/css/all.min.css" crossorigin="anonymous">'
56
+ });
57
+ ```
58
+
59
+ 2. Predicate的使用
60
+ ```js
61
+ // 当你需要在特定的页面注入内容时,需要用到Predicate,分为两种写法
62
+
63
+ // 与官方一样的,指定布局类型,如下,将在特定的music布局中添加APlayer
64
+ injector.register('head_end', () => {
65
+ return css('https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.css');
66
+ }, 'music');
67
+ injector.register('body_end', '<script src="https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.js">', 'music');
68
+ // 等价于 使用了 injector.is('home', 'category', ...),可以传递多个布局,同时生效
69
+ injector.register('body_end', '<script src="https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.js">', injector.is('music'));
70
+
71
+ // 依据上下文或者配置选项判断
72
+ injector.register('head-end', {
73
+ predicate: (ctx, options) => {
74
+ // ctx 在不同情况下,传入的值可能不同,options 在 injector.get() 时传入
75
+ return ctx.page['music'];
76
+ },
77
+ value: () => {
78
+ return css('https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.css');
79
+ }
80
+ });
81
+ ```
82
+
83
+ ### 获取
84
+
85
+ 默认情况下,只提供四个注入点 `head-begin` `head-end` `body-begin` `body-end`,你可以设置`disable_injector2_default_point`为true禁用
86
+
87
+ 其他情况,需要开发者提供JS API或者Hexo Helper两种途径获取存储在injector的内容,自行处理它
88
+
89
+ #### API
90
+
91
+ ```js
92
+ const result = injector.get(entry, options);
93
+ ```
94
+
95
+ - result.list(): 获取该注入点的所有注入对象
96
+ - result.rendered(): 获取并渲染该注入点的所有注入对象(如果value是函数,将执行转化为String)
97
+ - result.text(): 将该注入点的所有注入内容渲染拼接后返回
98
+
99
+ 例子
100
+
101
+ ```js
102
+ // 在bundler中,通过添加env来判断是否是需要的css内容
103
+ injector.get('css', {env: 'dark'});
104
+ // 覆盖默认的ctx
105
+ injector.get('point', {context: this});
106
+ ```
107
+
108
+ #### Helper
109
+
110
+ injector helper 与 injector.get() 十分相似,但context替换为了hexo的本地变量
111
+
112
+ ```ejs
113
+ <!DOCTYPE html>
114
+ <html>
115
+ <head>
116
+ <%- injector('head-begin').text() -%>
117
+ ...
118
+ <%- injector('head-end').text() -%>
119
+ </head>
120
+ <body>
121
+ <%- injector('body-begin').text() -%>
122
+ ...
123
+ <%- injector('body-end').text() -%>
124
+ </body>
125
+ </html>
126
+ ```
127
+
128
+ ### bundler
129
+
130
+ 该插件提供了js与css的bundler,你可以很方便的将js与css添加至主题中
131
+
132
+ #### config
133
+
134
+ 下面是bundler的默认配置
135
+
136
+ ```yml
137
+ injector2:
138
+ js:
139
+ enable: true
140
+ path: js/injector.js
141
+ options: {}
142
+ css:
143
+ enable: true
144
+ path:
145
+ default:
146
+ # 在 head 中添加 <link rel="stylesheet" type="text/css" href="${url_for(file.path)}" />
147
+ link: load
148
+ path: css/injector/main.css
149
+ dark:
150
+ # 在 head 中添加 <link rel="preload" as="style" href="${url_for(file.path)}" />
151
+ link: preload
152
+ path: css/injector/dark.css
153
+ light:
154
+ link: preload
155
+ path: css/injector/light.css
156
+ options: {}
157
+ ```
158
+
159
+ #### API/Example
160
+
161
+ ```js
162
+ injector.register('js or css', 'content');
163
+
164
+ // Example
165
+ injector.register('js', 'function log1() {console.log("bar");}');
166
+ injector.register('css', '.book{font-size:2rem}');
167
+
168
+ // CSS spec
169
+ // 额外添加了env的选择,如果env不同,那么会打包到不同的css文件下
170
+ // 你需要提前进行配置,默认情况下配置了default、dark和light,如果不设置为default
171
+ injector.register('css', {value: '.book{font-size:2rem}', env: 'dark'});
172
+
173
+ // CSS 别名
174
+ injector.register('variable', 'css content');
175
+ //=> injector.register('css', {value: 'css content', priority: injector.order.REGISTER_VARIABLE});
176
+ injector.register('style', 'css content');
177
+ //=> injector.register('css', {value: 'css content', priority: injector.order.REGISTER_STYLE});
178
+ ```
179
+
180
+ ### NexT plugin
181
+
182
+ 如果你希望在你的主题中使用NexT主题的插件,启用以下配置(默认启用),如果存在不兼容的插件,可以提交issue
183
+
184
+ ```yml
185
+ injector:
186
+ load_next_plugin: true
187
+ ```
188
+
189
+ 除此外,主题需要提供与[NexT类似的注入点](lib/next-point.js),如[Cake](https://github.com/jiangtj/hexo-theme-cake)主题已经添加,但如果是其它主题,你可能需要自己添加它
@@ -0,0 +1,191 @@
1
+ # hexo-extend-injector2
2
+
3
+ Provide extensions for plugins or themes to inject code to specified locations (if the theme provides corresponding injection points)
4
+
5
+ ![npm](https://img.shields.io/npm/v/hexo-extend-injector2.svg)
6
+
7
+ [中文文档](README-ZH.md)
8
+
9
+ The function of this plugin refers to the design of the native injector, but because it cannot be compatible with the original next plugin scheme, it is redesigned to provide more extension capabilities. For details, see [this PR](https://github.com/jiangtj/hexo-theme-cake/pull/39)
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ yarn add hexo-extend-injector2
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ First of all, you need to obtain the injector instance through require. The injectors in the following API are all obtained like this
20
+
21
+ ```js
22
+ const injector = require('hexo-extend-injector2')(hexo);
23
+ ```
24
+
25
+ ### Register
26
+
27
+ There are two ways to write
28
+
29
+ ```js
30
+ injector.register(entry, value, predicate, priority, isRun);
31
+ injector.register(entry, {
32
+ value: value,
33
+ predicate: predicate,
34
+ priority: priority,
35
+ isRun: true/false
36
+ });
37
+ ```
38
+
39
+ #### Params
40
+
41
+ | attribute | type | description | default |
42
+ | :----- | :----- | :----- | :----- |
43
+ | entry | String | injection position, it ignores case and ` ` `-` `_`, e.g. 'bodybegin' = 'bodyBegin' = 'body-begin' = 'body_begin' | - |
44
+ | value | String/Function | injected content, if it is a function, will pass the context and options parameters | - |
45
+ | predicate | String/Function | effective conditions, see example for details | `() => true` |
46
+ | priority | Number | priority | 10 |
47
+ | isRun | Boolean | Part of the content of hexo is reloaded after the file is changed. When reloading, the content of isRun will be cleared to avoid repeated loading. | false |
48
+
49
+
50
+ #### Example
51
+
52
+ 1. This is simplest demo, add fontawesome CSS to the head of your site. The following three methods are equivalent
53
+ ```js
54
+ injector.register('head-end', '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.11.2/css/all.min.css" crossorigin="anonymous">');
55
+ injector.register('head-end', () => '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.11.2/css/all.min.css" crossorigin="anonymous">');
56
+ injector.register('head-end', {
57
+ value: '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.11.2/css/all.min.css" crossorigin="anonymous">'
58
+ });
59
+ ```
60
+
61
+ 2. Use of Predicate
62
+ ```js
63
+ // When you need to inject content on a specific page, you need to use Predicate, which is divided into two ways of writing
64
+
65
+ // Like the official, specify the layout type, as follows, APlayer will be added to the specific music layout
66
+ injector.register('head_end', () => {
67
+ return css('https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.css');
68
+ }, 'music');
69
+ injector.register('body_end', '<script src="https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.js">', 'music');
70
+ // Equivalent to using injector.is('home','category', ...), multiple layouts can be passed, and they will take effect at the same time
71
+ injector.register('body_end', '<script src="https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.js">', injector.is('music'));
72
+
73
+ // Judging by context or options
74
+ injector.register('head-end', {
75
+ predicate: (ctx, options) => {
76
+ // ctx in different situations, the value passed in may be different,
77
+ return ctx.page['music'];
78
+ },
79
+ value: () => {
80
+ return css('https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.css');
81
+ }
82
+ });
83
+ ```
84
+
85
+ ### Get
86
+
87
+ By default, only four injection points are provided `head-begin` `head-end` `body-begin` `body-end`, you can set `disable_injector2_default_point` to true to disable
88
+
89
+ In other cases, developers need to use JS API or Hexo Helper to obtain the content stored in the injector, and process it by yourself
90
+
91
+ #### API
92
+
93
+ ```js
94
+ const result = injector.get(entry, options);
95
+ ```
96
+
97
+ - result.list(): Get all injection objects of this injection point
98
+ - result.rendered(): get and render all injection objects of this injection point (if value is a function, it will be converted to String)
99
+ - result.text(): render and merge all the injected content of this injection point
100
+
101
+ Example
102
+
103
+ ```js
104
+ // In bundler, by adding env to determine whether it is the required css content
105
+ injector.get('css', {env: 'dark'});
106
+ // Override the default ctx
107
+ injector.get('point', {context: this});
108
+ ```
109
+
110
+ #### Helper
111
+
112
+ The injector helper is very similar to injector.get(), but the context is replaced with the local variables of hexo
113
+
114
+ ```ejs
115
+ <!DOCTYPE html>
116
+ <html>
117
+ <head>
118
+ <%- injector('head-begin').text() -%>
119
+ ...
120
+ <%- injector('head-end').text() -%>
121
+ </head>
122
+ <body>
123
+ <%- injector('body-begin').text() -%>
124
+ ...
125
+ <%- injector('body-end').text() -%>
126
+ </body>
127
+ </html>
128
+ ```
129
+
130
+ ### bundler
131
+
132
+ The plug-in provides the bundler of JS and CSS, which can be easily added to the theme
133
+
134
+ #### config
135
+
136
+ The following is the default configuration of the bundler
137
+
138
+ ```yml
139
+ injector2:
140
+ js:
141
+ enable: true
142
+ path: js/injector.js
143
+ options: {}
144
+ css:
145
+ enable: true
146
+ path:
147
+ default:
148
+ # Add <link rel="stylesheet" type="text/css" href="${url_for(file.path)}" /> in the head
149
+ link: load
150
+ path: css/injector/main.css
151
+ dark:
152
+ # Add <link rel="preload" as="style" href="${url_for(file.path)}" /> in the head
153
+ link: preload
154
+ path: css/injector/dark.css
155
+ light:
156
+ link: preload
157
+ path: css/injector/light.css
158
+ options: {}
159
+ ```
160
+
161
+ #### API/Example
162
+
163
+ ```js
164
+ injector.register('js or css', 'content or file path');
165
+
166
+ // Example
167
+ injector.register('js', 'function log1() {console.log("bar");}');
168
+ injector.register('css', '.book{font-size:2rem}');
169
+
170
+ // CSS spec
171
+ // Additional env options are added. If the env is different, it will be packaged into a different CSS file
172
+ // But you need to configure it in advance. default dark and light are set by default, if not set, it will be default
173
+ injector.register('css', {value: '.book{font-size:2rem}', env: 'dark'});
174
+
175
+ // CSS alias
176
+ injector.register('variable', 'css content');
177
+ //=> injector.register('css', {value: 'css content', priority: injector.order.REGISTER_VARIABLE});
178
+ injector.register('style', 'css content');
179
+ //=> injector.register('css', {value: 'css content', priority: injector.order.REGISTER_STYLE});
180
+ ```
181
+
182
+ ### NexT plugin
183
+
184
+ If you want to use next theme plug-ins in your theme, enable the following configuration (enabled by default). If there are incompatible plug-ins, you can submit the issue
185
+
186
+ ```yml
187
+ injector:
188
+ load_next_plugin: true
189
+ ```
190
+
191
+ In addition, theme need to provide the injection point similar to [next](lib/next-point.js), such as [cake](https://github.com/jiangtj/hexo-theme-cake) has been added, but if it's another theme, you may need to add it by yourself.
@@ -0,0 +1,38 @@
1
+ ```js
2
+ const injector = require('../hexo/_inject/index')(hexo); // will make it as plugin
3
+ injector.register(entry, value, predicate, priority, isRun);
4
+ injector.register(entry, {
5
+ value: value,
6
+ predicate: predicate,
7
+ priority: priority,
8
+ isRun: true/false
9
+ });
10
+
11
+ entry = 'bodybegin' = 'bodyBegin' = 'body-begin' = 'body_begin'
12
+
13
+ value = 'String'
14
+ value = ctx => `${ctx.page.path}`
15
+
16
+ predicate = 'home'
17
+ predicate = injector.is('home', 'category', ...)
18
+ predicate = ctx => ctx.is_post()
19
+
20
+ // example
21
+ injector.register('body-Begin', '------------');
22
+ injector.register('bodyBegin', 'AAAA', 'home', 11);
23
+ injector.register('bodyBegin', 'BBBB', injector.is('home', 'category'));
24
+ injector.register('bodyBegin', 'CCCC', ctx => ctx.is_post());
25
+ injector.register('bodyBegin', {
26
+ value : 'DDDD',
27
+ predicate: ctx => ctx.is_post(),
28
+ priority : 1
29
+ });
30
+ // if use it in `before_generate` filter, set `isRun` to true
31
+ hexo.extend.filter.register('before_generate', () => {
32
+ injector.register('bodyBegin', {
33
+ value : 'isRun',
34
+ predicate: ctx => ctx.is_post(),
35
+ isRun: true
36
+ });
37
+ });
38
+ ```
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ const { resolve } = require('path');
4
+
5
+ module.exports = ctx => {
6
+ // If initialized, return the result
7
+ if (ctx.extend.injector2) {
8
+ return ctx.extend.injector2;
9
+ }
10
+ // If not in the main plugin directory, relocate to the main plugin directory
11
+ const load = require(resolve(ctx.plugin_dir, 'hexo-extend-injector2/lib/load'));
12
+ return load(ctx);
13
+ };
@@ -0,0 +1,79 @@
1
+ 'use strict';
2
+
3
+ const handleDataPre = require('./handle-data-pre');
4
+ const cssGenerator = require('./css-generator');
5
+
6
+
7
+ const loadCss = (ctx, injector, config) => {
8
+ const { generator } = ctx.extend;
9
+ const { options, file, env } = config;
10
+ const { REGISTER_CSS } = injector.order;
11
+
12
+ const url_for = require('hexo-util').url_for.bind(ctx);
13
+ if (file.link === 'preload') {
14
+ injector.register('head-end', {
15
+ value: `<link rel="preload" as="style" href="${url_for(file.path)}" />`,
16
+ priority: REGISTER_CSS
17
+ });
18
+ }
19
+ if (file.link === 'load') {
20
+ injector.register('head-end', {
21
+ value: `<link rel="stylesheet" type="text/css" href="${url_for(file.path)}" />`,
22
+ priority: REGISTER_CSS
23
+ });
24
+ }
25
+
26
+ generator.register(`css-bundler-${env}`, () => {
27
+ return {
28
+ path: file.path,
29
+ data: cssGenerator(injector, env, options)
30
+ };
31
+ });
32
+
33
+ };
34
+
35
+ module.exports = (ctx, injector) => {
36
+
37
+ const config = injector.config.css;
38
+
39
+ if (!config.enable) return;
40
+
41
+ const { filter } = ctx.extend;
42
+
43
+ const { REGISTER_VARIABLE, REGISTER_STYLE } = injector.order;
44
+
45
+ filter.register('injector2:register-variable', data => {
46
+ data.priority = REGISTER_VARIABLE;
47
+ injector.register('css', data);
48
+ });
49
+ filter.register('injector2:register-style', data => {
50
+ data.priority = REGISTER_STYLE;
51
+ injector.register('css', data);
52
+ });
53
+
54
+ if (typeof config.path === 'string') {
55
+ const { path } = config;
56
+ config.path = {
57
+ default: {
58
+ path,
59
+ link: 'load'
60
+ }
61
+ };
62
+ }
63
+
64
+ const isLoadCss = {};
65
+
66
+ filter.register('injector2:register-css', data => {
67
+ const env = data.env || 'default';
68
+ data.env = env;
69
+ const file = config.path[env];
70
+ const options = config.options;
71
+ if (file && !isLoadCss[env]) {
72
+ loadCss(ctx, injector, {options, env, file});
73
+ isLoadCss[env] = true;
74
+ }
75
+ handleDataPre(ctx, data, ['.css', '.sass', '.styl']);
76
+ data.predicate = (ctx, options) => options.env === env;
77
+ });
78
+
79
+ };
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ const CleanCSS = require('clean-css');
4
+
5
+ module.exports = (injector, env, options) => () => {
6
+ return Promise.all(injector.get('css', { env }).toPromise())
7
+ .then(values => values.join('\n'))
8
+ .then(source => {
9
+ const output = new CleanCSS(options).minify(source);
10
+ if (output.error) throw output.error;
11
+ return output.styles;
12
+ });
13
+ };