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,6 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = (injector, ctx) => point => {
4
- injector.config[`injector_point_${injector.formatKey(point)}`] = true;
5
- return injector.get(point, { context: ctx });
6
- };
@@ -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;
@@ -1,45 +0,0 @@
1
- 'use strict';
2
-
3
- const Injector = require('./injector');
4
- const { join } = require('path');
5
- const { readFileSync } = require('fs');
6
-
7
- const loadInjector = ctx => {
8
- const { filter } = ctx.extend;
9
-
10
- // Init injector
11
- const injector = new Injector(ctx);
12
- ctx.extend.injector2 = injector;
13
- ctx.on('generateBefore', () => {
14
- injector.clean();
15
- });
16
- injector.registerHelper();
17
-
18
- const { order, config } = injector;
19
-
20
- if (!config.disable_default_point) {
21
- injector.registerDefaultPoint();
22
- }
23
-
24
- // Load next plugin
25
- const themeD = JSON.parse(readFileSync(join(ctx.theme_dir, 'package.json'), 'utf-8'));
26
- if (themeD.name === 'hexo-theme-next') {
27
- if (config.load_next_compatible) {
28
- filter.register('after_init', () => {
29
- injector.registerNexTHelper();
30
- }, order.REGISTER_NEXT_HELPER);
31
- }
32
- } else {
33
- if (config.load_next_plugin) {
34
- require('./next')(ctx, injector);
35
- }
36
- }
37
-
38
- // Build js and css bundler
39
- require('./bundle/js-bundle')(ctx, injector);
40
- require('./bundle/css-bundle')(ctx, injector);
41
-
42
- return injector;
43
- };
44
-
45
- module.exports = loadInjector;
@@ -1,19 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- views: [
5
- 'head',
6
- 'header',
7
- 'sidebar',
8
- 'postMeta',
9
- 'postBodyEnd',
10
- 'footer',
11
- 'bodyEnd',
12
- 'comment'
13
- ],
14
- styles: [
15
- 'variable',
16
- 'mixin',
17
- 'style'
18
- ]
19
- };
@@ -1,87 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Compatible with next theme injector
5
- */
6
- const points = require('./next-point');
7
- const fs = require('fs');
8
- const path = require('path');
9
- const defaultExtname = '.swig';
10
-
11
- // Defining stylus types
12
- class StylusInject {
13
- constructor(base_dir) {
14
- this.base_dir = base_dir;
15
- this.files = [];
16
- }
17
- push(file) {
18
- // Get absolute path base on hexo dir
19
- this.files.push(path.resolve(this.base_dir, file));
20
- }
21
- }
22
-
23
- // Defining view types
24
- class ViewInject {
25
- constructor(base_dir) {
26
- this.base_dir = base_dir;
27
- this.raws = [];
28
- }
29
- raw(name, raw, ...args) {
30
- // Set default extname
31
- if (path.extname(name) === '') {
32
- name += defaultExtname;
33
- }
34
- this.raws.push({name, raw, args});
35
- }
36
- file(name, file, ...args) {
37
- // Set default extname from file's extname
38
- if (path.extname(name) === '') {
39
- name += path.extname(file);
40
- }
41
- // Get absolute path base on hexo dir
42
- this.raw(name, fs.readFileSync(path.resolve(this.base_dir, file), 'utf8'), ...args);
43
- }
44
- }
45
-
46
- // Init injects
47
- function initInject(base_dir) {
48
- const injects = {};
49
- points.styles.forEach(item => {
50
- injects[item] = new StylusInject(base_dir);
51
- });
52
- points.views.forEach(item => {
53
- injects[item] = new ViewInject(base_dir);
54
- });
55
- return injects;
56
- }
57
-
58
-
59
- module.exports = (ctx, injector) => {
60
-
61
- ctx.on('generateBefore', () => {
62
- const injects = initInject(ctx.base_dir);
63
- ctx.execFilterSync('theme_inject', injects);
64
- // stylus
65
- points.styles.forEach(type => {
66
- injects[type].files.forEach(file => injector.register(type, file, () => true, 10, true));
67
- });
68
- // view
69
- points.views.forEach(type => {
70
- injects[type].raws
71
- .map((injectObj, index) => {
72
- const name = injectObj.name;
73
- const layout = `inject/${type}/${name}`;
74
- if (!ctx.theme.getView(layout)) {
75
- ctx.theme.setView(layout, injectObj.raw);
76
- }
77
- const locals = injectObj.args[0];
78
- const options = injectObj.args[1];
79
- const order = injectObj.args[2] || index;
80
- const value = ctx => ctx.partial(layout, locals, options);
81
- return { value, priority: order, name, layout, locals, options, isRun: true };
82
- })
83
- .sort((a, b) => b.priority - a.priority)
84
- .forEach(data => injector.register(type, data));
85
- });
86
- });
87
- };
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- REGISTER_NEXT_HELPER: -1000,
5
- REGISTER_VARIABLE: -1000,
6
- REGISTER_STYLE: 1000,
7
- REGISTER_JS: 1000,
8
- REGISTER_CSS: 1000
9
- };
@@ -1,49 +0,0 @@
1
- {
2
- "name": "hexo-extend-injector2",
3
- "version": "0.3.1",
4
- "description": "🍀 a hexo extend to inject any code into theme.",
5
- "main": "index.js",
6
- "scripts": {
7
- "eslint": "eslint .",
8
- "test": "mocha test/index.js",
9
- "p": "yarn --proxy=http://localhost:1080"
10
- },
11
- "directories": {
12
- "lib": "./lib"
13
- },
14
- "files": [
15
- "lib",
16
- "index.js"
17
- ],
18
- "repository": {
19
- "type": "git",
20
- "url": "git+https://github.com/jiangtj/hexo-extend-injector2.git"
21
- },
22
- "keywords": [
23
- "hexo",
24
- "hexo-plugin"
25
- ],
26
- "author": "Mr.J",
27
- "license": "LGPL-3.0",
28
- "bugs": {
29
- "url": "https://github.com/jiangtj/hexo-extend-injector2/issues"
30
- },
31
- "homepage": "https://github.com/jiangtj/hexo-extend-injector2#readme",
32
- "dependencies": {
33
- "clean-css": "^5.1.1",
34
- "hexo-util": "^2.0.0",
35
- "lodash": "^4.17.15",
36
- "terser": "^5.0.0"
37
- },
38
- "devDependencies": {
39
- "chai": "^4.2.0",
40
- "eslint": "^7.0.0",
41
- "eslint-config-hexo": "^4.1.0",
42
- "hexo": "^5.0.0",
43
- "hexo-renderer-stylus": "^2.0.0",
44
- "mocha": "^8.0.1"
45
- },
46
- "publishConfig": {
47
- "registry": "https://registry.npmjs.org"
48
- }
49
- }
@@ -1,6 +0,0 @@
1
- {
2
- "extends": [
3
- "config:base",
4
- ":preserveSemverRanges"
5
- ]
6
- }
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "hexo/test"
3
- }
@@ -1,18 +0,0 @@
1
- 'use strict';
2
-
3
- const Hexo = require('hexo');
4
- // eslint-disable-next-line no-unused-vars
5
- const hexo = new Hexo(__dirname, { silent: true });
6
-
7
- describe('main', () => {
8
- require('./lib/injector');
9
- describe('helper', () => {
10
- require('./lib/helper/injector');
11
- require('./lib/helper/next-inject');
12
- });
13
- describe('bundler', () => {
14
- require('./lib/bundle/bundle-js');
15
- require('./lib/bundle/bundle-css');
16
- });
17
- require('./lib/hexo-compatible');
18
- });
@@ -1,86 +0,0 @@
1
- 'use strict';
2
-
3
- require('chai').should();
4
- const Hexo = require('hexo');
5
- const Injector = require('../../../lib/injector');
6
- const cssGenerator = require('../../../lib/bundle/css-generator');
7
- const { resolve } = require('path');
8
-
9
- describe('CSS Bundler', () => {
10
- it('basic', () => {
11
- const hexo = new Hexo();
12
- const injector = new Injector(hexo);
13
- require('../../../lib/bundle/css-bundle')(hexo, injector);
14
- injector.register('css', 'a{--color: #6f42c1;}');
15
- injector.register('css', 'body {\n color: #abc;\n}\n');
16
-
17
- injector.get('headend').text().should.eql('<link rel="stylesheet" type="text/css" href="/css/injector/main.css" />');
18
-
19
- const exec = cssGenerator(injector, 'default');
20
- return exec()
21
- .then(result => {
22
- result.should.eql('a{--color:#6f42c1}body{color:#abc}');
23
- });
24
- });
25
-
26
- it('v0.2 scheme', () => {
27
- const hexo = new Hexo();
28
- const injector = new Injector(hexo);
29
- require('../../../lib/bundle/css-bundle')(hexo, injector);
30
- injector.register('css', { path: resolve(__dirname, 'test.css') });
31
- injector.register('css', { text: () => 'body {\n color: #abc;\n}\n' });
32
-
33
- const exec = cssGenerator(injector, 'default');
34
- return exec()
35
- .then(result => {
36
- result.should.eql('.book1{color:#0ff}body{color:#abc}');
37
- });
38
- });
39
-
40
- it('dark mode', () => {
41
- const hexo = new Hexo();
42
- const injector = new Injector(hexo);
43
- require('../../../lib/bundle/css-bundle')(hexo, injector);
44
- injector.register('css', 'a{--color: #6f42c1;}');
45
- injector.register('css', 'body {\n color: #abc;\n}\n');
46
- injector.register('css', {env: 'dark', value: 'a{--color: #bbb;}'});
47
- injector.register('css', {env: 'dark', value: 'book{--color: #aaa;}'});
48
-
49
- injector.get('headend').text().should.eql('<link rel="stylesheet" type="text/css" href="/css/injector/main.css" /><link rel="preload" as="style" href="/css/injector/dark.css" />');
50
-
51
- let exec = cssGenerator(injector, 'default');
52
- return exec()
53
- .then(result => {
54
- result.should.eql('a{--color:#6f42c1}body{color:#abc}');
55
- exec = cssGenerator(injector, 'dark');
56
- return exec();
57
- })
58
- .then(result => {
59
- result.should.eql('a{--color:#bbb}book{--color:#aaa}');
60
- });
61
- });
62
-
63
- it('light mode', () => {
64
- const hexo = new Hexo();
65
- const injector = new Injector(hexo);
66
- require('../../../lib/bundle/css-bundle')(hexo, injector);
67
- injector.register('css', 'a{--color: #6f42c1;}');
68
- injector.register('css', 'body {\n color: #abc;\n}\n');
69
- injector.register('css', {env: 'light', value: 'a{--color: #bbb;}'});
70
- injector.register('css', {env: 'light', value: 'book{--color: #aaa;}'});
71
-
72
- injector.get('headend').text().should.eql('<link rel="stylesheet" type="text/css" href="/css/injector/main.css" /><link rel="preload" as="style" href="/css/injector/light.css" />');
73
-
74
- let exec = cssGenerator(injector, 'default');
75
- return exec()
76
- .then(result => {
77
- result.should.eql('a{--color:#6f42c1}body{color:#abc}');
78
- exec = cssGenerator(injector, 'light');
79
- return exec();
80
- })
81
- .then(result => {
82
- result.should.eql('a{--color:#bbb}book{--color:#aaa}');
83
- });
84
- });
85
-
86
- });
@@ -1,36 +0,0 @@
1
- 'use strict';
2
-
3
- require('chai').should();
4
- const Hexo = require('hexo');
5
- const Injector = require('../../../lib/injector');
6
- const jsGenerator = require('../../../lib/bundle/js-generator');
7
- const { resolve } = require('path');
8
-
9
- describe('JS Bundler', () => {
10
- it('basic', () => {
11
- const hexo = new Hexo();
12
- const injector = new Injector(hexo);
13
- require('../../../lib/bundle/js-bundle')(hexo, injector);
14
- injector.register('js', 'var a=1;');
15
- injector.register('js', 'var b=1;');
16
-
17
- injector.get('bodyend').text().should.eql('<script src="/js/injector.js"></script>');
18
- const exec = jsGenerator(injector);
19
- return exec().then(result => {
20
- result.should.eql('var a=1,b=1;');
21
- });
22
- });
23
-
24
- it('v0.2 scheme', () => {
25
- const hexo = new Hexo();
26
- const injector = new Injector(hexo);
27
- require('../../../lib/bundle/js-bundle')(hexo, injector);
28
- injector.register('js', { path: resolve(__dirname, 'test.js') });
29
- injector.register('js', { text: () => 'var b=1;' });
30
- const exec = jsGenerator(injector);
31
- return exec().then(result => {
32
- result.should.eql('var a=1,b=1;');
33
- });
34
- });
35
-
36
- });
@@ -1,3 +0,0 @@
1
- .book1 {
2
- color: aqua;
3
- }
@@ -1,5 +0,0 @@
1
- /* eslint-disable semi */
2
- /* eslint-disable no-unused-vars */
3
- /* eslint-disable no-var */
4
- /* eslint-disable strict */
5
- var a = 1
@@ -1,45 +0,0 @@
1
- 'use strict';
2
-
3
- require('chai').should();
4
- const Injector = require('../../../lib/injector');
5
- const Hexo = require('hexo');
6
- const hexo = new Hexo();
7
- const injectorHelper = require('../../../lib/helper/injector');
8
-
9
- describe('injector', () => {
10
-
11
- it('injector(point).text()', () => {
12
- const injector = new Injector(hexo);
13
- injector.register('body-start', 'xx');
14
- injector.register('head-start', 'ww');
15
- injector.register('head-end', 'cc');
16
- injector.register('body-end', 'a');
17
- injector.register('body end', 'b');
18
- injector.register('bodyend', 'c');
19
- injector.register('body_end', 'd');
20
- const result = injectorHelper(injector)('body-end').text();
21
- injector.config.injector_point_bodyend.should.be.true;
22
- result.should.eql('abcd');
23
- });
24
-
25
- it('use injector(point).text() in home', () => {
26
- const injector = new Injector(hexo);
27
- injector.register('body-end', 'a');
28
- injector.register('body-end', 'b', 'home');
29
- injector.register('body-end', 'v', injector.is('post'));
30
- const result = injectorHelper(injector, {page: {__index: true}})('body-end').text();
31
- injector.config.injector_point_bodyend.should.be.true;
32
- result.should.eql('ab');
33
- });
34
-
35
- it('use injector(point).text() in post', () => {
36
- const injector = new Injector(hexo);
37
- injector.register('body-end', 'a');
38
- injector.register('body-end', 'b', 'home');
39
- injector.register('body-end', 'v', injector.is('post'));
40
- const result = injectorHelper(injector, {page: {__post: true}})('body-end').text();
41
- injector.config.injector_point_bodyend.should.be.true;
42
- result.should.eql('av');
43
- });
44
-
45
- });
@@ -1,69 +0,0 @@
1
- 'use strict';
2
-
3
- require('chai').should();
4
- const Injector = require('../../../lib/injector');
5
- const Hexo = require('hexo');
6
- const hexo = new Hexo();
7
- const nextInjectHelper = require('../../../lib/helper/next-inject');
8
-
9
- hexo.theme.config = {
10
- injects: {
11
- 'head': [],
12
- 'header': [],
13
- 'sidebar': [],
14
- 'postMeta': [],
15
- 'postBodyEnd': [],
16
- 'footer': [],
17
- 'bodyEnd': [],
18
- 'comment': []
19
- }
20
- };
21
-
22
- describe('next-inject', () => {
23
-
24
- it('next_inject(point)', () => {
25
- const injector = new Injector(hexo);
26
- injector.register('body-start', 'xx');
27
- injector.register('head-start', 'ww');
28
- injector.register('head-end', 'cc');
29
- injector.register('body-end', 'a');
30
- injector.register('body end', 'b');
31
- injector.register('bodyend', 'c');
32
- injector.register('body_end', 'd');
33
- const result = nextInjectHelper(injector, hexo)('bodyEnd');
34
- injector.config.injector_point_bodyend.should.be.true;
35
- result.should.eql('abcd');
36
- });
37
-
38
- it('use next_inject(point) in home', () => {
39
- const injector = new Injector(hexo);
40
- injector.register('body-end', 'a');
41
- injector.register('body-end', 'b', 'home');
42
- injector.register('body-end', 'v', injector.is('post'));
43
- const result = nextInjectHelper(injector, Object.assign({page: {__index: true}}, hexo))('bodyEnd');
44
- injector.config.injector_point_bodyend.should.be.true;
45
- result.should.eql('ab');
46
- });
47
-
48
- it('use next_inject(point) in post', () => {
49
- const injector = new Injector(hexo);
50
- injector.register('body-end', 'a');
51
- injector.register('body-end', 'b', 'home');
52
- injector.register('body-end', 'v', injector.is('post'));
53
- const result = nextInjectHelper(injector, Object.assign({page: {__post: true}}, hexo))('bodyEnd');
54
- injector.config.injector_point_bodyend.should.be.true;
55
- result.should.eql('av');
56
- });
57
-
58
- it('next_inject(head) include head and head-end', () => {
59
- const injector = new Injector(hexo);
60
- injector.register('head', 'a');
61
- injector.register('body-end', 'b');
62
- injector.register('head-end', 'c');
63
- const result = nextInjectHelper(injector, Object.assign({page: {__post: true}}, hexo))('head');
64
- injector.config.injector_point_head.should.be.true;
65
- injector.config.injector_point_headend.should.be.true;
66
- result.should.eql('ac');
67
- });
68
-
69
- });