hexo-adsense 1.1.1 → 2.0.2

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 (192) hide show
  1. package/CHANGELOG.md +0 -0
  2. package/LICENSE +0 -0
  3. package/dist/index.cjs +12799 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.js +12782 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +12782 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/dist/source/adblock.css +2 -0
  10. package/dist/source/adblock.js +1 -0
  11. package/{lib → dist}/source/article-ads.css +0 -0
  12. package/dist/source/article-ads.js +1 -0
  13. package/dist/source/article-ads.old.js +1 -0
  14. package/{lib → dist}/source/blogger-redirect.html +0 -0
  15. package/dist/source/https.js +1 -0
  16. package/{lib → dist}/source/in_article_ads_test.html +0 -0
  17. package/package.json +122 -38
  18. package/{README.md → readme.md} +27 -8
  19. package/gulpfile.ts +0 -100
  20. package/lib/index.d.ts +0 -1
  21. package/lib/index.js +0 -91
  22. package/lib/packages/hexo-cli-extras/lib/env.d.ts +0 -3
  23. package/lib/packages/hexo-cli-extras/lib/env.js +0 -49
  24. package/lib/packages/hexo-extend-injector2/index.d.ts +0 -2
  25. package/lib/packages/hexo-extend-injector2/index.js +0 -12
  26. package/lib/packages/hexo-extend-injector2/lib/bundle/css-bundle.d.ts +0 -2
  27. package/lib/packages/hexo-extend-injector2/lib/bundle/css-bundle.js +0 -64
  28. package/lib/packages/hexo-extend-injector2/lib/bundle/css-generator.d.ts +0 -2
  29. package/lib/packages/hexo-extend-injector2/lib/bundle/css-generator.js +0 -12
  30. package/lib/packages/hexo-extend-injector2/lib/bundle/handle-data-pre.d.ts +0 -2
  31. package/lib/packages/hexo-extend-injector2/lib/bundle/handle-data-pre.js +0 -28
  32. package/lib/packages/hexo-extend-injector2/lib/bundle/js-bundle.d.ts +0 -2
  33. package/lib/packages/hexo-extend-injector2/lib/bundle/js-bundle.js +0 -32
  34. package/lib/packages/hexo-extend-injector2/lib/bundle/js-generator.d.ts +0 -2
  35. package/lib/packages/hexo-extend-injector2/lib/bundle/js-generator.js +0 -8
  36. package/lib/packages/hexo-extend-injector2/lib/default-config.d.ts +0 -39
  37. package/lib/packages/hexo-extend-injector2/lib/default-config.js +0 -46
  38. package/lib/packages/hexo-extend-injector2/lib/filter.d.ts +0 -2
  39. package/lib/packages/hexo-extend-injector2/lib/filter.js +0 -22
  40. package/lib/packages/hexo-extend-injector2/lib/helper/injector.d.ts +0 -2
  41. package/lib/packages/hexo-extend-injector2/lib/helper/injector.js +0 -5
  42. package/lib/packages/hexo-extend-injector2/lib/helper/next-inject.d.ts +0 -2
  43. package/lib/packages/hexo-extend-injector2/lib/helper/next-inject.js +0 -12
  44. package/lib/packages/hexo-extend-injector2/lib/injector.d.ts +0 -29
  45. package/lib/packages/hexo-extend-injector2/lib/injector.js +0 -125
  46. package/lib/packages/hexo-extend-injector2/lib/load.d.ts +0 -3
  47. package/lib/packages/hexo-extend-injector2/lib/load.js +0 -37
  48. package/lib/packages/hexo-extend-injector2/lib/next-point.d.ts +0 -2
  49. package/lib/packages/hexo-extend-injector2/lib/next-point.js +0 -18
  50. package/lib/packages/hexo-extend-injector2/lib/next.d.ts +0 -2
  51. package/lib/packages/hexo-extend-injector2/lib/next.js +0 -99
  52. package/lib/packages/hexo-extend-injector2/lib/order.d.ts +0 -5
  53. package/lib/packages/hexo-extend-injector2/lib/order.js +0 -8
  54. package/lib/source/adblock.css +0 -2
  55. package/lib/source/adblock.js +0 -1
  56. package/lib/source/article-ads.js +0 -1
  57. package/lib/source/article-ads.old.js +0 -1
  58. package/lib/source/https.js +0 -1
  59. package/lib/src/article-ads.d.ts +0 -20
  60. package/lib/src/article-ads.js +0 -310
  61. package/lib/src/checkLocalHost.d.ts +0 -10
  62. package/lib/src/checkLocalHost.js +0 -37
  63. package/lib/src/config.d.ts +0 -14
  64. package/lib/src/config.js +0 -50
  65. package/lib/src/html-parser.d.ts +0 -8
  66. package/lib/src/html-parser.js +0 -26
  67. package/lib/src/log.d.ts +0 -1
  68. package/lib/src/log.js +0 -11
  69. package/lib/src/logger.d.ts +0 -3
  70. package/lib/src/logger.js +0 -25
  71. package/lib/src/md5.d.ts +0 -7
  72. package/lib/src/md5.js +0 -30
  73. package/lib/src/safestringify.d.ts +0 -2
  74. package/lib/src/safestringify.js +0 -125
  75. package/lib/src/utils.d.ts +0 -31
  76. package/lib/src/utils.js +0 -160
  77. package/lib/src/versionParser.d.ts +0 -27
  78. package/lib/src/versionParser.js +0 -40
  79. package/packages/@types/.gitmodules +0 -8
  80. package/packages/@types/LICENSE +0 -21
  81. package/packages/@types/README.md +0 -27
  82. package/packages/@types/hexo/HexoConfig.d.ts +0 -216
  83. package/packages/@types/hexo/LICENSE +0 -21
  84. package/packages/@types/hexo/README.md +0 -16
  85. package/packages/@types/hexo/index.d.ts +0 -849
  86. package/packages/@types/hexo/package.json +0 -34
  87. package/packages/@types/hexo-bunyan/LICENSE +0 -21
  88. package/packages/@types/hexo-bunyan/README.md +0 -16
  89. package/packages/@types/hexo-bunyan/index.d.ts +0 -9
  90. package/packages/@types/hexo-bunyan/package.json +0 -24
  91. package/packages/@types/hexo-log/LICENSE +0 -21
  92. package/packages/@types/hexo-log/README.md +0 -16
  93. package/packages/@types/hexo-log/index.d.ts +0 -159
  94. package/packages/@types/hexo-log/package.json +0 -28
  95. package/packages/@types/index.js +0 -2
  96. package/packages/@types/package.json +0 -30
  97. package/packages/@types/test/package.json +0 -15
  98. package/packages/@types/test/through2.ts +0 -6
  99. package/packages/@types/tsconfig.json +0 -14
  100. package/packages/@types/typings/index.d.ts +0 -7
  101. package/packages/@types/typings/kill-port.d.ts +0 -3
  102. package/packages/@types/typings/markdown-it-abbr.d.ts +0 -4
  103. package/packages/@types/typings/markdown-it-footnote.d.ts +0 -4
  104. package/packages/@types/typings/markdown-it-image-figures.d.ts +0 -4
  105. package/packages/@types/typings/markdown-it-mark.d.ts +0 -4
  106. package/packages/@types/typings/markdown-it-sub.d.ts +0 -7
  107. package/packages/@types/typings/markdown-it-sup.d.ts +0 -7
  108. package/packages/hexo-cli-extras/.eslintrc +0 -13
  109. package/packages/hexo-cli-extras/LICENSE.md +0 -20
  110. package/packages/hexo-cli-extras/README.md +0 -146
  111. package/packages/hexo-cli-extras/docs/basic.gif +0 -0
  112. package/packages/hexo-cli-extras/docs/gui.gif +0 -0
  113. package/packages/hexo-cli-extras/docs/remove.png +0 -0
  114. package/packages/hexo-cli-extras/docs/rename.png +0 -0
  115. package/packages/hexo-cli-extras/index.js +0 -48
  116. package/packages/hexo-cli-extras/lib/edit.js +0 -209
  117. package/packages/hexo-cli-extras/lib/env.js +0 -52
  118. package/packages/hexo-cli-extras/lib/extensions.js +0 -23
  119. package/packages/hexo-cli-extras/lib/integrate.js +0 -87
  120. package/packages/hexo-cli-extras/lib/isolate.js +0 -179
  121. package/packages/hexo-cli-extras/lib/remove.js +0 -145
  122. package/packages/hexo-cli-extras/lib/rename.js +0 -171
  123. package/packages/hexo-cli-extras/package.json +0 -34
  124. package/packages/hexo-extend-injector2/.eslintrc +0 -4
  125. package/packages/hexo-extend-injector2/.github/workflows/linter.yml +0 -27
  126. package/packages/hexo-extend-injector2/.github/workflows/tester.yml +0 -24
  127. package/packages/hexo-extend-injector2/.vscode/settings.json +0 -10
  128. package/packages/hexo-extend-injector2/LICENSE +0 -165
  129. package/packages/hexo-extend-injector2/README-ZH.md +0 -189
  130. package/packages/hexo-extend-injector2/README.md +0 -191
  131. package/packages/hexo-extend-injector2/USAGE.md +0 -38
  132. package/packages/hexo-extend-injector2/index.js +0 -14
  133. package/packages/hexo-extend-injector2/lib/bundle/css-bundle.js +0 -79
  134. package/packages/hexo-extend-injector2/lib/bundle/css-generator.js +0 -13
  135. package/packages/hexo-extend-injector2/lib/bundle/handle-data-pre.js +0 -29
  136. package/packages/hexo-extend-injector2/lib/bundle/js-bundle.js +0 -42
  137. package/packages/hexo-extend-injector2/lib/bundle/js-generator.js +0 -10
  138. package/packages/hexo-extend-injector2/lib/default-config.js +0 -52
  139. package/packages/hexo-extend-injector2/lib/filter.js +0 -24
  140. package/packages/hexo-extend-injector2/lib/helper/injector.js +0 -6
  141. package/packages/hexo-extend-injector2/lib/helper/next-inject.js +0 -14
  142. package/packages/hexo-extend-injector2/lib/injector.js +0 -128
  143. package/packages/hexo-extend-injector2/lib/load.js +0 -45
  144. package/packages/hexo-extend-injector2/lib/next-point.js +0 -19
  145. package/packages/hexo-extend-injector2/lib/next.js +0 -87
  146. package/packages/hexo-extend-injector2/lib/order.js +0 -9
  147. package/packages/hexo-extend-injector2/package.json +0 -49
  148. package/packages/hexo-extend-injector2/renovate.json +0 -6
  149. package/packages/hexo-extend-injector2/test/.eslintrc +0 -3
  150. package/packages/hexo-extend-injector2/test/index.js +0 -18
  151. package/packages/hexo-extend-injector2/test/lib/bundle/bundle-css.js +0 -86
  152. package/packages/hexo-extend-injector2/test/lib/bundle/bundle-js.js +0 -36
  153. package/packages/hexo-extend-injector2/test/lib/bundle/test.css +0 -3
  154. package/packages/hexo-extend-injector2/test/lib/bundle/test.js +0 -5
  155. package/packages/hexo-extend-injector2/test/lib/helper/injector.js +0 -45
  156. package/packages/hexo-extend-injector2/test/lib/helper/next-inject.js +0 -69
  157. package/packages/hexo-extend-injector2/test/lib/hexo-compatible.js +0 -250
  158. package/packages/hexo-extend-injector2/test/lib/hexo-injector.js +0 -37
  159. package/packages/hexo-extend-injector2/test/lib/injector.js +0 -93
  160. package/packages/memoize/CHANGELOG.md +0 -82
  161. package/packages/memoize/CHANGES +0 -124
  162. package/packages/memoize/LICENSE +0 -15
  163. package/packages/memoize/README.md +0 -503
  164. package/packages/memoize/ext/async.js +0 -154
  165. package/packages/memoize/ext/dispose.js +0 -33
  166. package/packages/memoize/ext/max-age.js +0 -90
  167. package/packages/memoize/ext/max.js +0 -27
  168. package/packages/memoize/ext/promise.js +0 -147
  169. package/packages/memoize/ext/ref-counter.js +0 -48
  170. package/packages/memoize/index.js +0 -34
  171. package/packages/memoize/lib/configure-map.js +0 -182
  172. package/packages/memoize/lib/methods.js +0 -32
  173. package/packages/memoize/lib/registered-extensions.js +0 -1
  174. package/packages/memoize/lib/resolve-length.js +0 -15
  175. package/packages/memoize/lib/resolve-normalize.js +0 -17
  176. package/packages/memoize/lib/resolve-resolve.js +0 -21
  177. package/packages/memoize/lib/weak.js +0 -134
  178. package/packages/memoize/methods-plain.js +0 -3
  179. package/packages/memoize/methods.js +0 -3
  180. package/packages/memoize/normalizers/get-1.js +0 -29
  181. package/packages/memoize/normalizers/get-fixed.js +0 -71
  182. package/packages/memoize/normalizers/get-primitive-fixed.js +0 -16
  183. package/packages/memoize/normalizers/get.js +0 -90
  184. package/packages/memoize/normalizers/primitive.js +0 -9
  185. package/packages/memoize/package.json +0 -60
  186. package/packages/memoize/plain.js +0 -37
  187. package/packages/memoize/profile.js +0 -107
  188. package/packages/memoize/repository.md +0 -1
  189. package/packages/memoize/weak-plain.js +0 -3
  190. package/packages/memoize/weak.js +0 -3
  191. package/tsconfig.json +0 -39
  192. package/unused.md +0 -11
@@ -1,189 +0,0 @@
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)主题已经添加,但如果是其它主题,你可能需要自己添加它
@@ -1,191 +0,0 @@
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.
@@ -1,38 +0,0 @@
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
- ```
@@ -1,14 +0,0 @@
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
- const load = require('./lib/load');
13
- return load(ctx);
14
- };
@@ -1,79 +0,0 @@
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
- };
@@ -1,13 +0,0 @@
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
- };
@@ -1,29 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * 兼容以前的版本 v0.2
5
- * injector.register('css', {text: '.book{font-size:2rem}'});
6
- * injector.register('css', {path: 'xxxx.css'});
7
- */
8
-
9
- const {resolve} = require('path');
10
-
11
- module.exports = (ctx, data, suffixes = []) => {
12
- if (data.path) {
13
- data.value = () => ctx.render.render({path: resolve(ctx.base_dir, data.path)});
14
- return;
15
- }
16
- if (data.text) {
17
- data.value = data.text;
18
- return;
19
- }
20
- if (typeof data.value === 'string') {
21
- const str = data.value;
22
- for (const suffix of suffixes) {
23
- if (str.endsWith(suffix)) {
24
- data.value = () => ctx.render.render({path: resolve(ctx.base_dir, str)});
25
- return;
26
- }
27
- }
28
- }
29
- };
@@ -1,42 +0,0 @@
1
- 'use strict';
2
-
3
- const handleDataPre = require('./handle-data-pre');
4
- const jsGenerator = require('./js-generator');
5
-
6
- const loadJsScript = (ctx, injector, config) => {
7
- const { generator } = ctx.extend;
8
- const { REGISTER_JS } = injector.order;
9
-
10
- const url_for = require('hexo-util').url_for.bind(ctx);
11
- injector.register('body-end', {
12
- value: `<script src="${url_for(config.path)}"></script>`,
13
- priority: REGISTER_JS
14
- });
15
-
16
- generator.register('js-bundler', () => {
17
- return {
18
- path: config.path,
19
- data: jsGenerator(injector, config.options)
20
- };
21
- });
22
- };
23
-
24
- module.exports = (ctx, injector) => {
25
-
26
- const config = injector.config.js;
27
-
28
- if (!config.enable) return;
29
-
30
- const { filter } = ctx.extend;
31
-
32
- let isLoadJsScript = false;
33
-
34
- filter.register('injector2:register-js', data => {
35
- if (!isLoadJsScript) {
36
- loadJsScript(ctx, injector, config);
37
- isLoadJsScript = true;
38
- }
39
- handleDataPre(ctx, data, ['.js']);
40
- });
41
-
42
- };
@@ -1,10 +0,0 @@
1
- 'use strict';
2
-
3
- const { minify } = require('terser');
4
-
5
- module.exports = (injector, options) => () => {
6
- return Promise.all(injector.get('js').toPromise())
7
- .then(values => values.join('\n'))
8
- .then(source => minify(source, options))
9
- .then(result => result.code);
10
- };
@@ -1,52 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
-
5
- /**
6
- * Injector Point
7
- * If helper used, it will set injector_point_<key> to true
8
- */
9
- disable_default_point: false,
10
- injector_point_headbegin: false,
11
- injector_point_headend: false,
12
- injector_point_bodybegin: false,
13
- injector_point_bodyend: false,
14
-
15
- /**
16
- * NexT Plugin
17
- */
18
- load_next_compatible: true,
19
- load_next_plugin: true,
20
-
21
- /**
22
- * Js bundler config, use terser
23
- */
24
- js: {
25
- enable: true,
26
- path: 'js/injector.js',
27
- options: {}
28
- },
29
-
30
- /**
31
- * CSS bundler config, use clean css
32
- */
33
- css: {
34
- enable: true,
35
- path: {
36
- default: {
37
- path: 'css/injector/main.css',
38
- link: 'load'
39
- },
40
- dark: {
41
- path: 'css/injector/dark.css',
42
- link: 'preload'
43
- },
44
- light: {
45
- path: 'css/injector/light.css',
46
- link: 'preload'
47
- }
48
- },
49
- options: {}
50
- }
51
-
52
- };
@@ -1,24 +0,0 @@
1
- 'use strict';
2
-
3
- const injectFilter = injector => (data, locals) => {
4
-
5
- function inject(data, pattern, flag, isBegin = true) {
6
- if (injector.config[`injector_point_${injector.formatKey(flag)}`]) return data;
7
- const code = injector.get(flag, {context: locals}).text();
8
- if (!code.length) return data;
9
- return data.replace(pattern, str => { return isBegin ? str + code : code + str; });
10
- }
11
-
12
- // Inject head_begin
13
- data = inject(data, /<head.*?>/, 'head_begin', true);
14
- // Inject head_end
15
- data = inject(data, '</head>', 'head_end', false);
16
- // Inject body_begin
17
- data = inject(data, /<body.*?>/, 'body_begin', true);
18
- // Inject body_end
19
- data = inject(data, '</body>', 'body_end', false);
20
-
21
- return data;
22
- };
23
-
24
- module.exports = injectFilter;