hexo-theme-shokax 0.4.12 → 0.4.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,89 +1,105 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
4
10
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var injects_exports = {};
29
+ __export(injects_exports, {
30
+ default: () => injects_default
31
+ });
32
+ module.exports = __toCommonJS(injects_exports);
33
+ var import_node_fs = __toESM(require("node:fs"));
34
+ var import_node_path = __toESM(require("node:path"));
35
+ var import_injects_point = __toESM(require("./injects-point"));
6
36
  /*!
7
37
  inject.js in next-theme/hexo-theme-next by next-theme
8
38
  under GNU AFFERO GENERAL PUBLIC LICENSE v3.0 OR LATER
9
39
  https://github.com/next-theme/hexo-theme-next/blob/master/LICENSE.md
10
40
  */
11
- const node_fs_1 = __importDefault(require("node:fs"));
12
- const node_path_1 = __importDefault(require("node:path"));
13
- const injects_point_1 = __importDefault(require("./injects-point"));
14
- const defaultExtname = '.pug';
41
+ const defaultExtname = ".pug";
15
42
  class StylusInject {
16
- files;
17
- base_dir;
18
- constructor(base_dir) {
19
- this.base_dir = base_dir;
20
- this.files = [];
21
- }
22
- push(file) {
23
- this.files.push(node_path_1.default.resolve(this.base_dir, file));
24
- }
43
+ files;
44
+ base_dir;
45
+ constructor(base_dir) {
46
+ this.base_dir = base_dir;
47
+ this.files = [];
48
+ }
49
+ push(file) {
50
+ this.files.push(import_node_path.default.resolve(this.base_dir, file));
51
+ }
25
52
  }
26
- // Defining view types
27
53
  class ViewInject {
28
- base_dir;
29
- raws;
30
- constructor(base_dir) {
31
- this.base_dir = base_dir;
32
- this.raws = [];
33
- }
34
- raw(name, raw, ...args) {
35
- // Set default extname
36
- if (node_path_1.default.extname(name) === '') {
37
- name += defaultExtname;
38
- }
39
- this.raws.push({ name, raw, args });
54
+ base_dir;
55
+ raws;
56
+ constructor(base_dir) {
57
+ this.base_dir = base_dir;
58
+ this.raws = [];
59
+ }
60
+ raw(name, raw, ...args) {
61
+ if (import_node_path.default.extname(name) === "") {
62
+ name += defaultExtname;
40
63
  }
41
- file(name, file, ...args) {
42
- // Set default extname from file's extname
43
- if (node_path_1.default.extname(name) === '') {
44
- name += node_path_1.default.extname(file);
45
- }
46
- // Get absolute path base on hexo dir
47
- this.raw(name, node_fs_1.default.readFileSync(node_path_1.default.resolve(this.base_dir, file), 'utf8'), ...args);
64
+ this.raws.push({ name, raw, args });
65
+ }
66
+ file(name, file, ...args) {
67
+ if (import_node_path.default.extname(name) === "") {
68
+ name += import_node_path.default.extname(file);
48
69
  }
70
+ this.raw(name, import_node_fs.default.readFileSync(import_node_path.default.resolve(this.base_dir, file), "utf8"), ...args);
71
+ }
49
72
  }
50
- // Init injects
51
73
  function initInject(base_dir) {
52
- const injects = {};
53
- injects_point_1.default.styles.forEach(item => {
54
- injects[item] = new StylusInject(base_dir);
55
- });
56
- injects_point_1.default.views.forEach(item => {
57
- injects[item] = new ViewInject(base_dir);
58
- });
59
- return injects;
74
+ const injects = {};
75
+ import_injects_point.default.styles.forEach((item) => {
76
+ injects[item] = new StylusInject(base_dir);
77
+ });
78
+ import_injects_point.default.views.forEach((item) => {
79
+ injects[item] = new ViewInject(base_dir);
80
+ });
81
+ return injects;
60
82
  }
61
- exports.default = (hexo) => {
62
- // Exec theme_inject filter
63
- const injects = initInject(hexo.base_dir);
64
- hexo.execFilterSync('theme_inject', injects);
65
- hexo.theme.config.injects = {};
66
- // Inject stylus
67
- injects_point_1.default.styles.forEach(type => {
68
- hexo.theme.config.injects[type] = injects[type].files;
69
- });
70
- // Inject views
71
- injects_point_1.default.views.forEach(type => {
72
- const configs = Object.create(null);
73
- hexo.theme.config.injects[type] = [];
74
- // Add or override view.
75
- injects[type].raws.forEach((injectObj, index) => {
76
- const name = `inject/${type}/${injectObj.name}`;
77
- hexo.theme.setView(name, injectObj.raw);
78
- configs[name] = {
79
- layout: name,
80
- locals: injectObj.args[0],
81
- options: injectObj.args[1],
82
- order: injectObj.args[2] || index
83
- };
84
- });
85
- // Views sort.
86
- hexo.theme.config.injects[type] = Object.values(configs)
87
- .sort((x, y) => x.order - y.order);
83
+ var injects_default = (hexo) => {
84
+ const injects = initInject(hexo.base_dir);
85
+ hexo.execFilterSync("theme_inject", injects);
86
+ hexo.theme.config.injects = {};
87
+ import_injects_point.default.styles.forEach((type) => {
88
+ hexo.theme.config.injects[type] = injects[type].files;
89
+ });
90
+ import_injects_point.default.views.forEach((type) => {
91
+ const configs = /* @__PURE__ */ Object.create(null);
92
+ hexo.theme.config.injects[type] = [];
93
+ injects[type].raws.forEach((injectObj, index) => {
94
+ const name = `inject/${type}/${injectObj.name}`;
95
+ hexo.theme.setView(name, injectObj.raw);
96
+ configs[name] = {
97
+ layout: name,
98
+ locals: injectObj.args[0],
99
+ options: injectObj.args[1],
100
+ order: injectObj.args[2] || index
101
+ };
88
102
  });
103
+ hexo.theme.config.injects[type] = Object.values(configs).sort((x, y) => x.order - y.order);
104
+ });
89
105
  };
@@ -1,44 +1,61 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from))
10
+ if (!__hasOwnProp.call(to, key) && key !== except)
11
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ }
13
+ return to;
4
14
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_fs_1 = __importDefault(require("node:fs"));
7
- const node_path_1 = __importDefault(require("node:path"));
8
- const js_yaml_1 = __importDefault(require("js-yaml"));
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var import_node_fs = __toESM(require("node:fs"));
24
+ var import_node_path = __toESM(require("node:path"));
25
+ var import_js_yaml = __toESM(require("js-yaml"));
9
26
  function linkGrid(args, content) {
10
- const theme = hexo.theme.config;
11
- if (!args[0] && !content) {
12
- return;
27
+ const theme = hexo.theme.config;
28
+ if (!args[0] && !content) {
29
+ return;
30
+ }
31
+ if (args[0]) {
32
+ const filepath = import_node_path.default.join(hexo.source_dir, args[0]);
33
+ if (import_node_fs.default.existsSync(filepath)) {
34
+ content = import_node_fs.default.readFileSync(filepath, { encoding: "utf-8" });
13
35
  }
14
- if (args[0]) {
15
- const filepath = node_path_1.default.join(hexo.source_dir, args[0]);
16
- if (node_fs_1.default.existsSync(filepath)) {
17
- content = node_fs_1.default.readFileSync(filepath, { encoding: 'utf-8' });
18
- }
36
+ }
37
+ if (!content) {
38
+ return;
39
+ }
40
+ const list = import_js_yaml.default.load(content);
41
+ let result = "";
42
+ list.forEach((item) => {
43
+ if (!item.url || !item.site) {
44
+ return;
19
45
  }
20
- if (!content) {
21
- return;
46
+ let item_image = item.image || theme.assets + "/404.png";
47
+ if (!item_image.startsWith("//") && !item_image.startsWith("http")) {
48
+ item_image = theme.statics + item_image;
22
49
  }
23
- const list = js_yaml_1.default.load(content);
24
- let result = '';
25
- list.forEach((item) => {
26
- if (!item.url || !item.site) {
27
- return;
28
- }
29
- let item_image = item.image || theme.assets + '/404.png';
30
- if (!item_image.startsWith('//') && !item_image.startsWith('http')) {
31
- item_image = theme.statics + item_image;
32
- }
33
- item.color = item.color ? ` style="--block-color:${item.color};"` : '';
34
- result += `<div class="item" title="${item.owner || item.site}"${item.color}>`;
35
- result += `<a href="${item.url}" class="image" data-background-image="${item_image}"></a>
50
+ item.color = item.color ? ` style="--block-color:${item.color};"` : "";
51
+ result += `<div class="item" title="${item.owner || item.site}"${item.color}>`;
52
+ result += `<a href="${item.url}" class="image" data-background-image="${item_image}"></a>
36
53
  <div class="info">
37
54
  <a href="${item.url}" class="title">${item.site}</a>
38
55
  <p class="desc">${item.desc || item.url}</p>
39
56
  </div></div>`;
40
- });
41
- return `<div class="links">${result}</div>`;
57
+ });
58
+ return `<div class="links">${result}</div>`;
42
59
  }
43
- hexo.extend.tag.register('links', linkGrid, { ends: true });
44
- hexo.extend.tag.register('linksfile', linkGrid, { ends: false, async: true });
60
+ hexo.extend.tag.register("links", linkGrid, { ends: true });
61
+ hexo.extend.tag.register("linksfile", linkGrid, { ends: false, async: true });
@@ -1,19 +1,36 @@
1
- 'use strict';
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
4
15
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- /* global hexo */
7
- const js_yaml_1 = __importDefault(require("js-yaml"));
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var import_js_yaml = __toESM(require("js-yaml"));
8
25
  function postMedia(args, content) {
9
- if (!args[0] || !content) {
10
- return;
11
- }
12
- const list = js_yaml_1.default.load(content);
13
- switch (args[0]) {
14
- case 'video':
15
- case 'audio':
16
- return `<div class="media-container"><div class="player" data-type="${args[0]}" data-src='${JSON.stringify(list)}'></div></div>`;
17
- }
26
+ if (!args[0] || !content) {
27
+ return;
28
+ }
29
+ const list = import_js_yaml.default.load(content);
30
+ switch (args[0]) {
31
+ case "video":
32
+ case "audio":
33
+ return `<div class="media-container"><div class="player" data-type="${args[0]}" data-src='${JSON.stringify(list)}'></div></div>`;
34
+ }
18
35
  }
19
- hexo.extend.tag.register('media', postMedia, { ends: true });
36
+ hexo.extend.tag.register("media", postMedia, { ends: true });
package/scripts/utils.js CHANGED
@@ -1,20 +1,42 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getVendorLink = getVendorLink;
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var utils_exports = {};
19
+ __export(utils_exports, {
20
+ getVendorLink: () => getVendorLink
21
+ });
22
+ module.exports = __toCommonJS(utils_exports);
4
23
  function getVendorLink(hexo, source) {
5
- const vendorsCfg = hexo.theme.config.vendors;
6
- if (source.source === "local") {
7
- return {
8
- url: source.url,
9
- local: true,
10
- sri: ''
11
- };
12
- }
13
- else {
14
- return {
15
- url: vendorsCfg.cdns[source.source] + '/' + source.url,
16
- local: false,
17
- sri: source.sri
18
- };
19
- }
24
+ const vendorsCfg = hexo.theme.config.vendors;
25
+ if (source.source === "local") {
26
+ return {
27
+ url: source.url,
28
+ local: true,
29
+ sri: ""
30
+ };
31
+ } else {
32
+ return {
33
+ url: vendorsCfg.cdns[source.source] + "/" + source.url,
34
+ local: false,
35
+ sri: source.sri
36
+ };
37
+ }
20
38
  }
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ getVendorLink
42
+ });
@@ -5,35 +5,19 @@ compatibility: ShokaX v0.4.x
5
5
  import path from "node:path";
6
6
  import fs from 'fs/promises'
7
7
  import child_process from 'child_process'
8
+ import { buildSync } from 'esbuild'
9
+ import { glob } from 'glob'
8
10
 
9
11
  const CONFIG = {
10
- legacyScript: true,
12
+ legacyScript: false,
11
13
  }
12
14
 
13
- async function deleteFileRecursive(dir) {
14
- const files = await fs.readdir(dir)
15
- for (const f of files) {
16
- const fullPath = path.join(dir, f)
17
- const stat = await fs.lstat(fullPath)
18
- if (stat.isDirectory()) {
19
- await deleteFileRecursive(fullPath)
20
- } else {
21
- const fileExt = path.extname(f)
22
- if (fileExt === '.ts' || fileExt === '.json' || fileExt === '.tsbuildinfo') {
23
- await fs.unlink(fullPath)
24
- }
25
- }
26
- }
27
- }
28
15
  console.log('ShokaX ToolBox - Compiler')
29
16
  console.log('Start compiling...')
30
17
 
31
- let hexoRoot = path.join(import.meta.url, './../../../../').trim()
32
- if (hexoRoot.startsWith('file:/')) {
33
- hexoRoot = hexoRoot.slice(5); // 去除 'file://'
34
- } else if (hexoRoot.startsWith('file:\\')) {
35
- hexoRoot = hexoRoot.slice(8); // 去除 'file:\'
36
- }
18
+ const entryPoints = await glob('./scripts/**/*.ts');
19
+ const jsons = await glob('./scripts/**/*.json');
20
+
37
21
  if (CONFIG.legacyScript) {
38
22
  console.log('Simulating legacy script compiler...')
39
23
  let sPath = path.join(import.meta.url, './../../scripts/').trim()
@@ -49,12 +33,34 @@ if (CONFIG.legacyScript) {
49
33
  cwd: sPath
50
34
  }, async (code, stdout, stderr) => {
51
35
  console.log('Deleting typescript files...')
52
- await deleteFileRecursive(sPath)
36
+ for (const entry of entryPoints) {
37
+ await fs.unlink(entry)
38
+ }
39
+ for (const entry of jsons) {
40
+ await fs.unlink(entry)
41
+ }
53
42
  console.log('Finished compiling.')
54
43
  })
55
44
  })
56
45
  } else {
57
- throw Error('Not implemented yet.')
46
+ console.log('RUN THIS SCRIPT IN YOUR SHOKAX THEME ROOT DIRECTORY!')
47
+ console.log('Using esbuild compiler...')
48
+ buildSync({
49
+ entryPoints: entryPoints,
50
+ outdir: 'scripts',
51
+ bundle: false,
52
+ format: 'cjs',
53
+ target: ['esnext'],
54
+ platform: 'node',
55
+ loader: { '.ts': 'ts' },
56
+ })
57
+ entryPoints.forEach(async (entry) => {
58
+ await fs.unlink(entry)
59
+ })
60
+ jsons.forEach(async (entry)=>{
61
+ await fs.unlink(entry)
62
+ })
63
+ console.log('Finished compiling.')
58
64
  }
59
65
 
60
66
  console.log('Done.')