hexo-adsense 1.1.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -0
- package/LICENSE +0 -0
- package/dist/index.cjs +12799 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +12782 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +12782 -0
- package/dist/index.mjs.map +1 -0
- package/dist/source/adblock.css +2 -0
- package/dist/source/adblock.js +1 -0
- package/{lib → dist}/source/article-ads.css +0 -0
- package/dist/source/article-ads.js +1 -0
- package/dist/source/article-ads.old.js +1 -0
- package/{lib → dist}/source/blogger-redirect.html +0 -0
- package/dist/source/https.js +1 -0
- package/{lib → dist}/source/in_article_ads_test.html +0 -0
- package/package.json +122 -38
- package/{README.md → readme.md} +27 -8
- package/gulpfile.ts +0 -100
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -91
- package/lib/packages/hexo-cli-extras/lib/env.d.ts +0 -3
- package/lib/packages/hexo-cli-extras/lib/env.js +0 -49
- package/lib/packages/hexo-extend-injector2/index.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/index.js +0 -12
- package/lib/packages/hexo-extend-injector2/lib/bundle/css-bundle.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/bundle/css-bundle.js +0 -64
- package/lib/packages/hexo-extend-injector2/lib/bundle/css-generator.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/bundle/css-generator.js +0 -12
- package/lib/packages/hexo-extend-injector2/lib/bundle/handle-data-pre.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/bundle/handle-data-pre.js +0 -28
- package/lib/packages/hexo-extend-injector2/lib/bundle/js-bundle.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/bundle/js-bundle.js +0 -32
- package/lib/packages/hexo-extend-injector2/lib/bundle/js-generator.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/bundle/js-generator.js +0 -8
- package/lib/packages/hexo-extend-injector2/lib/default-config.d.ts +0 -39
- package/lib/packages/hexo-extend-injector2/lib/default-config.js +0 -46
- package/lib/packages/hexo-extend-injector2/lib/filter.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/filter.js +0 -22
- package/lib/packages/hexo-extend-injector2/lib/helper/injector.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/helper/injector.js +0 -5
- package/lib/packages/hexo-extend-injector2/lib/helper/next-inject.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/helper/next-inject.js +0 -12
- package/lib/packages/hexo-extend-injector2/lib/injector.d.ts +0 -29
- package/lib/packages/hexo-extend-injector2/lib/injector.js +0 -125
- package/lib/packages/hexo-extend-injector2/lib/load.d.ts +0 -3
- package/lib/packages/hexo-extend-injector2/lib/load.js +0 -37
- package/lib/packages/hexo-extend-injector2/lib/next-point.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/next-point.js +0 -18
- package/lib/packages/hexo-extend-injector2/lib/next.d.ts +0 -2
- package/lib/packages/hexo-extend-injector2/lib/next.js +0 -99
- package/lib/packages/hexo-extend-injector2/lib/order.d.ts +0 -5
- package/lib/packages/hexo-extend-injector2/lib/order.js +0 -8
- package/lib/source/adblock.css +0 -2
- package/lib/source/adblock.js +0 -1
- package/lib/source/article-ads.js +0 -1
- package/lib/source/article-ads.old.js +0 -1
- package/lib/source/https.js +0 -1
- package/lib/src/article-ads.d.ts +0 -20
- package/lib/src/article-ads.js +0 -310
- package/lib/src/checkLocalHost.d.ts +0 -10
- package/lib/src/checkLocalHost.js +0 -37
- package/lib/src/config.d.ts +0 -14
- package/lib/src/config.js +0 -50
- package/lib/src/html-parser.d.ts +0 -8
- package/lib/src/html-parser.js +0 -26
- package/lib/src/log.d.ts +0 -1
- package/lib/src/log.js +0 -11
- package/lib/src/logger.d.ts +0 -3
- package/lib/src/logger.js +0 -25
- package/lib/src/md5.d.ts +0 -7
- package/lib/src/md5.js +0 -30
- package/lib/src/safestringify.d.ts +0 -2
- package/lib/src/safestringify.js +0 -125
- package/lib/src/utils.d.ts +0 -31
- package/lib/src/utils.js +0 -160
- package/lib/src/versionParser.d.ts +0 -27
- package/lib/src/versionParser.js +0 -40
- package/packages/@types/.gitmodules +0 -8
- package/packages/@types/LICENSE +0 -21
- package/packages/@types/README.md +0 -27
- package/packages/@types/hexo/HexoConfig.d.ts +0 -216
- package/packages/@types/hexo/LICENSE +0 -21
- package/packages/@types/hexo/README.md +0 -16
- package/packages/@types/hexo/index.d.ts +0 -849
- package/packages/@types/hexo/package.json +0 -34
- package/packages/@types/hexo-bunyan/LICENSE +0 -21
- package/packages/@types/hexo-bunyan/README.md +0 -16
- package/packages/@types/hexo-bunyan/index.d.ts +0 -9
- package/packages/@types/hexo-bunyan/package.json +0 -24
- package/packages/@types/hexo-log/LICENSE +0 -21
- package/packages/@types/hexo-log/README.md +0 -16
- package/packages/@types/hexo-log/index.d.ts +0 -159
- package/packages/@types/hexo-log/package.json +0 -28
- package/packages/@types/index.js +0 -2
- package/packages/@types/package.json +0 -30
- package/packages/@types/test/package.json +0 -15
- package/packages/@types/test/through2.ts +0 -6
- package/packages/@types/tsconfig.json +0 -14
- package/packages/@types/typings/index.d.ts +0 -7
- package/packages/@types/typings/kill-port.d.ts +0 -3
- package/packages/@types/typings/markdown-it-abbr.d.ts +0 -4
- package/packages/@types/typings/markdown-it-footnote.d.ts +0 -4
- package/packages/@types/typings/markdown-it-image-figures.d.ts +0 -4
- package/packages/@types/typings/markdown-it-mark.d.ts +0 -4
- package/packages/@types/typings/markdown-it-sub.d.ts +0 -7
- package/packages/@types/typings/markdown-it-sup.d.ts +0 -7
- package/packages/hexo-cli-extras/.eslintrc +0 -13
- package/packages/hexo-cli-extras/LICENSE.md +0 -20
- package/packages/hexo-cli-extras/README.md +0 -146
- package/packages/hexo-cli-extras/docs/basic.gif +0 -0
- package/packages/hexo-cli-extras/docs/gui.gif +0 -0
- package/packages/hexo-cli-extras/docs/remove.png +0 -0
- package/packages/hexo-cli-extras/docs/rename.png +0 -0
- package/packages/hexo-cli-extras/index.js +0 -48
- package/packages/hexo-cli-extras/lib/edit.js +0 -209
- package/packages/hexo-cli-extras/lib/env.js +0 -52
- package/packages/hexo-cli-extras/lib/extensions.js +0 -23
- package/packages/hexo-cli-extras/lib/integrate.js +0 -87
- package/packages/hexo-cli-extras/lib/isolate.js +0 -179
- package/packages/hexo-cli-extras/lib/remove.js +0 -145
- package/packages/hexo-cli-extras/lib/rename.js +0 -171
- package/packages/hexo-cli-extras/package.json +0 -34
- package/packages/hexo-extend-injector2/.eslintrc +0 -4
- package/packages/hexo-extend-injector2/.github/workflows/linter.yml +0 -27
- package/packages/hexo-extend-injector2/.github/workflows/tester.yml +0 -24
- package/packages/hexo-extend-injector2/.vscode/settings.json +0 -10
- package/packages/hexo-extend-injector2/LICENSE +0 -165
- package/packages/hexo-extend-injector2/README-ZH.md +0 -189
- package/packages/hexo-extend-injector2/README.md +0 -191
- package/packages/hexo-extend-injector2/USAGE.md +0 -38
- package/packages/hexo-extend-injector2/index.js +0 -14
- package/packages/hexo-extend-injector2/lib/bundle/css-bundle.js +0 -79
- package/packages/hexo-extend-injector2/lib/bundle/css-generator.js +0 -13
- package/packages/hexo-extend-injector2/lib/bundle/handle-data-pre.js +0 -29
- package/packages/hexo-extend-injector2/lib/bundle/js-bundle.js +0 -42
- package/packages/hexo-extend-injector2/lib/bundle/js-generator.js +0 -10
- package/packages/hexo-extend-injector2/lib/default-config.js +0 -52
- package/packages/hexo-extend-injector2/lib/filter.js +0 -24
- package/packages/hexo-extend-injector2/lib/helper/injector.js +0 -6
- package/packages/hexo-extend-injector2/lib/helper/next-inject.js +0 -14
- package/packages/hexo-extend-injector2/lib/injector.js +0 -128
- package/packages/hexo-extend-injector2/lib/load.js +0 -45
- package/packages/hexo-extend-injector2/lib/next-point.js +0 -19
- package/packages/hexo-extend-injector2/lib/next.js +0 -87
- package/packages/hexo-extend-injector2/lib/order.js +0 -9
- package/packages/hexo-extend-injector2/package.json +0 -49
- package/packages/hexo-extend-injector2/renovate.json +0 -6
- package/packages/hexo-extend-injector2/test/.eslintrc +0 -3
- package/packages/hexo-extend-injector2/test/index.js +0 -18
- package/packages/hexo-extend-injector2/test/lib/bundle/bundle-css.js +0 -86
- package/packages/hexo-extend-injector2/test/lib/bundle/bundle-js.js +0 -36
- package/packages/hexo-extend-injector2/test/lib/bundle/test.css +0 -3
- package/packages/hexo-extend-injector2/test/lib/bundle/test.js +0 -5
- package/packages/hexo-extend-injector2/test/lib/helper/injector.js +0 -45
- package/packages/hexo-extend-injector2/test/lib/helper/next-inject.js +0 -69
- package/packages/hexo-extend-injector2/test/lib/hexo-compatible.js +0 -250
- package/packages/hexo-extend-injector2/test/lib/hexo-injector.js +0 -37
- package/packages/hexo-extend-injector2/test/lib/injector.js +0 -93
- package/packages/memoize/CHANGELOG.md +0 -82
- package/packages/memoize/CHANGES +0 -124
- package/packages/memoize/LICENSE +0 -15
- package/packages/memoize/README.md +0 -503
- package/packages/memoize/ext/async.js +0 -154
- package/packages/memoize/ext/dispose.js +0 -33
- package/packages/memoize/ext/max-age.js +0 -90
- package/packages/memoize/ext/max.js +0 -27
- package/packages/memoize/ext/promise.js +0 -147
- package/packages/memoize/ext/ref-counter.js +0 -48
- package/packages/memoize/index.js +0 -34
- package/packages/memoize/lib/configure-map.js +0 -182
- package/packages/memoize/lib/methods.js +0 -32
- package/packages/memoize/lib/registered-extensions.js +0 -1
- package/packages/memoize/lib/resolve-length.js +0 -15
- package/packages/memoize/lib/resolve-normalize.js +0 -17
- package/packages/memoize/lib/resolve-resolve.js +0 -21
- package/packages/memoize/lib/weak.js +0 -134
- package/packages/memoize/methods-plain.js +0 -3
- package/packages/memoize/methods.js +0 -3
- package/packages/memoize/normalizers/get-1.js +0 -29
- package/packages/memoize/normalizers/get-fixed.js +0 -71
- package/packages/memoize/normalizers/get-primitive-fixed.js +0 -16
- package/packages/memoize/normalizers/get.js +0 -90
- package/packages/memoize/normalizers/primitive.js +0 -9
- package/packages/memoize/package.json +0 -60
- package/packages/memoize/plain.js +0 -37
- package/packages/memoize/profile.js +0 -107
- package/packages/memoize/repository.md +0 -1
- package/packages/memoize/weak-plain.js +0 -3
- package/packages/memoize/weak.js +0 -3
- package/tsconfig.json +0 -39
- package/unused.md +0 -11
package/lib/src/article-ads.js
DELETED
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars */
|
|
2
|
-
/// <reference path="./article-ads.d.ts"/>
|
|
3
|
-
/**
|
|
4
|
-
* Server side processor
|
|
5
|
-
*/
|
|
6
|
-
///
|
|
7
|
-
var Hexo = require("hexo");
|
|
8
|
-
var fs = require("hexo-fs");
|
|
9
|
-
var path = require("path");
|
|
10
|
-
var minimatch = require("minimatch");
|
|
11
|
-
var utils = require("./utils");
|
|
12
|
-
var log = require("./log");
|
|
13
|
-
var memoize = require("underscore").memoize;
|
|
14
|
-
var md5 = require("./md5");
|
|
15
|
-
var adsContent = "<div hexo-adsense=\"ads-content\">ADS_CODE_HERE</div>";
|
|
16
|
-
String.prototype.joinpath = function (str) {
|
|
17
|
-
return path.join(this.toString(), str);
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Article ads reader
|
|
21
|
-
* @param {string[]} files
|
|
22
|
-
* @param {Hexo} hexo
|
|
23
|
-
*/
|
|
24
|
-
function articleAds(files, hexo) {
|
|
25
|
-
var base_dir = hexo.base_dir;
|
|
26
|
-
var source_dir = hexo.source_dir;
|
|
27
|
-
var isDevelopment = require("./config")(hexo).development;
|
|
28
|
-
//hexo.log.log(isDevelopment, "dev");
|
|
29
|
-
/**
|
|
30
|
-
* @type {string[]}
|
|
31
|
-
*/
|
|
32
|
-
var result = [];
|
|
33
|
-
files.forEach(function (file) {
|
|
34
|
-
/**
|
|
35
|
-
* @type {string}
|
|
36
|
-
*/
|
|
37
|
-
var html;
|
|
38
|
-
var tes = base_dir.joinpath(file);
|
|
39
|
-
if (fs.existsSync(tes)) {
|
|
40
|
-
html = fs.readFileSync(tes).toString();
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
tes = source_dir.joinpath(file);
|
|
44
|
-
if (fs.existsSync(tes)) {
|
|
45
|
-
html = fs.readFileSync(tes).toString();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (html.length > 0) {
|
|
49
|
-
if (isDevelopment) {
|
|
50
|
-
// ad-test on localhost
|
|
51
|
-
// https://stackoverflow.com/a/34389120
|
|
52
|
-
html = html.replace(/><\/ins>/gm, " data-adtest=\"on\"></ins>");
|
|
53
|
-
}
|
|
54
|
-
// replace script adsbygoogle.push
|
|
55
|
-
html = html.replace(/\(adsbygoogle?\s*=?\s*window\.adsbygoogle?\s*\|\|?\s*\[\]\)\.push\({}\);/gm, "");
|
|
56
|
-
// replace scripts
|
|
57
|
-
//html = html.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gm, "");
|
|
58
|
-
// replace script src=adsbygoogle.js
|
|
59
|
-
html = html.replace(/<script?.*src?.*adsbygoogle\b[^>]*>([\s\S]*?)<\/script>/gm, "");
|
|
60
|
-
result.push(adsContent.replace("ADS_CODE_HERE", html));
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
function after_generate() {
|
|
66
|
-
/**
|
|
67
|
-
* @type {Hexo}
|
|
68
|
-
*/
|
|
69
|
-
var hexo = this, route = hexo.route, options = require("./config")(hexo);
|
|
70
|
-
//console.log(arguments.length);
|
|
71
|
-
// Filter routes to select all html files.
|
|
72
|
-
var routes = route.list().filter(function (path0) {
|
|
73
|
-
var choose = minimatch(path0, "**/*.{htm,html}", { nocase: true });
|
|
74
|
-
console.log(choose, path0);
|
|
75
|
-
if (typeof options.exclude != "undefined") {
|
|
76
|
-
choose = choose && !utils.isIgnore(path0, options.exclude);
|
|
77
|
-
}
|
|
78
|
-
if (typeof hexo.config.skip_render != "undefined") {
|
|
79
|
-
// _config.yml skip_render https://hexo.io/docs/configuration.html#Directory
|
|
80
|
-
choose = choose && !utils.isIgnore(path0, hexo.config.skip_render);
|
|
81
|
-
}
|
|
82
|
-
return choose;
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
var cx = require("./config")(null);
|
|
86
|
-
/**
|
|
87
|
-
* filter and parse html ads files {adsense.article_ads}
|
|
88
|
-
* @param {typeof cx} options
|
|
89
|
-
* @param {Hexo} hexo
|
|
90
|
-
* @returns {string[]} html string arrays
|
|
91
|
-
*/
|
|
92
|
-
function filter_adshtml(hexo) {
|
|
93
|
-
var options = require("./config")(hexo);
|
|
94
|
-
// parse article ads
|
|
95
|
-
/**
|
|
96
|
-
* @type {string[]}
|
|
97
|
-
*/
|
|
98
|
-
var adshtml = [];
|
|
99
|
-
if (Array.isArray(options.article_ads)) {
|
|
100
|
-
adshtml = options.article_ads;
|
|
101
|
-
}
|
|
102
|
-
else if (typeof options.article_ads == "string") {
|
|
103
|
-
adshtml = [options.article_ads];
|
|
104
|
-
}
|
|
105
|
-
if (adshtml.length > 0) {
|
|
106
|
-
adshtml = adshtml.filter(function (ads) {
|
|
107
|
-
return typeof ads == "string" && ads.trim().length > 0;
|
|
108
|
-
});
|
|
109
|
-
if (adshtml.length > 0) {
|
|
110
|
-
// adshtml turned to array html string
|
|
111
|
-
adshtml = articleAds(adshtml, hexo);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return adshtml;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* filter excluded patterns
|
|
118
|
-
* @param {string} content data.content or content based on event type
|
|
119
|
-
* @param {string} source_path full source path of the source file
|
|
120
|
-
* @param {Hexo} hexo hexo instances
|
|
121
|
-
* @returns content html string
|
|
122
|
-
*/
|
|
123
|
-
var filter_patterns = function (content, source_path, hexo) {
|
|
124
|
-
var _a;
|
|
125
|
-
var options = require("./config")(hexo);
|
|
126
|
-
var excluded = utils.isIgnore(source_path, options.exclude, hexo);
|
|
127
|
-
// if `source_path` undefined, that is archive or tags
|
|
128
|
-
if (source_path &&
|
|
129
|
-
excluded &&
|
|
130
|
-
!minimatch(source_path, "**/*.{htm,html}", { nocase: true })) {
|
|
131
|
-
log.log((_a = {}, _a[source_path] = excluded, _a), "isnt html, skipping...");
|
|
132
|
-
return {
|
|
133
|
-
content: content,
|
|
134
|
-
excluded: true
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
//log.log("is excluded", excluded, source_path);
|
|
138
|
-
// if the post or page is match excluded pattern, return original contents
|
|
139
|
-
if (excluded) {
|
|
140
|
-
// remove pagead on head caused by ../index.js
|
|
141
|
-
content = content.replace(/<script?.*src?.*adsbygoogle?\b[^>]*>([\s\S]*?)<\/script>/gm, "<!--hexo-adsense disabled on this page-->");
|
|
142
|
-
}
|
|
143
|
-
return {
|
|
144
|
-
content: content,
|
|
145
|
-
excluded: excluded
|
|
146
|
-
};
|
|
147
|
-
};
|
|
148
|
-
/**
|
|
149
|
-
* inject ads after_post_render event
|
|
150
|
-
* @example
|
|
151
|
-
* hexo.extend.filter.register("after_generate", injectAdsAfterGenerate);
|
|
152
|
-
*/
|
|
153
|
-
function after_post_render(data) {
|
|
154
|
-
/**
|
|
155
|
-
* @type {Hexo}
|
|
156
|
-
*/
|
|
157
|
-
var hexo = this;
|
|
158
|
-
var options = require("./config")(hexo);
|
|
159
|
-
//utils.dump("after_post_render/" + md5(data.title) + ".txt", data);
|
|
160
|
-
var filterPattern = filter_patterns(data.content, getPageSource(data), hexo);
|
|
161
|
-
data.content = filterPattern.content;
|
|
162
|
-
if (filterPattern.excluded) {
|
|
163
|
-
// if this post excluded, return original data
|
|
164
|
-
return data;
|
|
165
|
-
}
|
|
166
|
-
//log.log(data.title, "not excluded");
|
|
167
|
-
// parse article ads
|
|
168
|
-
/**
|
|
169
|
-
* @type {string[]}
|
|
170
|
-
*/
|
|
171
|
-
var adshtml = filter_adshtml(hexo);
|
|
172
|
-
if (adshtml.length < 1) {
|
|
173
|
-
return data;
|
|
174
|
-
}
|
|
175
|
-
if (typeof data.adsense == "boolean") {
|
|
176
|
-
if (data.adsense) {
|
|
177
|
-
//log.log(data.title, "adsense is enabled locally");
|
|
178
|
-
// if post adsense is enabled
|
|
179
|
-
data.content = processAdsHtml(data.content, adshtml, hexo);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
else if (options.enable) {
|
|
183
|
-
//log.log(data.title, "adsense is enabled globally");
|
|
184
|
-
// if adsense is enabled globally and post adsense not set
|
|
185
|
-
// enable adsense on post
|
|
186
|
-
data.content = processAdsHtml(data.content, adshtml, hexo);
|
|
187
|
-
}
|
|
188
|
-
return data;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* process injector adshtml strings
|
|
192
|
-
* @param {string[]} adshtml
|
|
193
|
-
* @param {Hexo} hexo hexo instances
|
|
194
|
-
* @param {string} content content html of page
|
|
195
|
-
*/
|
|
196
|
-
function processAdsHtml(content, adshtml, hexo) {
|
|
197
|
-
var options = require("./config")(hexo);
|
|
198
|
-
var replacement = memoize(function (adshtml) {
|
|
199
|
-
var adsContentCss = __dirname.joinpath("../source/article-ads.css");
|
|
200
|
-
var adsContentJs = __dirname.joinpath("../source/article-ads.js");
|
|
201
|
-
var replacement = "<div id=\"hexo-adsense-hidden\" style=\"display:none\">".concat(adshtml.join(""), "</div>");
|
|
202
|
-
if (fs.existsSync(adsContentCss)) {
|
|
203
|
-
replacement += "<style>".concat(fs
|
|
204
|
-
.readFileSync(adsContentCss)
|
|
205
|
-
.toString(), "</style>");
|
|
206
|
-
}
|
|
207
|
-
if (fs.existsSync(adsContentJs)) {
|
|
208
|
-
replacement += "<script>".concat(fs
|
|
209
|
-
.readFileSync(adsContentJs)
|
|
210
|
-
.toString(), "</script>");
|
|
211
|
-
}
|
|
212
|
-
return replacement;
|
|
213
|
-
});
|
|
214
|
-
var caller = new Error().stack.split("at ")[2].replace(/^Hexo./g, "");
|
|
215
|
-
var isFieldPost = caller.startsWith("after_post_render");
|
|
216
|
-
//const isFieldSite = caller.startsWith("after_render_html");
|
|
217
|
-
if (isFieldPost) {
|
|
218
|
-
content += replacement(adshtml);
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
// add pagead if global _config.yml adsense disabled {adsense.enable: false}
|
|
222
|
-
// prevent duplicate onpage adsense in </head>
|
|
223
|
-
if (!options.enable) {
|
|
224
|
-
content = content.replace(/<\/head>/gm, "<script async src=\"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=".concat(options.pub, "\" crossorigin=\"anonymous\"></script>"));
|
|
225
|
-
}
|
|
226
|
-
content = content.replace(/<\/body>/gm, "".concat(replacement(adshtml), "</body>"));
|
|
227
|
-
}
|
|
228
|
-
return content;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Get page source path
|
|
232
|
-
* @param {object} page
|
|
233
|
-
* @returns {string}
|
|
234
|
-
*/
|
|
235
|
-
function getPageSource(page) {
|
|
236
|
-
if (typeof page.full_source != "undefined") {
|
|
237
|
-
return page.full_source;
|
|
238
|
-
}
|
|
239
|
-
if (typeof page.source != "undefined") {
|
|
240
|
-
return page.source;
|
|
241
|
-
}
|
|
242
|
-
// if archive page, source and full_source are not specified
|
|
243
|
-
if (typeof page.path != "undefined") {
|
|
244
|
-
return page.path;
|
|
245
|
-
}
|
|
246
|
-
if (typeof page.canonical_path != "undefined") {
|
|
247
|
-
return page.canonical_path;
|
|
248
|
-
}
|
|
249
|
-
//log.log(page.canonical_path);
|
|
250
|
-
//utils.dump("pageSource.txt", page.canonical_path, page);
|
|
251
|
-
return undefined;
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Inject ads after_render:html event (on all page)
|
|
255
|
-
* @param {object} data
|
|
256
|
-
* @param {string} content
|
|
257
|
-
*/
|
|
258
|
-
function after_render_html(content, data) {
|
|
259
|
-
/**
|
|
260
|
-
* @type {Hexo}
|
|
261
|
-
*/
|
|
262
|
-
var hexo = this;
|
|
263
|
-
var options = require("./config")(hexo);
|
|
264
|
-
var page;
|
|
265
|
-
if (data.post) {
|
|
266
|
-
data.type = "post";
|
|
267
|
-
page = data.post;
|
|
268
|
-
}
|
|
269
|
-
else if (data.page) {
|
|
270
|
-
data.type = "page";
|
|
271
|
-
page = data.page;
|
|
272
|
-
}
|
|
273
|
-
/*delete page._content;
|
|
274
|
-
delete page.raw;
|
|
275
|
-
delete page.content;
|
|
276
|
-
delete page.excerpt;
|
|
277
|
-
log.log(page);*/
|
|
278
|
-
var filterPattern = filter_patterns(content, getPageSource(page), hexo);
|
|
279
|
-
if (filterPattern.excluded) {
|
|
280
|
-
// if this post is excluded, return original content
|
|
281
|
-
return filterPattern.content;
|
|
282
|
-
}
|
|
283
|
-
// parse article ads
|
|
284
|
-
/**
|
|
285
|
-
* @type {string[]}
|
|
286
|
-
*/
|
|
287
|
-
var adshtml = filter_adshtml(hexo);
|
|
288
|
-
if (adshtml.length < 1) {
|
|
289
|
-
return content;
|
|
290
|
-
}
|
|
291
|
-
if (typeof page.adsense == "boolean") {
|
|
292
|
-
// apply adsense on each rendering post {adsense: true}
|
|
293
|
-
if (page.adsense) {
|
|
294
|
-
//console.log("adsense enabled at post", page.title);
|
|
295
|
-
content = processAdsHtml(content, adshtml, hexo);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
else if (options.enable) {
|
|
299
|
-
// if adsense is enabled globally and post adsense not set
|
|
300
|
-
// enable adsense on post
|
|
301
|
-
content = processAdsHtml(content, adshtml, hexo);
|
|
302
|
-
}
|
|
303
|
-
// return modified html
|
|
304
|
-
return content;
|
|
305
|
-
}
|
|
306
|
-
module.exports = {
|
|
307
|
-
endbodycode: articleAds,
|
|
308
|
-
after_render_html: after_render_html,
|
|
309
|
-
after_post_render: after_post_render
|
|
310
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Check if address/dnsname is local
|
|
3
|
-
* @param {*} address <ip address/dns name>
|
|
4
|
-
* @see {@link https://github.com/sanketbajoria/check-localhost#readme}
|
|
5
|
-
* @example
|
|
6
|
-
* const locals = ["127.0.0.1", "localhost", "::1"];
|
|
7
|
-
* checkLocalHost(locals[0]).then(function (isLocal){}) // isLocal is true
|
|
8
|
-
*/
|
|
9
|
-
declare const checkLocalHost: <T = Function>(fn: T, hashFn?: (...args: any[]) => string) => T;
|
|
10
|
-
export { checkLocalHost as default };
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
var dns = require("dns");
|
|
2
|
-
var os = require("os");
|
|
3
|
-
var memoize = require("./utils").memoize;
|
|
4
|
-
var ifaces = os.networkInterfaces();
|
|
5
|
-
/**
|
|
6
|
-
* Check if address/dnsname is local
|
|
7
|
-
* @param {*} address <ip address/dns name>
|
|
8
|
-
* @see {@link https://github.com/sanketbajoria/check-localhost#readme}
|
|
9
|
-
* @example
|
|
10
|
-
* const locals = ["127.0.0.1", "localhost", "::1"];
|
|
11
|
-
* checkLocalHost(locals[0]).then(function (isLocal){}) // isLocal is true
|
|
12
|
-
*/
|
|
13
|
-
var checkLocalHost = memoize(function (address) {
|
|
14
|
-
return new Promise(function (resolve, reject) {
|
|
15
|
-
dns.lookup(address, function (err, addr) {
|
|
16
|
-
if (err) {
|
|
17
|
-
return resolve(false, addr);
|
|
18
|
-
}
|
|
19
|
-
try {
|
|
20
|
-
address = addr;
|
|
21
|
-
Object.keys(ifaces).forEach(function (ifname) {
|
|
22
|
-
ifaces[ifname].forEach(function (iface) {
|
|
23
|
-
if (iface.address === address)
|
|
24
|
-
resolve(true, iface);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
resolve(false, ifaces);
|
|
28
|
-
}
|
|
29
|
-
catch (err) {
|
|
30
|
-
reject(err, addr);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
module.exports = {
|
|
36
|
-
"default": checkLocalHost
|
|
37
|
-
};
|
package/lib/src/config.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
declare function _exports(hexo: Hexo): typeof defaultConfig;
|
|
2
|
-
export = _exports;
|
|
3
|
-
import Hexo = require("hexo");
|
|
4
|
-
declare namespace defaultConfig {
|
|
5
|
-
const enable: boolean;
|
|
6
|
-
const article_ads: string[];
|
|
7
|
-
const pub: string;
|
|
8
|
-
const adblock: boolean;
|
|
9
|
-
const https: boolean;
|
|
10
|
-
const field: "site" | "post";
|
|
11
|
-
const type: "amp" | "javascript";
|
|
12
|
-
const exclude: string[];
|
|
13
|
-
const development: boolean;
|
|
14
|
-
}
|
package/lib/src/config.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars */
|
|
2
|
-
/* global hexo */
|
|
3
|
-
var Hexo = require("hexo");
|
|
4
|
-
var assign = require("object-assign");
|
|
5
|
-
var defaultConfig = {
|
|
6
|
-
/**
|
|
7
|
-
* Enable adsense
|
|
8
|
-
*/
|
|
9
|
-
enable: true,
|
|
10
|
-
article_ads: [""].filter(function (v) {
|
|
11
|
-
return typeof v == "string" && v.length > 0;
|
|
12
|
-
}),
|
|
13
|
-
/**
|
|
14
|
-
* Adsense ca-pub
|
|
15
|
-
*/
|
|
16
|
-
pub: "",
|
|
17
|
-
adblock: false,
|
|
18
|
-
https: false,
|
|
19
|
-
/**
|
|
20
|
-
* @type {"site" | "post"}
|
|
21
|
-
*/
|
|
22
|
-
field: "site",
|
|
23
|
-
/**
|
|
24
|
-
* @type {"amp" | "javascript"}
|
|
25
|
-
*/
|
|
26
|
-
type: "javascript",
|
|
27
|
-
exclude: [".gitignore"],
|
|
28
|
-
/**
|
|
29
|
-
* is development mode?
|
|
30
|
-
*/
|
|
31
|
-
development: false
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* hexo-adsense config
|
|
35
|
-
* @param {Hexo} hexo
|
|
36
|
-
* @returns {typeof defaultConfig}
|
|
37
|
-
*/
|
|
38
|
-
module.exports = function (hexo) {
|
|
39
|
-
if (hexo && typeof hexo.config.adsense != "undefined") {
|
|
40
|
-
/**
|
|
41
|
-
* @type {typeof defaultConfig}
|
|
42
|
-
*/
|
|
43
|
-
var c = assign(defaultConfig, hexo.config.adsense);
|
|
44
|
-
c.development = defaultConfig.development =
|
|
45
|
-
require("../packages/hexo-cli-extras/lib/env").isDev(hexo);
|
|
46
|
-
// console.log(c);
|
|
47
|
-
return c;
|
|
48
|
-
}
|
|
49
|
-
return defaultConfig;
|
|
50
|
-
};
|
package/lib/src/html-parser.d.ts
DELETED
package/lib/src/html-parser.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
var jsdom = require("jsdom");
|
|
2
|
-
var JSDOM = jsdom.JSDOM;
|
|
3
|
-
function parse(str) {
|
|
4
|
-
return new JSDOM(str);
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* create node from html string
|
|
8
|
-
* @param {string} htmlString
|
|
9
|
-
* @returns
|
|
10
|
-
*/
|
|
11
|
-
function createElementFromHTML(htmlString) {
|
|
12
|
-
var dom = new JSDOM("");
|
|
13
|
-
// Get DOMParser, same API as in browser
|
|
14
|
-
var DOMParser = dom.window.DOMParser;
|
|
15
|
-
var parser = new DOMParser();
|
|
16
|
-
// Create document by parsing XML/HTML
|
|
17
|
-
var document = parser.parseFromString(htmlString, "text/html");
|
|
18
|
-
var div = document.createElement("div");
|
|
19
|
-
div.innerHTML = htmlString.trim();
|
|
20
|
-
// Change this to div.childNodes to support multiple top-level nodes
|
|
21
|
-
return div.firstChild;
|
|
22
|
-
}
|
|
23
|
-
module.exports = {
|
|
24
|
-
parse: parse,
|
|
25
|
-
createNodeFromHtml: createElementFromHTML
|
|
26
|
-
};
|
package/lib/src/log.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/src/log.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
exports.__esModule = true;
|
|
6
|
-
var hexo_log_1 = __importDefault(require("hexo-log"));
|
|
7
|
-
var log = (0, hexo_log_1["default"])({
|
|
8
|
-
debug: false,
|
|
9
|
-
silent: false
|
|
10
|
-
});
|
|
11
|
-
module.exports = log;
|
package/lib/src/logger.d.ts
DELETED
package/lib/src/logger.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
var logger = {
|
|
2
|
-
log: log2,
|
|
3
|
-
once: once
|
|
4
|
-
};
|
|
5
|
-
var once = (function () {
|
|
6
|
-
var fn = [];
|
|
7
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
8
|
-
fn[_i] = arguments[_i];
|
|
9
|
-
}
|
|
10
|
-
var executed = false;
|
|
11
|
-
return function () {
|
|
12
|
-
if (!executed) {
|
|
13
|
-
executed = true;
|
|
14
|
-
// do something
|
|
15
|
-
if (typeof fn[0] == "function")
|
|
16
|
-
return fn[0]();
|
|
17
|
-
console.log(fn);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
})();
|
|
21
|
-
function log2(msg) {
|
|
22
|
-
var logLineDetails = new Error().stack.split("at ")[3].trim();
|
|
23
|
-
console.log("DEBUG", new Date().toUTCString(), logLineDetails, msg);
|
|
24
|
-
}
|
|
25
|
-
module.exports = logger;
|
package/lib/src/md5.d.ts
DELETED
package/lib/src/md5.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
exports.__esModule = true;
|
|
6
|
-
exports.md5 = void 0;
|
|
7
|
-
var crypto_1 = __importDefault(require("crypto"));
|
|
8
|
-
var util_1 = require("util");
|
|
9
|
-
/**
|
|
10
|
-
* PHP MD5 Equivalent
|
|
11
|
-
* @param data
|
|
12
|
-
* @returns
|
|
13
|
-
*/
|
|
14
|
-
function md5(data) {
|
|
15
|
-
if (typeof data !== "string" || !data) {
|
|
16
|
-
if (typeof data !== "string") {
|
|
17
|
-
throw new Error('The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type ' +
|
|
18
|
-
typeof data +
|
|
19
|
-
" (" +
|
|
20
|
-
(0, util_1.inspect)(data) +
|
|
21
|
-
") ");
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
throw new Error("the 'data' argument is empty");
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return crypto_1["default"].createHash("md5").update(data).digest("hex");
|
|
28
|
-
}
|
|
29
|
-
exports.md5 = md5;
|
|
30
|
-
exports["default"] = md5;
|
package/lib/src/safestringify.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JSON safestringify
|
|
3
|
-
* @see {@link https://github.com/bugsnag/safe-json-stringify#readme}
|
|
4
|
-
*/
|
|
5
|
-
module.exports = function (data, replacer, space, opts) {
|
|
6
|
-
var redactedKeys = opts && opts.redactedKeys ? opts.redactedKeys : [];
|
|
7
|
-
var redactedPaths = opts && opts.redactedPaths ? opts.redactedPaths : [];
|
|
8
|
-
return JSON.stringify(prepareObjForSerialization(data, redactedKeys, redactedPaths), replacer, space);
|
|
9
|
-
};
|
|
10
|
-
var MAX_DEPTH = 20;
|
|
11
|
-
var MAX_EDGES = 25000;
|
|
12
|
-
var MIN_PRESERVED_DEPTH = 8;
|
|
13
|
-
var REPLACEMENT_NODE = "...";
|
|
14
|
-
function isError(o) {
|
|
15
|
-
return o instanceof Error || /^\[object (Error|(Dom)?Exception)\]$/.test(Object.prototype.toString.call(o));
|
|
16
|
-
}
|
|
17
|
-
function throwsMessage(err) {
|
|
18
|
-
return "[Throws: " + (err ? err.message : "?") + "]";
|
|
19
|
-
}
|
|
20
|
-
function find(haystack, needle) {
|
|
21
|
-
for (var i = 0, len = haystack.length; i < len; i++) {
|
|
22
|
-
if (haystack[i] === needle)
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
// returns true if the string `path` starts with any of the provided `paths`
|
|
28
|
-
function isDescendent(paths, path) {
|
|
29
|
-
for (var i = 0, len = paths.length; i < len; i++) {
|
|
30
|
-
if (path.indexOf(paths[i]) === 0)
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
function shouldRedact(patterns, key) {
|
|
36
|
-
for (var i = 0, len = patterns.length; i < len; i++) {
|
|
37
|
-
if (typeof patterns[i] === "string" && patterns[i].toLowerCase() === key.toLowerCase())
|
|
38
|
-
return true;
|
|
39
|
-
if (patterns[i] && typeof patterns[i].test === "function" && patterns[i].test(key))
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
function isArray(obj) {
|
|
45
|
-
return Object.prototype.toString.call(obj) === "[object Array]";
|
|
46
|
-
}
|
|
47
|
-
function safelyGetProp(obj, prop) {
|
|
48
|
-
try {
|
|
49
|
-
return obj[prop];
|
|
50
|
-
}
|
|
51
|
-
catch (err) {
|
|
52
|
-
return throwsMessage(err);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
function prepareObjForSerialization(obj, redactedKeys, redactedPaths) {
|
|
56
|
-
var seen = []; // store references to objects we have seen before
|
|
57
|
-
var edges = 0;
|
|
58
|
-
function visit(obj, path) {
|
|
59
|
-
function edgesExceeded() {
|
|
60
|
-
return path.length > MIN_PRESERVED_DEPTH && edges > MAX_EDGES;
|
|
61
|
-
}
|
|
62
|
-
edges++;
|
|
63
|
-
if (path.length > MAX_DEPTH)
|
|
64
|
-
return REPLACEMENT_NODE;
|
|
65
|
-
if (edgesExceeded())
|
|
66
|
-
return REPLACEMENT_NODE;
|
|
67
|
-
if (obj === null || typeof obj !== "object")
|
|
68
|
-
return obj;
|
|
69
|
-
if (find(seen, obj))
|
|
70
|
-
return "[Circular]";
|
|
71
|
-
seen.push(obj);
|
|
72
|
-
if (typeof obj.toJSON === "function") {
|
|
73
|
-
try {
|
|
74
|
-
// we're not going to count this as an edge because it
|
|
75
|
-
// replaces the value of the currently visited object
|
|
76
|
-
edges--;
|
|
77
|
-
var fResult = visit(obj.toJSON(), path);
|
|
78
|
-
seen.pop();
|
|
79
|
-
return fResult;
|
|
80
|
-
}
|
|
81
|
-
catch (err) {
|
|
82
|
-
return throwsMessage(err);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
var er = isError(obj);
|
|
86
|
-
if (er) {
|
|
87
|
-
edges--;
|
|
88
|
-
var eResult = visit({ name: obj.name, message: obj.message }, path);
|
|
89
|
-
seen.pop();
|
|
90
|
-
return eResult;
|
|
91
|
-
}
|
|
92
|
-
if (isArray(obj)) {
|
|
93
|
-
var aResult = [];
|
|
94
|
-
for (var i = 0, len = obj.length; i < len; i++) {
|
|
95
|
-
if (edgesExceeded()) {
|
|
96
|
-
aResult.push(REPLACEMENT_NODE);
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
aResult.push(visit(obj[i], path.concat("[]")));
|
|
100
|
-
}
|
|
101
|
-
seen.pop();
|
|
102
|
-
return aResult;
|
|
103
|
-
}
|
|
104
|
-
var result = {};
|
|
105
|
-
try {
|
|
106
|
-
for (var prop in obj) {
|
|
107
|
-
if (!Object.prototype.hasOwnProperty.call(obj, prop))
|
|
108
|
-
continue;
|
|
109
|
-
if (isDescendent(redactedPaths, path.join(".")) && shouldRedact(redactedKeys, prop)) {
|
|
110
|
-
result[prop] = "[REDACTED]";
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
if (edgesExceeded()) {
|
|
114
|
-
result[prop] = REPLACEMENT_NODE;
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
result[prop] = visit(safelyGetProp(obj, prop), path.concat(prop));
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
catch (e) { }
|
|
121
|
-
seen.pop();
|
|
122
|
-
return result;
|
|
123
|
-
}
|
|
124
|
-
return visit(obj, []);
|
|
125
|
-
}
|