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.
- package/CHANGELOG.md +0 -0
- package/LICENSE +0 -0
- package/dist/index.cjs +12799 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +12782 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +12782 -0
- package/dist/index.mjs.map +1 -0
- package/dist/source/adblock.css +2 -0
- package/dist/source/adblock.js +1 -0
- package/{lib → dist}/source/article-ads.css +0 -0
- package/dist/source/article-ads.js +1 -0
- package/dist/source/article-ads.old.js +1 -0
- package/{lib → dist}/source/blogger-redirect.html +0 -0
- package/dist/source/https.js +1 -0
- package/{lib → dist}/source/in_article_ads_test.html +0 -0
- package/package.json +122 -38
- package/{README.md → readme.md} +27 -8
- package/gulpfile.ts +0 -100
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -91
- package/lib/packages/hexo-cli-extras/lib/env.d.ts +0 -3
- package/lib/packages/hexo-cli-extras/lib/env.js +0 -49
- package/lib/packages/hexo-extend-injector2/index.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/index.js +0 -12
- package/lib/packages/hexo-extend-injector2/lib/bundle/css-bundle.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/bundle/css-bundle.js +0 -64
- package/lib/packages/hexo-extend-injector2/lib/bundle/css-generator.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/bundle/css-generator.js +0 -12
- package/lib/packages/hexo-extend-injector2/lib/bundle/handle-data-pre.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/bundle/handle-data-pre.js +0 -28
- package/lib/packages/hexo-extend-injector2/lib/bundle/js-bundle.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/bundle/js-bundle.js +0 -32
- package/lib/packages/hexo-extend-injector2/lib/bundle/js-generator.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/bundle/js-generator.js +0 -8
- package/lib/packages/hexo-extend-injector2/lib/default-config.d.ts +0 -39
- package/lib/packages/hexo-extend-injector2/lib/default-config.js +0 -46
- package/lib/packages/hexo-extend-injector2/lib/filter.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/filter.js +0 -22
- package/lib/packages/hexo-extend-injector2/lib/helper/injector.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/helper/injector.js +0 -5
- package/lib/packages/hexo-extend-injector2/lib/helper/next-inject.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/helper/next-inject.js +0 -12
- package/lib/packages/hexo-extend-injector2/lib/injector.d.ts +0 -29
- package/lib/packages/hexo-extend-injector2/lib/injector.js +0 -125
- package/lib/packages/hexo-extend-injector2/lib/load.d.ts +0 -3
- package/lib/packages/hexo-extend-injector2/lib/load.js +0 -37
- package/lib/packages/hexo-extend-injector2/lib/next-point.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/next-point.js +0 -18
- package/lib/packages/hexo-extend-injector2/lib/next.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/next.js +0 -99
- package/lib/packages/hexo-extend-injector2/lib/order.d.ts +0 -5
- package/lib/packages/hexo-extend-injector2/lib/order.js +0 -8
- package/lib/source/adblock.css +0 -2
- package/lib/source/adblock.js +0 -1
- package/lib/source/article-ads.js +0 -1
- package/lib/source/article-ads.old.js +0 -1
- package/lib/source/https.js +0 -1
- package/lib/src/article-ads.d.ts +0 -20
- package/lib/src/article-ads.js +0 -310
- package/lib/src/checkLocalHost.d.ts +0 -10
- package/lib/src/checkLocalHost.js +0 -37
- package/lib/src/config.d.ts +0 -14
- package/lib/src/config.js +0 -50
- package/lib/src/html-parser.d.ts +0 -8
- package/lib/src/html-parser.js +0 -26
- package/lib/src/log.d.ts +0 -1
- package/lib/src/log.js +0 -11
- package/lib/src/logger.d.ts +0 -3
- package/lib/src/logger.js +0 -25
- package/lib/src/md5.d.ts +0 -7
- package/lib/src/md5.js +0 -30
- package/lib/src/safestringify.d.ts +0 -2
- package/lib/src/safestringify.js +0 -125
- package/lib/src/utils.d.ts +0 -31
- package/lib/src/utils.js +0 -160
- package/lib/src/versionParser.d.ts +0 -27
- package/lib/src/versionParser.js +0 -40
- package/packages/@types/.gitmodules +0 -8
- package/packages/@types/LICENSE +0 -21
- package/packages/@types/README.md +0 -27
- package/packages/@types/hexo/HexoConfig.d.ts +0 -216
- package/packages/@types/hexo/LICENSE +0 -21
- package/packages/@types/hexo/README.md +0 -16
- package/packages/@types/hexo/index.d.ts +0 -849
- package/packages/@types/hexo/package.json +0 -34
- package/packages/@types/hexo-bunyan/LICENSE +0 -21
- package/packages/@types/hexo-bunyan/README.md +0 -16
- package/packages/@types/hexo-bunyan/index.d.ts +0 -9
- package/packages/@types/hexo-bunyan/package.json +0 -24
- package/packages/@types/hexo-log/LICENSE +0 -21
- package/packages/@types/hexo-log/README.md +0 -16
- package/packages/@types/hexo-log/index.d.ts +0 -159
- package/packages/@types/hexo-log/package.json +0 -28
- package/packages/@types/index.js +0 -2
- package/packages/@types/package.json +0 -30
- package/packages/@types/test/package.json +0 -15
- package/packages/@types/test/through2.ts +0 -6
- package/packages/@types/tsconfig.json +0 -14
- package/packages/@types/typings/index.d.ts +0 -7
- package/packages/@types/typings/kill-port.d.ts +0 -3
- package/packages/@types/typings/markdown-it-abbr.d.ts +0 -4
- package/packages/@types/typings/markdown-it-footnote.d.ts +0 -4
- package/packages/@types/typings/markdown-it-image-figures.d.ts +0 -4
- package/packages/@types/typings/markdown-it-mark.d.ts +0 -4
- package/packages/@types/typings/markdown-it-sub.d.ts +0 -7
- package/packages/@types/typings/markdown-it-sup.d.ts +0 -7
- package/packages/hexo-cli-extras/.eslintrc +0 -13
- package/packages/hexo-cli-extras/LICENSE.md +0 -20
- package/packages/hexo-cli-extras/README.md +0 -146
- package/packages/hexo-cli-extras/docs/basic.gif +0 -0
- package/packages/hexo-cli-extras/docs/gui.gif +0 -0
- package/packages/hexo-cli-extras/docs/remove.png +0 -0
- package/packages/hexo-cli-extras/docs/rename.png +0 -0
- package/packages/hexo-cli-extras/index.js +0 -48
- package/packages/hexo-cli-extras/lib/edit.js +0 -209
- package/packages/hexo-cli-extras/lib/env.js +0 -52
- package/packages/hexo-cli-extras/lib/extensions.js +0 -23
- package/packages/hexo-cli-extras/lib/integrate.js +0 -87
- package/packages/hexo-cli-extras/lib/isolate.js +0 -179
- package/packages/hexo-cli-extras/lib/remove.js +0 -145
- package/packages/hexo-cli-extras/lib/rename.js +0 -171
- package/packages/hexo-cli-extras/package.json +0 -34
- package/packages/hexo-extend-injector2/.eslintrc +0 -4
- package/packages/hexo-extend-injector2/.github/workflows/linter.yml +0 -27
- package/packages/hexo-extend-injector2/.github/workflows/tester.yml +0 -24
- package/packages/hexo-extend-injector2/.vscode/settings.json +0 -10
- package/packages/hexo-extend-injector2/LICENSE +0 -165
- package/packages/hexo-extend-injector2/README-ZH.md +0 -189
- package/packages/hexo-extend-injector2/README.md +0 -191
- package/packages/hexo-extend-injector2/USAGE.md +0 -38
- package/packages/hexo-extend-injector2/index.js +0 -14
- package/packages/hexo-extend-injector2/lib/bundle/css-bundle.js +0 -79
- package/packages/hexo-extend-injector2/lib/bundle/css-generator.js +0 -13
- package/packages/hexo-extend-injector2/lib/bundle/handle-data-pre.js +0 -29
- package/packages/hexo-extend-injector2/lib/bundle/js-bundle.js +0 -42
- package/packages/hexo-extend-injector2/lib/bundle/js-generator.js +0 -10
- package/packages/hexo-extend-injector2/lib/default-config.js +0 -52
- package/packages/hexo-extend-injector2/lib/filter.js +0 -24
- package/packages/hexo-extend-injector2/lib/helper/injector.js +0 -6
- package/packages/hexo-extend-injector2/lib/helper/next-inject.js +0 -14
- package/packages/hexo-extend-injector2/lib/injector.js +0 -128
- package/packages/hexo-extend-injector2/lib/load.js +0 -45
- package/packages/hexo-extend-injector2/lib/next-point.js +0 -19
- package/packages/hexo-extend-injector2/lib/next.js +0 -87
- package/packages/hexo-extend-injector2/lib/order.js +0 -9
- package/packages/hexo-extend-injector2/package.json +0 -49
- package/packages/hexo-extend-injector2/renovate.json +0 -6
- package/packages/hexo-extend-injector2/test/.eslintrc +0 -3
- package/packages/hexo-extend-injector2/test/index.js +0 -18
- package/packages/hexo-extend-injector2/test/lib/bundle/bundle-css.js +0 -86
- package/packages/hexo-extend-injector2/test/lib/bundle/bundle-js.js +0 -36
- package/packages/hexo-extend-injector2/test/lib/bundle/test.css +0 -3
- package/packages/hexo-extend-injector2/test/lib/bundle/test.js +0 -5
- package/packages/hexo-extend-injector2/test/lib/helper/injector.js +0 -45
- package/packages/hexo-extend-injector2/test/lib/helper/next-inject.js +0 -69
- package/packages/hexo-extend-injector2/test/lib/hexo-compatible.js +0 -250
- package/packages/hexo-extend-injector2/test/lib/hexo-injector.js +0 -37
- package/packages/hexo-extend-injector2/test/lib/injector.js +0 -93
- package/packages/memoize/CHANGELOG.md +0 -82
- package/packages/memoize/CHANGES +0 -124
- package/packages/memoize/LICENSE +0 -15
- package/packages/memoize/README.md +0 -503
- package/packages/memoize/ext/async.js +0 -154
- package/packages/memoize/ext/dispose.js +0 -33
- package/packages/memoize/ext/max-age.js +0 -90
- package/packages/memoize/ext/max.js +0 -27
- package/packages/memoize/ext/promise.js +0 -147
- package/packages/memoize/ext/ref-counter.js +0 -48
- package/packages/memoize/index.js +0 -34
- package/packages/memoize/lib/configure-map.js +0 -182
- package/packages/memoize/lib/methods.js +0 -32
- package/packages/memoize/lib/registered-extensions.js +0 -1
- package/packages/memoize/lib/resolve-length.js +0 -15
- package/packages/memoize/lib/resolve-normalize.js +0 -17
- package/packages/memoize/lib/resolve-resolve.js +0 -21
- package/packages/memoize/lib/weak.js +0 -134
- package/packages/memoize/methods-plain.js +0 -3
- package/packages/memoize/methods.js +0 -3
- package/packages/memoize/normalizers/get-1.js +0 -29
- package/packages/memoize/normalizers/get-fixed.js +0 -71
- package/packages/memoize/normalizers/get-primitive-fixed.js +0 -16
- package/packages/memoize/normalizers/get.js +0 -90
- package/packages/memoize/normalizers/primitive.js +0 -9
- package/packages/memoize/package.json +0 -60
- package/packages/memoize/plain.js +0 -37
- package/packages/memoize/profile.js +0 -107
- package/packages/memoize/repository.md +0 -1
- package/packages/memoize/weak-plain.js +0 -3
- package/packages/memoize/weak.js +0 -3
- package/tsconfig.json +0 -39
- package/unused.md +0 -11
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
# hexo-extend-injector2
|
|
2
|
-
|
|
3
|
-
为插件或者主题提供扩展,能将代码注入到指定位置(如果主题提供相应的注入点)
|
|
4
|
-
|
|
5
|
-

|
|
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
|
-

|
|
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;
|