hexo-adsense 1.0.26 → 2.0.0
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 +6 -0
- package/LICENSE +0 -0
- package/dist/index.cjs +757 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +740 -0
- package/dist/index.mjs +740 -0
- package/dist/source/adblock.css +2 -0
- package/{lib → dist}/source/adblock.js +0 -0
- package/{lib → dist}/source/article-ads.css +0 -0
- package/dist/source/article-ads.js +1 -0
- package/{lib/source/article-ads.js → dist/source/article-ads.old.js} +0 -0
- package/{lib → dist}/source/blogger-redirect.html +0 -0
- package/{lib → dist}/source/https.js +0 -0
- package/{lib → dist}/source/in_article_ads_test.html +0 -0
- package/package.json +122 -37
- package/{README.md → readme.md} +29 -11
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -85
- 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/src/article-ads.d.ts +0 -20
- package/lib/src/article-ads.js +0 -304
- package/lib/src/checkLocalHost.d.ts +0 -10
- package/lib/src/checkLocalHost.js +0 -37
- package/lib/src/config.d.ts +0 -13
- package/lib/src/config.js +0 -42
- package/lib/src/html-parser.d.ts +0 -9
- 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 -2
- package/lib/src/md5.js +0 -165
- 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 -159
- package/lib/src/versionParser.d.ts +0 -27
- package/lib/src/versionParser.js +0 -40
- 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/unused.md +0 -12
|
@@ -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;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const injectorHelper = require('./injector');
|
|
4
|
-
|
|
5
|
-
module.exports = (injector, ctx) => point => {
|
|
6
|
-
const nextInject = ctx.theme.injects[point]
|
|
7
|
-
.map(item => ctx.partial(item.layout, item.locals, item.options))
|
|
8
|
-
.join('');
|
|
9
|
-
let injector2 = injectorHelper(injector, ctx)(point).text();
|
|
10
|
-
if (point === 'head') {
|
|
11
|
-
injector2 += injectorHelper(injector, ctx)('head-end').text();
|
|
12
|
-
}
|
|
13
|
-
return nextInject + injector2;
|
|
14
|
-
};
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const order = require('./order');
|
|
4
|
-
const defaultConfig = require('./default-config');
|
|
5
|
-
const { mergeWith } = require('lodash');
|
|
6
|
-
// const { join } = require('path');
|
|
7
|
-
// const { readFileSync } = require('fs');
|
|
8
|
-
class Injector {
|
|
9
|
-
constructor(ctx) {
|
|
10
|
-
this._store = {};
|
|
11
|
-
this._run = {};
|
|
12
|
-
this._ctx = ctx;
|
|
13
|
-
this.order = order;
|
|
14
|
-
this.config = mergeWith(defaultConfig, ctx.config.injector, (objValue, srcValue) => {
|
|
15
|
-
if (Array.isArray(objValue)) {
|
|
16
|
-
return srcValue;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
clean() {
|
|
22
|
-
this._run = {};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
get(entry, options) {
|
|
26
|
-
entry = this.formatKey(entry);
|
|
27
|
-
options = Object.assign({context: this._ctx}, options);
|
|
28
|
-
const ctx = options.context;
|
|
29
|
-
|
|
30
|
-
const _storeEntries = Array.from(this._store[entry] || []);
|
|
31
|
-
const _runEntries = Array.from(this._run[entry] || []);
|
|
32
|
-
|
|
33
|
-
const list = () => _storeEntries.concat(_runEntries)
|
|
34
|
-
.filter(item => item.predicate(ctx, options))
|
|
35
|
-
.sort((a, b) => a.priority - b.priority);
|
|
36
|
-
|
|
37
|
-
const rendered = () => list()
|
|
38
|
-
.map(item => {
|
|
39
|
-
const renderItem = Object.assign({}, item);
|
|
40
|
-
if (typeof item.value === 'function') {
|
|
41
|
-
renderItem.value = item.value(ctx, options);
|
|
42
|
-
}
|
|
43
|
-
return renderItem;
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const text = (sep = '') => rendered()
|
|
47
|
-
.map(item => item.value)
|
|
48
|
-
.join(sep);
|
|
49
|
-
|
|
50
|
-
const toPromise = () => rendered()
|
|
51
|
-
.map(item => Promise.resolve(item.value));
|
|
52
|
-
|
|
53
|
-
return {list, rendered, text, toPromise};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
getSize(entry) {
|
|
57
|
-
entry = this.formatKey(entry);
|
|
58
|
-
const storeLen = this._store[entry] ? this._store[entry].length : 0;
|
|
59
|
-
const runLen = this._run[entry] ? this._run[entry].length : 0;
|
|
60
|
-
return storeLen + runLen;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
register(entry, value, predicate = () => true, priority = 10, isRun) {
|
|
64
|
-
if (!entry) throw new TypeError('entry is required');
|
|
65
|
-
entry = this.formatKey(entry);
|
|
66
|
-
|
|
67
|
-
if (typeof value !== 'object') {
|
|
68
|
-
value = { value };
|
|
69
|
-
}
|
|
70
|
-
const options = Object.assign({ predicate, priority, isRun }, value);
|
|
71
|
-
|
|
72
|
-
const store = options.isRun ? this._run : this._store;
|
|
73
|
-
store[entry] = store[entry] || [];
|
|
74
|
-
|
|
75
|
-
if (typeof options.predicate === 'string') {
|
|
76
|
-
options.predicate = this.is(options.predicate);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
this._ctx.execFilterSync('injector2:register', options, {args: [entry]});
|
|
80
|
-
this._ctx.execFilterSync(`injector2:register-${entry}`, options);
|
|
81
|
-
|
|
82
|
-
store[entry].push(options);
|
|
83
|
-
return this;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
is(...types) {
|
|
87
|
-
return locals => {
|
|
88
|
-
for (const type of types) {
|
|
89
|
-
if (type === 'home' && locals.page.__index) return true;
|
|
90
|
-
if (type === 'post' && locals.page.__post) return true;
|
|
91
|
-
if (type === 'page' && locals.page.__page) return true;
|
|
92
|
-
if (type === 'archive' && locals.page.archive) return true;
|
|
93
|
-
if (type === 'category' && locals.page.category) return true;
|
|
94
|
-
if (type === 'tag' && locals.page.tag) return true;
|
|
95
|
-
if (locals.page[type]) return true;
|
|
96
|
-
}
|
|
97
|
-
return false;
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
formatKey(entry) {
|
|
102
|
-
return entry.replace(/[-| |_]/g, '').toLowerCase();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
registerDefaultPoint() {
|
|
106
|
-
const { filter } = this._ctx.extend;
|
|
107
|
-
filter.register('_after_html_render', require('./filter')(this));
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
registerHelper() {
|
|
111
|
-
const self = this;
|
|
112
|
-
const { helper } = this._ctx.extend;
|
|
113
|
-
helper.register('injector', function(point) {
|
|
114
|
-
return require('./helper/injector')(self, this)(point);
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
registerNexTHelper() {
|
|
119
|
-
// 为了能覆盖主题中的注册,请在after_init中调用
|
|
120
|
-
const self = this;
|
|
121
|
-
const { helper } = this._ctx.extend;
|
|
122
|
-
helper.register('next_inject', function(point) {
|
|
123
|
-
return require('./helper/next-inject')(self, this)(point);
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
module.exports = Injector;
|