hexo-adsense 1.0.21 → 1.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +20 -6
  3. package/lib/index.js +8 -1
  4. package/lib/source/adblock.css +2 -83
  5. package/lib/source/adblock.js +1 -31
  6. package/lib/source/article-ads.css +2 -11
  7. package/lib/source/article-ads.js +1 -270
  8. package/lib/source/blogger-redirect.html +1 -14
  9. package/lib/source/https.js +1 -4
  10. package/lib/src/article-ads.d.ts +1 -1
  11. package/lib/src/article-ads.js +6 -6
  12. package/lib/src/config.d.ts +12 -19
  13. package/lib/src/config.js +3 -5
  14. package/lib/src/utils.d.ts +9 -1
  15. package/lib/src/utils.js +2 -2
  16. package/package.json +20 -5
  17. package/packages/hexo-cli-extras/.eslintrc +13 -0
  18. package/packages/hexo-cli-extras/LICENSE.md +20 -0
  19. package/packages/hexo-cli-extras/README.md +146 -0
  20. package/packages/hexo-cli-extras/docs/basic.gif +0 -0
  21. package/packages/hexo-cli-extras/docs/gui.gif +0 -0
  22. package/packages/hexo-cli-extras/docs/remove.png +0 -0
  23. package/packages/hexo-cli-extras/docs/rename.png +0 -0
  24. package/packages/hexo-cli-extras/index.js +48 -0
  25. package/packages/hexo-cli-extras/lib/edit.js +209 -0
  26. package/packages/hexo-cli-extras/lib/env.js +52 -0
  27. package/packages/hexo-cli-extras/lib/extensions.js +23 -0
  28. package/packages/hexo-cli-extras/lib/integrate.js +87 -0
  29. package/packages/hexo-cli-extras/lib/isolate.js +179 -0
  30. package/packages/hexo-cli-extras/lib/remove.js +145 -0
  31. package/packages/hexo-cli-extras/lib/rename.js +171 -0
  32. package/packages/hexo-cli-extras/package.json +34 -0
  33. package/packages/hexo-extend-injector2/.eslintrc +4 -0
  34. package/packages/hexo-extend-injector2/.github/workflows/linter.yml +27 -0
  35. package/packages/hexo-extend-injector2/.github/workflows/tester.yml +24 -0
  36. package/packages/hexo-extend-injector2/.vscode/settings.json +10 -0
  37. package/packages/hexo-extend-injector2/LICENSE +165 -0
  38. package/packages/hexo-extend-injector2/README-ZH.md +189 -0
  39. package/packages/hexo-extend-injector2/README.md +191 -0
  40. package/packages/hexo-extend-injector2/USAGE.md +38 -0
  41. package/packages/hexo-extend-injector2/index.js +13 -0
  42. package/packages/hexo-extend-injector2/lib/bundle/css-bundle.js +79 -0
  43. package/packages/hexo-extend-injector2/lib/bundle/css-generator.js +13 -0
  44. package/packages/hexo-extend-injector2/lib/bundle/handle-data-pre.js +29 -0
  45. package/packages/hexo-extend-injector2/lib/bundle/js-bundle.js +42 -0
  46. package/packages/hexo-extend-injector2/lib/bundle/js-generator.js +10 -0
  47. package/packages/hexo-extend-injector2/lib/default-config.js +52 -0
  48. package/packages/hexo-extend-injector2/lib/filter.js +24 -0
  49. package/packages/hexo-extend-injector2/lib/helper/injector.js +6 -0
  50. package/packages/hexo-extend-injector2/lib/helper/next-inject.js +14 -0
  51. package/packages/hexo-extend-injector2/lib/injector.js +128 -0
  52. package/packages/hexo-extend-injector2/lib/load.js +45 -0
  53. package/packages/hexo-extend-injector2/lib/next-point.js +19 -0
  54. package/packages/hexo-extend-injector2/lib/next.js +87 -0
  55. package/packages/hexo-extend-injector2/lib/order.js +9 -0
  56. package/packages/hexo-extend-injector2/package.json +49 -0
  57. package/packages/hexo-extend-injector2/renovate.json +6 -0
  58. package/packages/hexo-extend-injector2/test/.eslintrc +3 -0
  59. package/packages/hexo-extend-injector2/test/index.js +18 -0
  60. package/packages/hexo-extend-injector2/test/lib/bundle/bundle-css.js +86 -0
  61. package/packages/hexo-extend-injector2/test/lib/bundle/bundle-js.js +36 -0
  62. package/packages/hexo-extend-injector2/test/lib/bundle/test.css +3 -0
  63. package/packages/hexo-extend-injector2/test/lib/bundle/test.js +5 -0
  64. package/packages/hexo-extend-injector2/test/lib/helper/injector.js +45 -0
  65. package/packages/hexo-extend-injector2/test/lib/helper/next-inject.js +69 -0
  66. package/packages/hexo-extend-injector2/test/lib/hexo-compatible.js +250 -0
  67. package/packages/hexo-extend-injector2/test/lib/hexo-injector.js +37 -0
  68. package/packages/hexo-extend-injector2/test/lib/injector.js +93 -0
  69. package/packages/memoize/CHANGELOG.md +82 -0
  70. package/packages/memoize/CHANGES +124 -0
  71. package/packages/memoize/LICENSE +15 -0
  72. package/packages/memoize/README.md +503 -0
  73. package/packages/memoize/ext/async.js +154 -0
  74. package/packages/memoize/ext/dispose.js +33 -0
  75. package/packages/memoize/ext/max-age.js +90 -0
  76. package/packages/memoize/ext/max.js +27 -0
  77. package/packages/memoize/ext/promise.js +147 -0
  78. package/packages/memoize/ext/ref-counter.js +48 -0
  79. package/packages/memoize/index.js +34 -0
  80. package/packages/memoize/lib/configure-map.js +182 -0
  81. package/packages/memoize/lib/methods.js +32 -0
  82. package/packages/memoize/lib/registered-extensions.js +1 -0
  83. package/packages/memoize/lib/resolve-length.js +15 -0
  84. package/packages/memoize/lib/resolve-normalize.js +17 -0
  85. package/packages/memoize/lib/resolve-resolve.js +21 -0
  86. package/packages/memoize/lib/weak.js +134 -0
  87. package/packages/memoize/methods-plain.js +3 -0
  88. package/packages/memoize/methods.js +3 -0
  89. package/packages/memoize/normalizers/get-1.js +29 -0
  90. package/packages/memoize/normalizers/get-fixed.js +71 -0
  91. package/packages/memoize/normalizers/get-primitive-fixed.js +16 -0
  92. package/packages/memoize/normalizers/get.js +90 -0
  93. package/packages/memoize/normalizers/primitive.js +9 -0
  94. package/packages/memoize/package.json +60 -0
  95. package/packages/memoize/plain.js +37 -0
  96. package/packages/memoize/profile.js +107 -0
  97. package/packages/memoize/repository.md +1 -0
  98. package/packages/memoize/weak-plain.js +3 -0
  99. package/packages/memoize/weak.js +3 -0
@@ -0,0 +1,29 @@
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
+ };
@@ -0,0 +1,42 @@
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
+ };
@@ -0,0 +1,10 @@
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
+ };
@@ -0,0 +1,52 @@
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
+ };
@@ -0,0 +1,24 @@
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;
@@ -0,0 +1,6 @@
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
+ };
@@ -0,0 +1,14 @@
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
+ };
@@ -0,0 +1,128 @@
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;
@@ -0,0 +1,45 @@
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;
@@ -0,0 +1,19 @@
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
+ };
@@ -0,0 +1,87 @@
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
+ };
@@ -0,0 +1,9 @@
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
+ };
@@ -0,0 +1,49 @@
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
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": [
3
+ "config:base",
4
+ ":preserveSemverRanges"
5
+ ]
6
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "hexo/test"
3
+ }
@@ -0,0 +1,18 @@
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
+ });
@@ -0,0 +1,86 @@
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
+ });
@@ -0,0 +1,36 @@
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
+ });
@@ -0,0 +1,3 @@
1
+ .book1 {
2
+ color: aqua;
3
+ }