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/gulpfile.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import Bluebird from "bluebird";
|
|
3
|
-
import { exec } from "child_process";
|
|
4
|
-
import { existsSync, rmSync, writeFileSync } from "fs";
|
|
5
|
-
import gulp from "gulp";
|
|
6
|
-
import autoprefixer from "gulp-autoprefixer";
|
|
7
|
-
import cleanCSS from "gulp-clean-css";
|
|
8
|
-
import htmlmin from "gulp-html-minifier-terser";
|
|
9
|
-
import sourcemaps from "gulp-sourcemaps";
|
|
10
|
-
import gulpTerser from "gulp-terser";
|
|
11
|
-
import { join } from "path";
|
|
12
|
-
import terser from "terser";
|
|
13
|
-
import pkg from "./package.json";
|
|
14
|
-
|
|
15
|
-
function tsc(cb) {
|
|
16
|
-
exec("npx tsc", function (err, stdout, stderr) {
|
|
17
|
-
console.log(stdout);
|
|
18
|
-
console.log(stderr);
|
|
19
|
-
cb(err);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function copy(done) {
|
|
24
|
-
return Bluebird.resolve(
|
|
25
|
-
gulp
|
|
26
|
-
.src("./source/*.js")
|
|
27
|
-
.pipe(gulpTerser({}, terser.minify))
|
|
28
|
-
.pipe(gulp.dest("./lib/source"))
|
|
29
|
-
)
|
|
30
|
-
.then(() => {
|
|
31
|
-
//gulp.src(["./packages/**/*", "!**/.git**", "!**/tmp/**"]).pipe(gulp.dest("./lib/packages"));
|
|
32
|
-
})
|
|
33
|
-
.finally(done);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function css() {
|
|
37
|
-
return gulp
|
|
38
|
-
.src("./source/*.css")
|
|
39
|
-
.pipe(sourcemaps.init({ loadMaps: true }))
|
|
40
|
-
.pipe(autoprefixer())
|
|
41
|
-
.pipe(
|
|
42
|
-
cleanCSS({ compatibility: "ie8", debug: true }, (details) => {
|
|
43
|
-
console.log(`${details.name}: ${details.stats.originalSize}`);
|
|
44
|
-
console.log(`${details.name}: ${details.stats.minifiedSize}`);
|
|
45
|
-
})
|
|
46
|
-
)
|
|
47
|
-
.pipe(sourcemaps.write())
|
|
48
|
-
.pipe(gulp.dest("./lib/source"));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function clean() {
|
|
52
|
-
const paths = [join(__dirname, "lib")].filter((path) => existsSync(path));
|
|
53
|
-
return (await Bluebird.all(paths)).forEach((path) => {
|
|
54
|
-
rmSync(path, { recursive: true, force: true });
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function html() {
|
|
59
|
-
return gulp
|
|
60
|
-
.src("source/*.html")
|
|
61
|
-
.pipe(
|
|
62
|
-
htmlmin({
|
|
63
|
-
collapseWhitespace: true,
|
|
64
|
-
minifyJS: true,
|
|
65
|
-
minifyCSS: true,
|
|
66
|
-
preserveLineBreaks: true,
|
|
67
|
-
})
|
|
68
|
-
)
|
|
69
|
-
.pipe(gulp.dest("./lib/source"));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function updateVersion() {
|
|
73
|
-
return new Bluebird((resolve) => {
|
|
74
|
-
const parse = String(pkg.version)
|
|
75
|
-
.split(".")
|
|
76
|
-
.map((n) => parseInt(n));
|
|
77
|
-
let major = parse[0];
|
|
78
|
-
let minor = parse[1];
|
|
79
|
-
if (minor > 10) {
|
|
80
|
-
minor = 0;
|
|
81
|
-
major += 1;
|
|
82
|
-
}
|
|
83
|
-
let patch = parse[2] + 1; // +1
|
|
84
|
-
if (patch > 10) {
|
|
85
|
-
patch = 0;
|
|
86
|
-
minor += 1;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const merge = `${major}.${minor}.${patch}`;
|
|
90
|
-
pkg.version = merge;
|
|
91
|
-
const build = JSON.stringify(pkg, null, 2) + "\n";
|
|
92
|
-
writeFileSync(join(__dirname, "package.json"), build);
|
|
93
|
-
resolve();
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
gulp.task("update", updateVersion);
|
|
98
|
-
|
|
99
|
-
exports.default = gulp.series(clean, copy, css, html, tsc);
|
|
100
|
-
exports.copy = copy;
|
package/lib/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/index.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/* global hexo */
|
|
2
|
-
"use strict";
|
|
3
|
-
var injector2 = require("./packages/hexo-extend-injector2/index");
|
|
4
|
-
var fs = require("fs");
|
|
5
|
-
var path = require("path");
|
|
6
|
-
var getConfig = require("./src/config");
|
|
7
|
-
var isDevelopment = require("./src/config")(hexo).development;
|
|
8
|
-
var assign = require("object-assign");
|
|
9
|
-
var log = require("hexo-log")({
|
|
10
|
-
debug: false,
|
|
11
|
-
silent: false
|
|
12
|
-
});
|
|
13
|
-
if (typeof hexo == "undefined" || typeof hexo.config.adsense == "undefined") {
|
|
14
|
-
//console.log("[hexo-adsense] Not hexo process, skipping..");
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
var injector = injector2(hexo); // will make it as plugin
|
|
18
|
-
var config = getConfig(hexo);
|
|
19
|
-
if (config.pub.length < 1) {
|
|
20
|
-
log.error("adsense ca-pub (adsense.pub) not configured in _config.yml");
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
// only apply these function on production
|
|
24
|
-
if (!isDevelopment) {
|
|
25
|
-
//log.debug("is remote");
|
|
26
|
-
// add redirect https
|
|
27
|
-
if (typeof config.https == "boolean") {
|
|
28
|
-
if (config.https) {
|
|
29
|
-
injector.register("body-end", function () {
|
|
30
|
-
var https_js = fs
|
|
31
|
-
.readFileSync(path.join(__dirname, "source/https.js"))
|
|
32
|
-
.toString();
|
|
33
|
-
return "<script>".concat(https_js, "</script>");
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
// add adblock blocker
|
|
38
|
-
if (typeof config.adblock == "boolean") {
|
|
39
|
-
if (config.adblock) {
|
|
40
|
-
var adblock_css_1 = fs
|
|
41
|
-
.readFileSync(path.join(__dirname, "source/adblock.css"))
|
|
42
|
-
.toString();
|
|
43
|
-
var adblock_js_1 = fs
|
|
44
|
-
.readFileSync(path.join(__dirname, "source/adblock.js"))
|
|
45
|
-
.toString();
|
|
46
|
-
injector.register("body-end", function () {
|
|
47
|
-
return "<style>".concat(adblock_css_1, "</style><script>").concat(adblock_js_1, "</script>");
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (config.enable) {
|
|
53
|
-
injector.register("head_end", function () {
|
|
54
|
-
var adsenseConfigObject;
|
|
55
|
-
if (isDevelopment) {
|
|
56
|
-
adsenseConfigObject = JSON.stringify(assign(config, hexo.env), null, 2);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
adsenseConfigObject = JSON.stringify(assign(config, hexo.env));
|
|
60
|
-
}
|
|
61
|
-
return "<script id=\"hexo-adsense-config\" type=\"application/json\">".concat(adsenseConfigObject, "</script>");
|
|
62
|
-
});
|
|
63
|
-
// adsense enabled to all pages
|
|
64
|
-
injector.register("head-end", {
|
|
65
|
-
value: "<script async src=\"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=".concat(config.pub, "\" crossorigin=\"anonymous\"></script>")
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
if (typeof config.article_ads != "undefined") {
|
|
69
|
-
/*
|
|
70
|
-
injector.register("body-end", function () {
|
|
71
|
-
let adshtml = [];
|
|
72
|
-
if (Array.isArray(config.article_ads)) {
|
|
73
|
-
adshtml = config.article_ads;
|
|
74
|
-
}
|
|
75
|
-
if (adshtml.length) {
|
|
76
|
-
return require("./lib/article-ads").endbodycode(adshtml, hexo);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
*/
|
|
80
|
-
//log.log("hexo-adsense article ads process starting...");
|
|
81
|
-
if (config.field === "post") {
|
|
82
|
-
// only on post
|
|
83
|
-
//log.log("after_post_render");
|
|
84
|
-
hexo.extend.filter.register("after_post_render", require("./src/article-ads").after_post_render);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
//log.log("after_render:html");
|
|
88
|
-
// entire html
|
|
89
|
-
hexo.extend.filter.register("after_render:html", require("./src/article-ads").after_render_html);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var Hexo = require("hexo");
|
|
3
|
-
var memoize = require("underscore").memoize;
|
|
4
|
-
var argv = require("minimist")(process.argv.slice(2));
|
|
5
|
-
/**
|
|
6
|
-
* Check is production or development
|
|
7
|
-
* @param {Hexo} inHexo
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
var getEnv = memoize(function (inHexo) {
|
|
11
|
-
var DEV = "development";
|
|
12
|
-
var PRD = "production";
|
|
13
|
-
// --development
|
|
14
|
-
var arg = typeof argv["development"] == "boolean" && argv["development"];
|
|
15
|
-
// set NODE_ENV = "development"
|
|
16
|
-
var env = process.env.NODE_ENV && process.env.NODE_ENV.toString().toLowerCase() === "development";
|
|
17
|
-
// define is development
|
|
18
|
-
var isDev = arg || env;
|
|
19
|
-
if (inHexo) {
|
|
20
|
-
if (isDev)
|
|
21
|
-
return DEV;
|
|
22
|
-
if (typeof inHexo.env.args.development == "boolean" && inHexo.env.args.development)
|
|
23
|
-
return DEV;
|
|
24
|
-
if (inHexo.env.args._ && inHexo.env.args._.length > 0) {
|
|
25
|
-
for (var i = 0; i < inHexo.env.args._.length; i++) {
|
|
26
|
-
if (inHexo.env.args._[i] == "s" || inHexo.env.args._[i] == "server")
|
|
27
|
-
return DEV;
|
|
28
|
-
if (inHexo.env.args._[i] == "d" || inHexo.env.args._[i] == "deploy")
|
|
29
|
-
return PRD;
|
|
30
|
-
if (inHexo.env.args._[i] == "g" || inHexo.env.args._[i] == "generate")
|
|
31
|
-
return PRD;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return null;
|
|
36
|
-
});
|
|
37
|
-
var isDev = memoize(function (hexo) {
|
|
38
|
-
return getEnv(hexo) == "development";
|
|
39
|
-
});
|
|
40
|
-
var isProd = memoize(function (hexo) {
|
|
41
|
-
return getEnv(hexo) == "production";
|
|
42
|
-
});
|
|
43
|
-
module.exports = {
|
|
44
|
-
env: function (inHexo) {
|
|
45
|
-
return getEnv(inHexo);
|
|
46
|
-
},
|
|
47
|
-
isProd: isProd,
|
|
48
|
-
isDev: isDev
|
|
49
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
// const { resolve } = require('path');
|
|
3
|
-
module.exports = function (ctx) {
|
|
4
|
-
// If initialized, return the result
|
|
5
|
-
if (ctx.extend.injector2) {
|
|
6
|
-
return ctx.extend.injector2;
|
|
7
|
-
}
|
|
8
|
-
// If not in the main plugin directory, relocate to the main plugin directory
|
|
9
|
-
// const load = require(resolve(ctx.plugin_dir, 'hexo-extend-injector2/lib/load'));
|
|
10
|
-
var load = require('./lib/load');
|
|
11
|
-
return load(ctx);
|
|
12
|
-
};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var handleDataPre = require('./handle-data-pre');
|
|
3
|
-
var cssGenerator = require('./css-generator');
|
|
4
|
-
var loadCss = function (ctx, injector, config) {
|
|
5
|
-
var generator = ctx.extend.generator;
|
|
6
|
-
var options = config.options, file = config.file, env = config.env;
|
|
7
|
-
var REGISTER_CSS = injector.order.REGISTER_CSS;
|
|
8
|
-
var url_for = require('hexo-util').url_for.bind(ctx);
|
|
9
|
-
if (file.link === 'preload') {
|
|
10
|
-
injector.register('head-end', {
|
|
11
|
-
value: "<link rel=\"preload\" as=\"style\" href=\"".concat(url_for(file.path), "\" />"),
|
|
12
|
-
priority: REGISTER_CSS
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
if (file.link === 'load') {
|
|
16
|
-
injector.register('head-end', {
|
|
17
|
-
value: "<link rel=\"stylesheet\" type=\"text/css\" href=\"".concat(url_for(file.path), "\" />"),
|
|
18
|
-
priority: REGISTER_CSS
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
generator.register("css-bundler-".concat(env), function () {
|
|
22
|
-
return {
|
|
23
|
-
path: file.path,
|
|
24
|
-
data: cssGenerator(injector, env, options)
|
|
25
|
-
};
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
module.exports = function (ctx, injector) {
|
|
29
|
-
var config = injector.config.css;
|
|
30
|
-
if (!config.enable)
|
|
31
|
-
return;
|
|
32
|
-
var filter = ctx.extend.filter;
|
|
33
|
-
var _a = injector.order, REGISTER_VARIABLE = _a.REGISTER_VARIABLE, REGISTER_STYLE = _a.REGISTER_STYLE;
|
|
34
|
-
filter.register('injector2:register-variable', function (data) {
|
|
35
|
-
data.priority = REGISTER_VARIABLE;
|
|
36
|
-
injector.register('css', data);
|
|
37
|
-
});
|
|
38
|
-
filter.register('injector2:register-style', function (data) {
|
|
39
|
-
data.priority = REGISTER_STYLE;
|
|
40
|
-
injector.register('css', data);
|
|
41
|
-
});
|
|
42
|
-
if (typeof config.path === 'string') {
|
|
43
|
-
var path = config.path;
|
|
44
|
-
config.path = {
|
|
45
|
-
"default": {
|
|
46
|
-
path: path,
|
|
47
|
-
link: 'load'
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
var isLoadCss = {};
|
|
52
|
-
filter.register('injector2:register-css', function (data) {
|
|
53
|
-
var env = data.env || 'default';
|
|
54
|
-
data.env = env;
|
|
55
|
-
var file = config.path[env];
|
|
56
|
-
var options = config.options;
|
|
57
|
-
if (file && !isLoadCss[env]) {
|
|
58
|
-
loadCss(ctx, injector, { options: options, env: env, file: file });
|
|
59
|
-
isLoadCss[env] = true;
|
|
60
|
-
}
|
|
61
|
-
handleDataPre(ctx, data, ['.css', '.sass', '.styl']);
|
|
62
|
-
data.predicate = function (ctx, options) { return options.env === env; };
|
|
63
|
-
});
|
|
64
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var CleanCSS = require('clean-css');
|
|
3
|
-
module.exports = function (injector, env, options) { return function () {
|
|
4
|
-
return Promise.all(injector.get('css', { env: env }).toPromise())
|
|
5
|
-
.then(function (values) { return values.join('\n'); })
|
|
6
|
-
.then(function (source) {
|
|
7
|
-
var output = new CleanCSS(options).minify(source);
|
|
8
|
-
if (output.error)
|
|
9
|
-
throw output.error;
|
|
10
|
-
return output.styles;
|
|
11
|
-
});
|
|
12
|
-
}; };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
/**
|
|
3
|
-
* 兼容以前的版本 v0.2
|
|
4
|
-
* injector.register('css', {text: '.book{font-size:2rem}'});
|
|
5
|
-
* injector.register('css', {path: 'xxxx.css'});
|
|
6
|
-
*/
|
|
7
|
-
var resolve = require('path').resolve;
|
|
8
|
-
module.exports = function (ctx, data, suffixes) {
|
|
9
|
-
if (suffixes === void 0) { suffixes = []; }
|
|
10
|
-
if (data.path) {
|
|
11
|
-
data.value = function () { return ctx.render.render({ path: resolve(ctx.base_dir, data.path) }); };
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
if (data.text) {
|
|
15
|
-
data.value = data.text;
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (typeof data.value === 'string') {
|
|
19
|
-
var str_1 = data.value;
|
|
20
|
-
for (var _i = 0, suffixes_1 = suffixes; _i < suffixes_1.length; _i++) {
|
|
21
|
-
var suffix = suffixes_1[_i];
|
|
22
|
-
if (str_1.endsWith(suffix)) {
|
|
23
|
-
data.value = function () { return ctx.render.render({ path: resolve(ctx.base_dir, str_1) }); };
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var handleDataPre = require('./handle-data-pre');
|
|
3
|
-
var jsGenerator = require('./js-generator');
|
|
4
|
-
var loadJsScript = function (ctx, injector, config) {
|
|
5
|
-
var generator = ctx.extend.generator;
|
|
6
|
-
var REGISTER_JS = injector.order.REGISTER_JS;
|
|
7
|
-
var url_for = require('hexo-util').url_for.bind(ctx);
|
|
8
|
-
injector.register('body-end', {
|
|
9
|
-
value: "<script src=\"".concat(url_for(config.path), "\"></script>"),
|
|
10
|
-
priority: REGISTER_JS
|
|
11
|
-
});
|
|
12
|
-
generator.register('js-bundler', function () {
|
|
13
|
-
return {
|
|
14
|
-
path: config.path,
|
|
15
|
-
data: jsGenerator(injector, config.options)
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
module.exports = function (ctx, injector) {
|
|
20
|
-
var config = injector.config.js;
|
|
21
|
-
if (!config.enable)
|
|
22
|
-
return;
|
|
23
|
-
var filter = ctx.extend.filter;
|
|
24
|
-
var isLoadJsScript = false;
|
|
25
|
-
filter.register('injector2:register-js', function (data) {
|
|
26
|
-
if (!isLoadJsScript) {
|
|
27
|
-
loadJsScript(ctx, injector, config);
|
|
28
|
-
isLoadJsScript = true;
|
|
29
|
-
}
|
|
30
|
-
handleDataPre(ctx, data, ['.js']);
|
|
31
|
-
});
|
|
32
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var minify = require('terser').minify;
|
|
3
|
-
module.exports = function (injector, options) { return function () {
|
|
4
|
-
return Promise.all(injector.get('js').toPromise())
|
|
5
|
-
.then(function (values) { return values.join('\n'); })
|
|
6
|
-
.then(function (source) { return minify(source, options); })
|
|
7
|
-
.then(function (result) { return result.code; });
|
|
8
|
-
}; };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export const disable_default_point: boolean;
|
|
2
|
-
export const injector_point_headbegin: boolean;
|
|
3
|
-
export const injector_point_headend: boolean;
|
|
4
|
-
export const injector_point_bodybegin: boolean;
|
|
5
|
-
export const injector_point_bodyend: boolean;
|
|
6
|
-
export const load_next_compatible: boolean;
|
|
7
|
-
export const load_next_plugin: boolean;
|
|
8
|
-
export namespace js {
|
|
9
|
-
const enable: boolean;
|
|
10
|
-
const path: string;
|
|
11
|
-
const options: {};
|
|
12
|
-
}
|
|
13
|
-
export namespace css {
|
|
14
|
-
const enable_1: boolean;
|
|
15
|
-
export { enable_1 as enable };
|
|
16
|
-
export namespace path_1 {
|
|
17
|
-
namespace _default {
|
|
18
|
-
const path_2: string;
|
|
19
|
-
export { path_2 as path };
|
|
20
|
-
export const link: string;
|
|
21
|
-
}
|
|
22
|
-
export { _default as default };
|
|
23
|
-
export namespace dark {
|
|
24
|
-
const path_3: string;
|
|
25
|
-
export { path_3 as path };
|
|
26
|
-
const link_1: string;
|
|
27
|
-
export { link_1 as link };
|
|
28
|
-
}
|
|
29
|
-
export namespace light {
|
|
30
|
-
const path_4: string;
|
|
31
|
-
export { path_4 as path };
|
|
32
|
-
const link_2: string;
|
|
33
|
-
export { link_2 as link };
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
export { path_1 as path };
|
|
37
|
-
const options_1: {};
|
|
38
|
-
export { options_1 as options };
|
|
39
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
module.exports = {
|
|
3
|
-
/**
|
|
4
|
-
* Injector Point
|
|
5
|
-
* If helper used, it will set injector_point_<key> to true
|
|
6
|
-
*/
|
|
7
|
-
disable_default_point: false,
|
|
8
|
-
injector_point_headbegin: false,
|
|
9
|
-
injector_point_headend: false,
|
|
10
|
-
injector_point_bodybegin: false,
|
|
11
|
-
injector_point_bodyend: false,
|
|
12
|
-
/**
|
|
13
|
-
* NexT Plugin
|
|
14
|
-
*/
|
|
15
|
-
load_next_compatible: true,
|
|
16
|
-
load_next_plugin: true,
|
|
17
|
-
/**
|
|
18
|
-
* Js bundler config, use terser
|
|
19
|
-
*/
|
|
20
|
-
js: {
|
|
21
|
-
enable: true,
|
|
22
|
-
path: 'js/injector.js',
|
|
23
|
-
options: {}
|
|
24
|
-
},
|
|
25
|
-
/**
|
|
26
|
-
* CSS bundler config, use clean css
|
|
27
|
-
*/
|
|
28
|
-
css: {
|
|
29
|
-
enable: true,
|
|
30
|
-
path: {
|
|
31
|
-
"default": {
|
|
32
|
-
path: 'css/injector/main.css',
|
|
33
|
-
link: 'load'
|
|
34
|
-
},
|
|
35
|
-
dark: {
|
|
36
|
-
path: 'css/injector/dark.css',
|
|
37
|
-
link: 'preload'
|
|
38
|
-
},
|
|
39
|
-
light: {
|
|
40
|
-
path: 'css/injector/light.css',
|
|
41
|
-
link: 'preload'
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
options: {}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var injectFilter = function (injector) { return function (data, locals) {
|
|
3
|
-
function inject(data, pattern, flag, isBegin) {
|
|
4
|
-
if (isBegin === void 0) { isBegin = true; }
|
|
5
|
-
if (injector.config["injector_point_".concat(injector.formatKey(flag))])
|
|
6
|
-
return data;
|
|
7
|
-
var code = injector.get(flag, { context: locals }).text();
|
|
8
|
-
if (!code.length)
|
|
9
|
-
return data;
|
|
10
|
-
return data.replace(pattern, function (str) { return isBegin ? str + code : code + str; });
|
|
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
|
-
return data;
|
|
21
|
-
}; };
|
|
22
|
-
module.exports = injectFilter;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var injectorHelper = require('./injector');
|
|
3
|
-
module.exports = function (injector, ctx) { return function (point) {
|
|
4
|
-
var nextInject = ctx.theme.injects[point]
|
|
5
|
-
.map(function (item) { return ctx.partial(item.layout, item.locals, item.options); })
|
|
6
|
-
.join('');
|
|
7
|
-
var injector2 = injectorHelper(injector, ctx)(point).text();
|
|
8
|
-
if (point === 'head') {
|
|
9
|
-
injector2 += injectorHelper(injector, ctx)('head-end').text();
|
|
10
|
-
}
|
|
11
|
-
return nextInject + injector2;
|
|
12
|
-
}; };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export = Injector;
|
|
2
|
-
declare class Injector {
|
|
3
|
-
constructor(ctx: any);
|
|
4
|
-
_store: {};
|
|
5
|
-
_run: {};
|
|
6
|
-
_ctx: any;
|
|
7
|
-
order: {
|
|
8
|
-
REGISTER_NEXT_HELPER: number;
|
|
9
|
-
REGISTER_VARIABLE: number;
|
|
10
|
-
REGISTER_STYLE: number;
|
|
11
|
-
REGISTER_JS: number;
|
|
12
|
-
REGISTER_CSS: number;
|
|
13
|
-
};
|
|
14
|
-
config: any;
|
|
15
|
-
clean(): void;
|
|
16
|
-
get(entry: any, options: any): {
|
|
17
|
-
list: () => any[];
|
|
18
|
-
rendered: () => any[];
|
|
19
|
-
text: (sep?: string) => string;
|
|
20
|
-
toPromise: () => Promise<any>[];
|
|
21
|
-
};
|
|
22
|
-
getSize(entry: any): any;
|
|
23
|
-
register(entry: any, value: any, predicate: () => boolean, priority: number, isRun: any): Injector;
|
|
24
|
-
is(...types: any[]): (locals: any) => boolean;
|
|
25
|
-
formatKey(entry: any): any;
|
|
26
|
-
registerDefaultPoint(): void;
|
|
27
|
-
registerHelper(): void;
|
|
28
|
-
registerNexTHelper(): void;
|
|
29
|
-
}
|