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.
Files changed (157) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/LICENSE +0 -0
  3. package/dist/index.cjs +757 -0
  4. package/dist/index.d.cts +2 -0
  5. package/dist/index.d.mts +2 -0
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.js +740 -0
  8. package/dist/index.mjs +740 -0
  9. package/dist/source/adblock.css +2 -0
  10. package/{lib → dist}/source/adblock.js +0 -0
  11. package/{lib → dist}/source/article-ads.css +0 -0
  12. package/dist/source/article-ads.js +1 -0
  13. package/{lib/source/article-ads.js → dist/source/article-ads.old.js} +0 -0
  14. package/{lib → dist}/source/blogger-redirect.html +0 -0
  15. package/{lib → dist}/source/https.js +0 -0
  16. package/{lib → dist}/source/in_article_ads_test.html +0 -0
  17. package/package.json +122 -37
  18. package/{README.md → readme.md} +29 -11
  19. package/lib/index.d.ts +0 -1
  20. package/lib/index.js +0 -85
  21. package/lib/packages/hexo-cli-extras/lib/env.d.ts +0 -3
  22. package/lib/packages/hexo-cli-extras/lib/env.js +0 -49
  23. package/lib/packages/hexo-extend-injector2/index.d.ts +0 -2
  24. package/lib/packages/hexo-extend-injector2/index.js +0 -12
  25. package/lib/packages/hexo-extend-injector2/lib/bundle/css-bundle.d.ts +0 -2
  26. package/lib/packages/hexo-extend-injector2/lib/bundle/css-bundle.js +0 -64
  27. package/lib/packages/hexo-extend-injector2/lib/bundle/css-generator.d.ts +0 -2
  28. package/lib/packages/hexo-extend-injector2/lib/bundle/css-generator.js +0 -12
  29. package/lib/packages/hexo-extend-injector2/lib/bundle/handle-data-pre.d.ts +0 -2
  30. package/lib/packages/hexo-extend-injector2/lib/bundle/handle-data-pre.js +0 -28
  31. package/lib/packages/hexo-extend-injector2/lib/bundle/js-bundle.d.ts +0 -2
  32. package/lib/packages/hexo-extend-injector2/lib/bundle/js-bundle.js +0 -32
  33. package/lib/packages/hexo-extend-injector2/lib/bundle/js-generator.d.ts +0 -2
  34. package/lib/packages/hexo-extend-injector2/lib/bundle/js-generator.js +0 -8
  35. package/lib/packages/hexo-extend-injector2/lib/default-config.d.ts +0 -39
  36. package/lib/packages/hexo-extend-injector2/lib/default-config.js +0 -46
  37. package/lib/packages/hexo-extend-injector2/lib/filter.d.ts +0 -2
  38. package/lib/packages/hexo-extend-injector2/lib/filter.js +0 -22
  39. package/lib/packages/hexo-extend-injector2/lib/helper/injector.d.ts +0 -2
  40. package/lib/packages/hexo-extend-injector2/lib/helper/injector.js +0 -5
  41. package/lib/packages/hexo-extend-injector2/lib/helper/next-inject.d.ts +0 -2
  42. package/lib/packages/hexo-extend-injector2/lib/helper/next-inject.js +0 -12
  43. package/lib/packages/hexo-extend-injector2/lib/injector.d.ts +0 -29
  44. package/lib/packages/hexo-extend-injector2/lib/injector.js +0 -125
  45. package/lib/packages/hexo-extend-injector2/lib/load.d.ts +0 -3
  46. package/lib/packages/hexo-extend-injector2/lib/load.js +0 -37
  47. package/lib/packages/hexo-extend-injector2/lib/next-point.d.ts +0 -2
  48. package/lib/packages/hexo-extend-injector2/lib/next-point.js +0 -18
  49. package/lib/packages/hexo-extend-injector2/lib/next.d.ts +0 -2
  50. package/lib/packages/hexo-extend-injector2/lib/next.js +0 -99
  51. package/lib/packages/hexo-extend-injector2/lib/order.d.ts +0 -5
  52. package/lib/packages/hexo-extend-injector2/lib/order.js +0 -8
  53. package/lib/source/adblock.css +0 -2
  54. package/lib/src/article-ads.d.ts +0 -20
  55. package/lib/src/article-ads.js +0 -304
  56. package/lib/src/checkLocalHost.d.ts +0 -10
  57. package/lib/src/checkLocalHost.js +0 -37
  58. package/lib/src/config.d.ts +0 -13
  59. package/lib/src/config.js +0 -42
  60. package/lib/src/html-parser.d.ts +0 -9
  61. package/lib/src/html-parser.js +0 -26
  62. package/lib/src/log.d.ts +0 -1
  63. package/lib/src/log.js +0 -11
  64. package/lib/src/logger.d.ts +0 -3
  65. package/lib/src/logger.js +0 -25
  66. package/lib/src/md5.d.ts +0 -2
  67. package/lib/src/md5.js +0 -165
  68. package/lib/src/safestringify.d.ts +0 -2
  69. package/lib/src/safestringify.js +0 -125
  70. package/lib/src/utils.d.ts +0 -31
  71. package/lib/src/utils.js +0 -159
  72. package/lib/src/versionParser.d.ts +0 -27
  73. package/lib/src/versionParser.js +0 -40
  74. package/packages/hexo-cli-extras/.eslintrc +0 -13
  75. package/packages/hexo-cli-extras/LICENSE.md +0 -20
  76. package/packages/hexo-cli-extras/README.md +0 -146
  77. package/packages/hexo-cli-extras/docs/basic.gif +0 -0
  78. package/packages/hexo-cli-extras/docs/gui.gif +0 -0
  79. package/packages/hexo-cli-extras/docs/remove.png +0 -0
  80. package/packages/hexo-cli-extras/docs/rename.png +0 -0
  81. package/packages/hexo-cli-extras/index.js +0 -48
  82. package/packages/hexo-cli-extras/lib/edit.js +0 -209
  83. package/packages/hexo-cli-extras/lib/env.js +0 -52
  84. package/packages/hexo-cli-extras/lib/extensions.js +0 -23
  85. package/packages/hexo-cli-extras/lib/integrate.js +0 -87
  86. package/packages/hexo-cli-extras/lib/isolate.js +0 -179
  87. package/packages/hexo-cli-extras/lib/remove.js +0 -145
  88. package/packages/hexo-cli-extras/lib/rename.js +0 -171
  89. package/packages/hexo-cli-extras/package.json +0 -34
  90. package/packages/hexo-extend-injector2/.eslintrc +0 -4
  91. package/packages/hexo-extend-injector2/.github/workflows/linter.yml +0 -27
  92. package/packages/hexo-extend-injector2/.github/workflows/tester.yml +0 -24
  93. package/packages/hexo-extend-injector2/.vscode/settings.json +0 -10
  94. package/packages/hexo-extend-injector2/LICENSE +0 -165
  95. package/packages/hexo-extend-injector2/README-ZH.md +0 -189
  96. package/packages/hexo-extend-injector2/README.md +0 -191
  97. package/packages/hexo-extend-injector2/USAGE.md +0 -38
  98. package/packages/hexo-extend-injector2/index.js +0 -14
  99. package/packages/hexo-extend-injector2/lib/bundle/css-bundle.js +0 -79
  100. package/packages/hexo-extend-injector2/lib/bundle/css-generator.js +0 -13
  101. package/packages/hexo-extend-injector2/lib/bundle/handle-data-pre.js +0 -29
  102. package/packages/hexo-extend-injector2/lib/bundle/js-bundle.js +0 -42
  103. package/packages/hexo-extend-injector2/lib/bundle/js-generator.js +0 -10
  104. package/packages/hexo-extend-injector2/lib/default-config.js +0 -52
  105. package/packages/hexo-extend-injector2/lib/filter.js +0 -24
  106. package/packages/hexo-extend-injector2/lib/helper/injector.js +0 -6
  107. package/packages/hexo-extend-injector2/lib/helper/next-inject.js +0 -14
  108. package/packages/hexo-extend-injector2/lib/injector.js +0 -128
  109. package/packages/hexo-extend-injector2/lib/load.js +0 -45
  110. package/packages/hexo-extend-injector2/lib/next-point.js +0 -19
  111. package/packages/hexo-extend-injector2/lib/next.js +0 -87
  112. package/packages/hexo-extend-injector2/lib/order.js +0 -9
  113. package/packages/hexo-extend-injector2/package.json +0 -49
  114. package/packages/hexo-extend-injector2/renovate.json +0 -6
  115. package/packages/hexo-extend-injector2/test/.eslintrc +0 -3
  116. package/packages/hexo-extend-injector2/test/index.js +0 -18
  117. package/packages/hexo-extend-injector2/test/lib/bundle/bundle-css.js +0 -86
  118. package/packages/hexo-extend-injector2/test/lib/bundle/bundle-js.js +0 -36
  119. package/packages/hexo-extend-injector2/test/lib/bundle/test.css +0 -3
  120. package/packages/hexo-extend-injector2/test/lib/bundle/test.js +0 -5
  121. package/packages/hexo-extend-injector2/test/lib/helper/injector.js +0 -45
  122. package/packages/hexo-extend-injector2/test/lib/helper/next-inject.js +0 -69
  123. package/packages/hexo-extend-injector2/test/lib/hexo-compatible.js +0 -250
  124. package/packages/hexo-extend-injector2/test/lib/hexo-injector.js +0 -37
  125. package/packages/hexo-extend-injector2/test/lib/injector.js +0 -93
  126. package/packages/memoize/CHANGELOG.md +0 -82
  127. package/packages/memoize/CHANGES +0 -124
  128. package/packages/memoize/LICENSE +0 -15
  129. package/packages/memoize/README.md +0 -503
  130. package/packages/memoize/ext/async.js +0 -154
  131. package/packages/memoize/ext/dispose.js +0 -33
  132. package/packages/memoize/ext/max-age.js +0 -90
  133. package/packages/memoize/ext/max.js +0 -27
  134. package/packages/memoize/ext/promise.js +0 -147
  135. package/packages/memoize/ext/ref-counter.js +0 -48
  136. package/packages/memoize/index.js +0 -34
  137. package/packages/memoize/lib/configure-map.js +0 -182
  138. package/packages/memoize/lib/methods.js +0 -32
  139. package/packages/memoize/lib/registered-extensions.js +0 -1
  140. package/packages/memoize/lib/resolve-length.js +0 -15
  141. package/packages/memoize/lib/resolve-normalize.js +0 -17
  142. package/packages/memoize/lib/resolve-resolve.js +0 -21
  143. package/packages/memoize/lib/weak.js +0 -134
  144. package/packages/memoize/methods-plain.js +0 -3
  145. package/packages/memoize/methods.js +0 -3
  146. package/packages/memoize/normalizers/get-1.js +0 -29
  147. package/packages/memoize/normalizers/get-fixed.js +0 -71
  148. package/packages/memoize/normalizers/get-primitive-fixed.js +0 -16
  149. package/packages/memoize/normalizers/get.js +0 -90
  150. package/packages/memoize/normalizers/primitive.js +0 -9
  151. package/packages/memoize/package.json +0 -60
  152. package/packages/memoize/plain.js +0 -37
  153. package/packages/memoize/profile.js +0 -107
  154. package/packages/memoize/repository.md +0 -1
  155. package/packages/memoize/weak-plain.js +0 -3
  156. package/packages/memoize/weak.js +0 -3
  157. package/unused.md +0 -12
package/dist/index.mjs ADDED
@@ -0,0 +1,740 @@
1
+ // hexo-adsense 2.0.0 by Dimas Lanjaka <dimaslanjaka@gmail.com> (https://github.com/dimaslanjaka)
2
+
3
+ // import nodeUrl from 'node:url';
4
+ // import nodePath from 'path';
5
+ // const __filename = nodeUrl.fileURLToPath(import.meta.url);
6
+ // const __dirname = nodePath.dirname(__filename);
7
+ import fs$2 from 'fs-extra';
8
+ import assign from 'object-assign';
9
+ import path from 'path';
10
+ import * as prettier from 'prettier';
11
+ import { fileURLToPath } from 'url';
12
+ import { globSync } from 'glob';
13
+ import fs$1 from 'hexo-fs';
14
+ import fs from 'fs';
15
+ import require$$1 from 'hexo-log';
16
+ import require$$3 from 'util';
17
+ import { minimatch } from 'minimatch';
18
+ import { memoize } from 'underscore';
19
+ import minimist from 'minimist';
20
+ import ansiColors from 'ansi-colors';
21
+ import { debug, normalizePath, normalizePathUnix } from 'sbg-utility';
22
+ import 'bluebird';
23
+
24
+ function getDefaultExportFromCjs (x) {
25
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
26
+ }
27
+
28
+ var src = {};
29
+
30
+ var name = "hexo-is";
31
+ var version = "2.0.0";
32
+ var description = "Determine whether hexo is";
33
+ var main = "dist/index.js";
34
+ var types = "dist/index.d.ts";
35
+ var type = "module";
36
+ var module = "dist/index.mjs";
37
+ var exports = {
38
+ ".": {
39
+ require: {
40
+ "default": "./dist/index.cjs",
41
+ types: "./dist/index.d.ts"
42
+ },
43
+ "import": {
44
+ "default": "./dist/index.mjs",
45
+ types: "./dist/index.d.mts"
46
+ }
47
+ }
48
+ };
49
+ var files = [
50
+ "dist/"
51
+ ];
52
+ var scripts = {
53
+ test: "echo \"Error: no test specified\" && exit 1",
54
+ build: "tsc && rollup -c",
55
+ clean: "rimraf dist && npm run build",
56
+ hook: "ts-node hook.ts",
57
+ postbuild: "node packer.js",
58
+ update: "npx npm-check-updates -u -x chalk",
59
+ pack: "node packer.cjs --yarn"
60
+ };
61
+ var keywords = [
62
+ ];
63
+ var repository = {
64
+ type: "git",
65
+ url: "https://github.com/dimaslanjaka/hexo-is.git"
66
+ };
67
+ var homepage = "https://github.com/dimaslanjaka/hexo-seo/tree/master/packages/hexo-is#readme";
68
+ var author = {
69
+ email: "dimaslanjaka@gmail.com",
70
+ name: "Dimas Lanjaka",
71
+ url: "https://github.com/dimaslanjaka"
72
+ };
73
+ var license = "MIT";
74
+ var workspaces = [
75
+ "test/demo",
76
+ "test/demo/themes/*"
77
+ ];
78
+ var dependencies = {
79
+ "fs-extra": "^11.2.0",
80
+ "hexo-log": "^4.1.0",
81
+ minimatch: "^10.0.1",
82
+ "sbg-utility": "^2.0.5",
83
+ upath: "^2.0.1"
84
+ };
85
+ var devDependencies = {
86
+ "@rollup/plugin-commonjs": "^28.0.1",
87
+ "@rollup/plugin-json": "^6.1.0",
88
+ "@rollup/plugin-node-resolve": "^15.3.0",
89
+ "@types/gulp": "^4.0.17",
90
+ "@types/node": "^22.8.4",
91
+ "cross-spawn": "https://github.com/dimaslanjaka/node-cross-spawn/raw/private/release/cross-spawn.tgz",
92
+ "git-command-helper": "^2.0.2",
93
+ gulp: "^5.0.0",
94
+ "gulp-cli": "^3.0.0",
95
+ hexo: "^7.3.0",
96
+ nodemon: "^3.1.7",
97
+ rimraf: "^6.0.1",
98
+ rollup: "^4.24.3",
99
+ "rollup-plugin-dts": "^6.1.1",
100
+ "ts-node": "^10.9.2",
101
+ typescript: "^5.6.3"
102
+ };
103
+ var resolutions = {
104
+ "@types/git-command-helper": "https://github.com/dimaslanjaka/git-command-helper/raw/pre-release/release/git-command-helper.tgz",
105
+ "@types/hexo": "https://github.com/dimaslanjaka/hexo/raw/monorepo-v7/releases/hexo.tgz",
106
+ "binary-collections": "https://github.com/dimaslanjaka/bin/raw/fcd1121/releases/bin.tgz",
107
+ "cross-spawn": "https://github.com/dimaslanjaka/node-cross-spawn/raw/private/release/cross-spawn.tgz",
108
+ "git-command-helper": "https://github.com/dimaslanjaka/git-command-helper/raw/pre-release/release/git-command-helper.tgz",
109
+ hexo: "https://github.com/dimaslanjaka/hexo/raw/monorepo-v7/releases/hexo.tgz",
110
+ "hexo-asset-link": "https://github.com/dimaslanjaka/hexo/raw/monorepo-v7/releases/hexo-asset-link.tgz",
111
+ "hexo-cli": "https://github.com/dimaslanjaka/hexo/raw/monorepo-v7/releases/hexo-cli.tgz",
112
+ "hexo-front-matter": "https://github.com/dimaslanjaka/hexo/raw/monorepo-v7/releases/hexo-front-matter.tgz",
113
+ "hexo-generator-redirect": "https://github.com/dimaslanjaka/hexo-generator-redirect/raw/0885394/release/hexo-generator-redirect.tgz",
114
+ "hexo-log": "https://github.com/dimaslanjaka/hexo/raw/monorepo-v7/releases/hexo-log.tgz",
115
+ "hexo-post-parser": "https://github.com/dimaslanjaka/hexo-post-parser/raw/8c4e98159e4407b77e1c25e028c1fd4a0073a8e3/release/hexo-post-parser.tgz",
116
+ "hexo-renderers": "https://github.com/dimaslanjaka/hexo-renderers/raw/add4a2491075dd85281a5dc0c48b74a7ce51d987/release/hexo-renderers.tgz",
117
+ "hexo-seo": "https://github.com/dimaslanjaka/hexo-seo/raw/f4cf27fbc7de2b831462d3b26cf70ece2499d15b/release/hexo-seo.tgz",
118
+ "hexo-server": "https://github.com/dimaslanjaka/hexo/raw/monorepo-v7/releases/hexo-server.tgz",
119
+ "hexo-shortcodes": "https://github.com/dimaslanjaka/hexo-shortcodes/raw/f70a1c0/release/hexo-shortcodes.tgz",
120
+ "hexo-util": "https://github.com/dimaslanjaka/hexo/raw/monorepo-v7/releases/hexo-util.tgz",
121
+ "instant-indexing": "https://github.com/dimaslanjaka/static-blog-generator/raw/master/packages/instant-indexing/release/instant-indexing.tgz",
122
+ "markdown-it": "https://github.com/dimaslanjaka/markdown-it/raw/17ccc825cbb3e4c6d59edada5f6d93f27075d752/release/markdown-it.tgz",
123
+ "nodejs-package-types": "https://github.com/dimaslanjaka/nodejs-package-types/raw/a2e797bc27975cba20ef4c87547841e6341bfcf4/release/nodejs-package-types.tgz",
124
+ "sbg-api": "https://github.com/dimaslanjaka/static-blog-generator/raw/74a402210be05e3452a386f90b80521e1182a724/packages/sbg-api/release/sbg-api.tgz",
125
+ "sbg-cli": "https://github.com/dimaslanjaka/static-blog-generator/raw/0164b0d2e4ba5453890af8ec4863b2a09e043815/packages/sbg-cli/release/sbg-cli.tgz",
126
+ "sbg-server": "https://github.com/dimaslanjaka/static-blog-generator/raw/master/packages/sbg-server/release/sbg-server.tgz",
127
+ "sbg-utility": "https://github.com/dimaslanjaka/static-blog-generator/raw/c7e82cae850b9fd6c1829ff6d30ef3ee8987019b/packages/sbg-utility/release/sbg-utility.tgz",
128
+ "static-blog-generator": "https://github.com/dimaslanjaka/static-blog-generator/raw/master/packages/static-blog-generator/release/static-blog-generator.tgz",
129
+ warehouse: "https://github.com/dimaslanjaka/hexo/raw/monorepo-v7/releases/warehouse.tgz"
130
+ };
131
+ var packageManager = "yarn@4.5.1";
132
+ var require$$4 = {
133
+ name: name,
134
+ version: version,
135
+ description: description,
136
+ main: main,
137
+ types: types,
138
+ type: type,
139
+ module: module,
140
+ exports: exports,
141
+ files: files,
142
+ scripts: scripts,
143
+ keywords: keywords,
144
+ repository: repository,
145
+ homepage: homepage,
146
+ author: author,
147
+ license: license,
148
+ workspaces: workspaces,
149
+ dependencies: dependencies,
150
+ devDependencies: devDependencies,
151
+ resolutions: resolutions,
152
+ packageManager: packageManager
153
+ };
154
+
155
+ var is = {};
156
+
157
+ /* eslint-disable @typescript-eslint/no-this-alias */
158
+
159
+ var hasRequiredIs;
160
+
161
+ function requireIs () {
162
+ if (hasRequiredIs) return is;
163
+ hasRequiredIs = 1;
164
+ (function (exports) {
165
+ Object.defineProperty(exports, "__esModule", { value: true });
166
+ exports.tag = exports.category = exports.month = exports.year = exports.archive = exports.page = exports.post = exports.home = exports.current = void 0;
167
+ exports.default = internalIs;
168
+ function isCurrentHelper(path, strict) {
169
+ if (path === void 0) { path = "/"; }
170
+ var currentPath = this.path.replace(/^[^/].*/, "/$&");
171
+ if (strict) {
172
+ if (path.endsWith("/"))
173
+ path += "index.html";
174
+ path = path.replace(/^[^/].*/, "/$&");
175
+ return currentPath === path;
176
+ }
177
+ path = path.replace(/\/index\.html$/, "/");
178
+ if (path === "/")
179
+ return currentPath === "/index.html";
180
+ path = path.replace(/^[^/].*/, "/$&");
181
+ return currentPath.startsWith(path);
182
+ }
183
+ function isHomeHelper() {
184
+ return Boolean(this.page.__index);
185
+ }
186
+ function isPostHelper() {
187
+ if (this.page) {
188
+ var src = this.page["full_source"] || "";
189
+ var layout = this.page.layout || "";
190
+ if (layout.startsWith("post"))
191
+ return true;
192
+ if (layout.startsWith("page"))
193
+ return false;
194
+ if (src !== "") {
195
+ return Boolean(this.page.__post) && src.includes("_posts");
196
+ }
197
+ }
198
+ return Boolean(this.page.__post);
199
+ }
200
+ function isPageHelper() {
201
+ if (this.page) {
202
+ var src = this.page["full_source"] || "";
203
+ var layout = this.page.layout || "";
204
+ if (layout.startsWith("post"))
205
+ return false;
206
+ if (layout.startsWith("page"))
207
+ return true;
208
+ if (src !== "") {
209
+ return Boolean(this.page.__post) && !src.includes("_posts");
210
+ }
211
+ }
212
+ return Boolean(this.page.__page);
213
+ }
214
+ function isArchiveHelper() {
215
+ return Boolean(this.page.archive);
216
+ }
217
+ function isYearHelper(year) {
218
+ var page = this.page;
219
+ if (!page.archive)
220
+ return false;
221
+ if (year) {
222
+ return page.year === year;
223
+ }
224
+ return Boolean(page.year);
225
+ }
226
+ function isMonthHelper(year, month) {
227
+ var page = this.page;
228
+ if (!page.archive)
229
+ return false;
230
+ if (year) {
231
+ if (month) {
232
+ return page.year === year && page.month === month;
233
+ }
234
+ return page.month === year;
235
+ }
236
+ return Boolean(page.year && page.month);
237
+ }
238
+ function isCategoryHelper(category) {
239
+ if (category) {
240
+ return this.page.category === category;
241
+ }
242
+ return Boolean(this.page.category);
243
+ }
244
+ function isTagHelper(tag) {
245
+ if (tag) {
246
+ return this.page.tag === tag;
247
+ }
248
+ return Boolean(this.page.tag);
249
+ }
250
+ exports.current = isCurrentHelper;
251
+ exports.home = isHomeHelper;
252
+ exports.post = isPostHelper;
253
+ exports.page = isPageHelper;
254
+ exports.archive = isArchiveHelper;
255
+ exports.year = isYearHelper;
256
+ exports.month = isMonthHelper;
257
+ exports.category = isCategoryHelper;
258
+ exports.tag = isTagHelper;
259
+ /**
260
+ * Custom function
261
+ * @param hexo
262
+ * @returns
263
+ */
264
+ function internalIs(hexo) {
265
+ var obj = {
266
+ current: false,
267
+ home: false,
268
+ post: false,
269
+ page: false,
270
+ archive: false,
271
+ year: false,
272
+ month: false,
273
+ category: false,
274
+ tag: false,
275
+ message: "try using second argument",
276
+ };
277
+ if (typeof hexo["page"] == "undefined")
278
+ return obj;
279
+ return {
280
+ current: exports.current.bind(hexo)(),
281
+ home: exports.home.bind(hexo)(),
282
+ post: exports.post.bind(hexo)(),
283
+ page: exports.page.bind(hexo)(),
284
+ archive: exports.archive.bind(hexo)(),
285
+ year: exports.year.bind(hexo)(),
286
+ month: exports.month.bind(hexo)(),
287
+ category: exports.category.bind(hexo)(),
288
+ tag: exports.tag.bind(hexo)(),
289
+ };
290
+ }
291
+ } (is));
292
+ return is;
293
+ }
294
+
295
+ var hasRequiredSrc;
296
+
297
+ function requireSrc () {
298
+ if (hasRequiredSrc) return src;
299
+ hasRequiredSrc = 1;
300
+ (function (exports) {
301
+ var __createBinding = (src && src.__createBinding) || (Object.create ? (function(o, m, k, k2) {
302
+ if (k2 === undefined) k2 = k;
303
+ var desc = Object.getOwnPropertyDescriptor(m, k);
304
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
305
+ desc = { enumerable: true, get: function() { return m[k]; } };
306
+ }
307
+ Object.defineProperty(o, k2, desc);
308
+ }) : (function(o, m, k, k2) {
309
+ if (k2 === undefined) k2 = k;
310
+ o[k2] = m[k];
311
+ }));
312
+ var __setModuleDefault = (src && src.__setModuleDefault) || (Object.create ? (function(o, v) {
313
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
314
+ }) : function(o, v) {
315
+ o["default"] = v;
316
+ });
317
+ var __importStar = (src && src.__importStar) || function (mod) {
318
+ if (mod && mod.__esModule) return mod;
319
+ var result = {};
320
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
321
+ __setModuleDefault(result, mod);
322
+ return result;
323
+ };
324
+ var __importDefault = (src && src.__importDefault) || function (mod) {
325
+ return (mod && mod.__esModule) ? mod : { "default": mod };
326
+ };
327
+ Object.defineProperty(exports, "__esModule", { value: true });
328
+ exports.hexoIs = void 0;
329
+ exports.hexoIsDump = hexoIsDump;
330
+ /* eslint-disable prefer-rest-params */
331
+ var fs$1 = __importStar(fs);
332
+ var hexo_log_1 = __importDefault(require$$1);
333
+ var path_1 = __importDefault(path);
334
+ var util_1 = __importDefault(require$$3);
335
+ var package_json_1 = __importDefault(require$$4);
336
+ var is_1 = __importDefault(requireIs());
337
+ var log = (0, hexo_log_1.default)({
338
+ debug: false,
339
+ silent: false,
340
+ });
341
+ /**
342
+ * @example
343
+ * // run inside plugin or theme event
344
+ * import hexoIs from 'hexo-is';
345
+ * const hexo = this;
346
+ * console.log(hexoIs(hexo)); // object or string
347
+ * @param hexo
348
+ * @returns
349
+ */
350
+ var hexoIs = function (hexo) {
351
+ if (typeof hexo === "undefined")
352
+ return;
353
+ if (typeof hexo["page"] != "undefined")
354
+ return (0, is_1.default)(hexo);
355
+ if (typeof hexo["type"] != "undefined") {
356
+ var ix = (0, is_1.default)(hexo);
357
+ if (typeof ix[hexo["type"]] != "undefined")
358
+ ix[hexo["type"]] = true;
359
+ return ix;
360
+ }
361
+ };
362
+ exports.hexoIs = hexoIs;
363
+ /**
364
+ * Dump variable to file
365
+ * @param toDump
366
+ */
367
+ function hexoIsDump(toDump, name) {
368
+ if (name === void 0) { name = ""; }
369
+ if (name.length > 0)
370
+ name = "-" + name;
371
+ var dump = util_1.default.inspect(toDump, { showHidden: true, depth: null });
372
+ var loc = path_1.default.join("tmp/hexo-is/dump" + name + ".txt");
373
+ if (!fs$1.existsSync(path_1.default.dirname(loc))) {
374
+ fs$1.mkdirSync(path_1.default.dirname(loc), { recursive: true });
375
+ }
376
+ fs$1.writeFileSync(loc, dump);
377
+ log.log("".concat(package_json_1.default.name, ": dump saved to: ").concat(path_1.default.resolve(loc)));
378
+ }
379
+ exports.default = exports.hexoIs;
380
+ } (src));
381
+ return src;
382
+ }
383
+
384
+ var srcExports = requireSrc();
385
+ var index = /*@__PURE__*/getDefaultExportFromCjs(srcExports);
386
+
387
+ const argv = minimist(process.argv.slice(2));
388
+ /**
389
+ * Check if the environment is production or development
390
+ * @param inHexo Hexo instance
391
+ * @returns Environment
392
+ */
393
+ const getEnv = memoize((inHexo) => {
394
+ const DEV = 'development';
395
+ const PRD = 'production';
396
+ // Check if --development flag is set
397
+ const arg = typeof argv['development'] === 'boolean' && argv['development'];
398
+ // Check if NODE_ENV is set to "development"
399
+ const env = process.env.NODE_ENV?.toLowerCase() === 'development';
400
+ // Determine if environment is development
401
+ const isDev = arg || env;
402
+ if (inHexo) {
403
+ if (isDev)
404
+ return DEV;
405
+ if (typeof inHexo.env.args.development === 'boolean' && inHexo.env.args.development)
406
+ return DEV;
407
+ if (inHexo.env.args._ && inHexo.env.args._.length > 0) {
408
+ for (const arg of inHexo.env.args._) {
409
+ if (arg === 's' || arg === 'server')
410
+ return DEV;
411
+ if (arg === 'd' || arg === 'deploy')
412
+ return PRD;
413
+ if (arg === 'g' || arg === 'generate')
414
+ return PRD;
415
+ }
416
+ }
417
+ }
418
+ return null;
419
+ });
420
+ /**
421
+ * Determine if the environment is development
422
+ * @param hexo Hexo instance
423
+ * @returns boolean
424
+ */
425
+ const isDev = memoize((hexo) => getEnv(hexo) === 'development');
426
+ /**
427
+ * Determine if the environment is production
428
+ * @param hexo Hexo instance
429
+ * @returns boolean
430
+ */
431
+ memoize((hexo) => getEnv(hexo) === 'production');
432
+ const defaultConfig = {
433
+ enable: true,
434
+ article_ads: [''].filter((v) => typeof v === 'string' && v.length > 0),
435
+ pub: '',
436
+ adblock: false,
437
+ https: false,
438
+ field: 'site',
439
+ type: 'javascript',
440
+ exclude: ['.gitignore'],
441
+ development: false
442
+ };
443
+ /**
444
+ * hexo-adsense config
445
+ * @param hexo
446
+ * @returns
447
+ */
448
+ function getHexoAdsenseConfig(hexo) {
449
+ if (typeof hexo.config.adsense !== 'undefined') {
450
+ if (typeof hexo.config.adsense === 'boolean') {
451
+ // fix when adsense: false
452
+ hexo.config.adsense = {};
453
+ hexo.config.adsense.enable = hexo.config.adsense;
454
+ }
455
+ const config = assign(defaultConfig, hexo.config.adsense);
456
+ config.development = defaultConfig.development = isDev(hexo);
457
+ return config;
458
+ }
459
+ return defaultConfig;
460
+ }
461
+
462
+ const logname = ansiColors.magentaBright('hexo-adsense');
463
+ const once = (function (...fn) {
464
+ let executed = false;
465
+ return function () {
466
+ if (!executed) {
467
+ executed = true;
468
+ // Do something
469
+ if (typeof fn[0] === 'function')
470
+ return fn[0]();
471
+ console.log(fn);
472
+ }
473
+ };
474
+ })();
475
+ function stack(msg) {
476
+ const logLineDetails = new Error().stack?.split('at ')[3].trim();
477
+ console.log('DEBUG', new Date().toUTCString(), logLineDetails, msg);
478
+ }
479
+ const defaultLogger = typeof hexo !== 'undefined' ? hexo.log : require$$1({ silent: false, debug: true });
480
+ const logger = {
481
+ stack,
482
+ once
483
+ };
484
+ const debugLog = function (...args) {
485
+ debug('hexo-adsense')(...args);
486
+ defaultLogger.debug(logname, ...args);
487
+ };
488
+ var logger$1 = Object.assign(defaultLogger, logger);
489
+
490
+ // ESM-compatible __dirname replacement
491
+ path.dirname(fileURLToPath(import.meta.url));
492
+ /**
493
+ * @param path0
494
+ * @param exclude
495
+ * @param hexo
496
+ * @returns boolean
497
+ */
498
+ const isIgnore = (path0, exclude, hexo) => {
499
+ if (exclude && !Array.isArray(exclude))
500
+ exclude = [exclude];
501
+ if (path0 && exclude && exclude.length) {
502
+ for (let i = 0, len = exclude.length; i < len; i++) {
503
+ const excludePattern = exclude[i];
504
+ if (hexo) {
505
+ const fromBase = normalizePathUnix(hexo.base_dir, excludePattern);
506
+ const fromSource = normalizePathUnix(hexo.source_dir, excludePattern);
507
+ if (minimatch(path0, fromSource))
508
+ return true;
509
+ if (minimatch(path0, fromBase))
510
+ return true;
511
+ }
512
+ if (minimatch(path0, excludePattern))
513
+ return true;
514
+ }
515
+ }
516
+ return false;
517
+ };
518
+ const tmpFolder = normalizePath(typeof hexo !== 'undefined' ? hexo.base_dir : process.cwd(), 'tmp/hexo-adsense');
519
+
520
+ // ESM-compatible __dirname replacement
521
+ const __dirname$1 = path.dirname(fileURLToPath(import.meta.url));
522
+ const adsContent = `<div hexo-adsense="ads-content">ADS_CODE_HERE</div>`;
523
+ String.prototype.joinpath = function (str) {
524
+ return path.join(this.toString(), str);
525
+ };
526
+ function parseConfig(hexo) {
527
+ return getHexoAdsenseConfig(hexo);
528
+ }
529
+ function articleAds(files, hexo) {
530
+ const base_dir = hexo.base_dir;
531
+ const source_dir = hexo.source_dir;
532
+ const isDevelopment = parseConfig(hexo).development;
533
+ const result = [];
534
+ files.forEach((file) => {
535
+ let html = '';
536
+ let tes = base_dir.joinpath(file);
537
+ if (fs$1.existsSync(tes)) {
538
+ html = fs$1.readFileSync(tes).toString();
539
+ }
540
+ else {
541
+ tes = source_dir.joinpath(file);
542
+ if (fs$1.existsSync(tes)) {
543
+ html = fs$1.readFileSync(tes).toString();
544
+ }
545
+ }
546
+ if (html.length > 0) {
547
+ if (isDevelopment) {
548
+ html = html.replace(/><\/ins>/gm, ` data-adtest="on"></ins>`);
549
+ }
550
+ html = html.replace(/\(adsbygoogle?\s*=?\s*window\.adsbygoogle?\s*\|\|?\s*\[\]\)\.push\({}\);/gm, '');
551
+ html = html.replace(/<script?.*src?.*adsbygoogle\b[^>]*>([\s\S]*?)<\/script>/gm, '');
552
+ result.push(adsContent.replace('ADS_CODE_HERE', html));
553
+ }
554
+ });
555
+ return result;
556
+ }
557
+ function filter_adshtml(hexo) {
558
+ const options = parseConfig(hexo);
559
+ let adshtml = [];
560
+ if (Array.isArray(options.article_ads)) {
561
+ // array of file paths
562
+ adshtml = options.article_ads;
563
+ }
564
+ else if (typeof options.article_ads === 'string') {
565
+ // single file path
566
+ adshtml = [options.article_ads];
567
+ }
568
+ else if (typeof options.article_ads === 'boolean') {
569
+ // scan source_dir/_data/hexo-adsense/*.html
570
+ adshtml = globSync([`${hexo.config.source_dir}/ads/**/*.html`, `${hexo.config.source_dir}/_data/hexo-adsense/**/*.html`], {
571
+ cwd: hexo.base_dir
572
+ });
573
+ }
574
+ if (adshtml.length > 0) {
575
+ adshtml = adshtml.filter((ads) => typeof ads === 'string' && ads.trim().length > 0);
576
+ if (adshtml.length > 0) {
577
+ adshtml = articleAds(adshtml, hexo);
578
+ }
579
+ }
580
+ return adshtml;
581
+ }
582
+ function filter_patterns(content, source_path, hexo) {
583
+ const options = parseConfig(hexo);
584
+ const excluded = isIgnore(source_path, options.exclude, hexo);
585
+ if (excluded) {
586
+ content = content.replace(/<script?.*src?.*adsbygoogle?\b[^>]*>([\s\S]*?)<\/script>/gm, '<!--hexo-adsense disabled on this page-->');
587
+ }
588
+ return {
589
+ content,
590
+ excluded
591
+ };
592
+ }
593
+ function after_post_render(data) {
594
+ const hexo = this;
595
+ const options = parseConfig(hexo);
596
+ const filterPattern = filter_patterns(data.content, getPageSource(data), hexo);
597
+ data.content = filterPattern.content;
598
+ if (filterPattern.excluded)
599
+ return data;
600
+ const adshtml = filter_adshtml(hexo);
601
+ if (adshtml.length < 1)
602
+ return data;
603
+ if (typeof data.adsense === 'boolean' && data.adsense) {
604
+ data.content = processAdsHtml(data.content, adshtml, hexo);
605
+ }
606
+ else if (options.enable) {
607
+ data.content = processAdsHtml(data.content, adshtml, hexo);
608
+ }
609
+ return data;
610
+ }
611
+ function processAdsHtml(content, adshtml, hexo) {
612
+ const options = parseConfig(hexo);
613
+ const replacement = memoize((adshtml) => {
614
+ const adsContentCss = path.join(__dirname$1, 'source/article-ads.css');
615
+ const adsContentJs = path.join(__dirname$1, 'source/article-ads.js');
616
+ let replacement = `<div id="hexo-adsense-hidden" style="display:none">${adshtml.join('')}</div>`;
617
+ if (fs$1.existsSync(adsContentCss))
618
+ replacement += `<style>${fs$1.readFileSync(adsContentCss).toString()}</style>`;
619
+ if (fs$1.existsSync(adsContentJs))
620
+ replacement += `<script>${fs$1.readFileSync(adsContentJs).toString()}</script>`;
621
+ return replacement;
622
+ });
623
+ const caller = new Error().stack?.split('at ')[2].replace(/^Hexo./g, '');
624
+ const isFieldPost = caller?.startsWith('after_post_render');
625
+ if (isFieldPost) {
626
+ content += replacement(adshtml);
627
+ }
628
+ else {
629
+ if (!options.enable) {
630
+ content = content.replace(/<\/head>/gm, `<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${options.pub}" crossorigin="anonymous"></script>`);
631
+ }
632
+ content = content.replace(/<\/body>/gm, `${replacement(adshtml)}</body>`);
633
+ }
634
+ return content;
635
+ }
636
+ function getPageSource(page) {
637
+ return page.full_source || page.source || page.path || page.canonical_path;
638
+ }
639
+ function after_render_html(content, data) {
640
+ const hexo = this;
641
+ const options = parseConfig(hexo);
642
+ const where = index(data);
643
+ const page = data.post ?? data.page;
644
+ const isPageAdsenseEnabled = typeof page.adsense === 'boolean' ? page.adsense : options.enable;
645
+ if (options.field === 'post') {
646
+ if (where.category || where.archive || where.home || where.tag) {
647
+ debugLog(`config field for post, skipping ${data.path || '<empty path>'}`);
648
+ return content;
649
+ }
650
+ }
651
+ debugLog(page.path, 'is adsense enabled', isPageAdsenseEnabled);
652
+ if (isPageAdsenseEnabled) {
653
+ const filterPattern = filter_patterns(content, getPageSource(page), hexo);
654
+ if (filterPattern.excluded)
655
+ return filterPattern.content;
656
+ const adshtml = filter_adshtml(hexo);
657
+ if (adshtml.length < 1)
658
+ return content;
659
+ if (page.adsense || options.enable) {
660
+ content = processAdsHtml(content, adshtml, hexo);
661
+ }
662
+ const pageAd = `<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${options.pub}" crossorigin="anonymous"></script>`;
663
+ content = content.replace(/<\/head>/, pageAd + '</head>');
664
+ }
665
+ return content;
666
+ }
667
+
668
+ /* global hexo */
669
+ // ESM-compatible __dirname replacement
670
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
671
+ if (typeof hexo !== 'undefined' && typeof hexo.config.adsense !== 'undefined') {
672
+ // const injector = injector2(hexo); // Create injector plugin
673
+ const config = getHexoAdsenseConfig(hexo);
674
+ const isDevelopment = config.development;
675
+ // clean temp folder on `hexo clean`
676
+ hexo.extend.filter.register('after_clean', function () {
677
+ // remove some other temporary files
678
+ hexo.log.debug(logname + '(clean)', 'cleaning temp folder');
679
+ if (fs$2.existsSync(tmpFolder))
680
+ fs$2.rmSync(tmpFolder, { recursive: true, force: true });
681
+ });
682
+ if (config.pub.length < 1) {
683
+ logger$1.error(logname + '(config)', `adsense ca-pub (adsense.pub) not configured in _config.yml`);
684
+ }
685
+ else {
686
+ if (config.enable) {
687
+ // Write config on </head>
688
+ // injector.register('head_end', function () {
689
+ // const adsenseConfigObject = JSON.stringify(
690
+ // assign(config, hexo.env, { adsense: hexo.config.adsense }),
691
+ // null,
692
+ // isDevelopment ? 2 : undefined
693
+ // );
694
+ // return `<script id="hexo-adsense-config" type="application/json">${adsenseConfigObject}</script>`;
695
+ // });
696
+ hexo.extend.filter.register('after_render:html', function (content, _data) {
697
+ const lastBodyRegex = /<\/body>(?=[^<]*$)/;
698
+ const firstHeadRegex = /<\/head>/;
699
+ const adsenseConfigObject = JSON.stringify(assign(config, hexo.env, { adsense: hexo.config.adsense }), null, isDevelopment ? 2 : undefined);
700
+ const script = `<script id="hexo-adsense-config" type="application/json">${adsenseConfigObject}</script>`;
701
+ // Apply functions only in production
702
+ if (!isDevelopment) {
703
+ // Redirect to HTTPS if configured
704
+ if (typeof config.https === 'boolean' && config.https) {
705
+ const https_js = fs$2.readFileSync(path.join(__dirname, 'source/https.js'), 'utf-8');
706
+ content = content.replace(lastBodyRegex, `<script>${https_js}</script></body>`);
707
+ }
708
+ // Add adblock blocker if configured
709
+ if (typeof config.adblock === 'boolean' && config.adblock) {
710
+ const adblock_css = fs$2.readFileSync(path.join(__dirname, 'source/adblock.css'), 'utf-8');
711
+ const adblock_js = fs$2.readFileSync(path.join(__dirname, 'source/adblock.js'), 'utf-8');
712
+ content = content.replace(lastBodyRegex, `<style>${adblock_css}</style><script>${adblock_js}</script></body>`);
713
+ }
714
+ }
715
+ return content.replace(firstHeadRegex, script + '</head>');
716
+ });
717
+ // Handle article ads if configured
718
+ if (typeof config.article_ads !== 'undefined') {
719
+ if (config.field === 'post') {
720
+ logger$1.info(logname, 'apply adsense only for posts');
721
+ // Apply to posts
722
+ hexo.extend.filter.register('after_post_render', after_post_render);
723
+ }
724
+ else {
725
+ logger$1.info(logname, 'apply adsense for all sites pages and posts');
726
+ // Apply to entire HTML
727
+ hexo.extend.filter.register('after_render:html', after_render_html);
728
+ }
729
+ }
730
+ // Prettify on development
731
+ if (hexo.env.cmd === 'server' && isDevelopment) {
732
+ hexo.extend.filter.register('after_render:html', async function (content, _page) {
733
+ const format = await prettier.format(content, { parser: 'html' });
734
+ debugLog(`Prettier formatted html result of ${_page.path}`);
735
+ return format;
736
+ });
737
+ }
738
+ }
739
+ }
740
+ }