hexo-theme-shokax 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,42 +1,39 @@
1
- 'use strict'
2
- /* global hexo */
3
-
4
- const merge = require('hexo-util').deepMerge || require('lodash/merge')
5
- const fs = require('hexo-fs')
6
- const path = require('path')
7
- const yaml = require('js-yaml')
8
-
1
+ 'use strict';
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const hexo_util_1 = __importDefault(require("hexo-util"));
7
+ const hexo_fs_1 = __importDefault(require("hexo-fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const js_yaml_1 = __importDefault(require("js-yaml"));
9
10
  hexo.extend.filter.register('before_generate', () => {
10
- if (hexo.config.theme_config) {
11
- hexo.theme.config = merge(hexo.theme.config, hexo.config.theme_config)
12
- }
13
-
14
- const data = hexo.locals.get('data')
15
-
16
- if (data.languages) {
17
- const { i18n } = hexo.theme
18
-
19
- const mergeLang = lang => {
20
- if (data.languages[lang]) { i18n.set(lang, merge(i18n.get([lang]), data.languages[lang])) }
11
+ if (hexo.config.theme_config) {
12
+ hexo.theme.config = hexo_util_1.default.deepMerge(hexo.theme.config, hexo.config.theme_config);
21
13
  }
22
-
23
- for (const lang of ['en', 'ja', 'zh-CN', 'zh-HK', 'zh-TW']) {
24
- mergeLang(lang)
14
+ const data = hexo.locals.get('data');
15
+ if (data.languages) {
16
+ const { i18n } = hexo.theme;
17
+ const mergeLang = lang => {
18
+ if (data.languages[lang]) {
19
+ i18n.set(lang, hexo_util_1.default.deepMerge(i18n.get([lang]), data.languages[lang]));
20
+ }
21
+ };
22
+ for (const lang of ['en', 'ja', 'zh-CN', 'zh-HK', 'zh-TW']) {
23
+ mergeLang(lang);
24
+ }
25
25
  }
26
- }
27
-
28
- hexo.theme.config.style = {}
29
-
30
- for (const style of ['iconfont', 'colors', 'custom']) {
31
- const custom_file = 'source/_data/' + style + '.styl'
32
- if (fs.existsSync(custom_file)) {
33
- hexo.theme.config.style[style] = path.resolve(hexo.base_dir, custom_file)
26
+ hexo.theme.config.style = {};
27
+ for (const style of ['iconfont', 'colors', 'custom']) {
28
+ const custom_file = 'source/_data/' + style + '.styl';
29
+ if (hexo_fs_1.default.existsSync(custom_file)) {
30
+ hexo.theme.config.style[style] = path_1.default.resolve(hexo.base_dir, custom_file);
31
+ }
34
32
  }
35
- }
36
-
37
- if (data.images && data.images.length >= 6) {
38
- hexo.theme.config.image_list = data.images
39
- } else {
40
- hexo.theme.config.image_list = yaml.load(fs.readFileSync(path.join(__dirname, '../../_images.yml')))
41
- }
42
- })
33
+ if (data.images && data.images.length >= 6) {
34
+ hexo.theme.config.image_list = data.images;
35
+ }
36
+ else {
37
+ hexo.theme.config.image_list = js_yaml_1.default.load(hexo_fs_1.default.readFileSync(path_1.default.join(__dirname, '../../_images.yml')));
38
+ }
39
+ });
@@ -1,25 +1,24 @@
1
- /* global hexo */
2
- 'use strict'
3
-
4
- const fs = require('hexo-fs')
5
-
1
+ 'use strict';
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const hexo_fs_1 = __importDefault(require("hexo-fs"));
6
7
  hexo.extend.generator.register('images', function (locals) {
7
- const theme = hexo.theme.config
8
- const dir = 'source/_data/' + theme.assets + '/'
9
-
10
- if (!fs.existsSync(dir)) { return }
11
-
12
- const result = []
13
- const files = fs.listDirSync(dir)
14
-
15
- files.forEach((file) => {
16
- result.push({
17
- path: theme.assets + '/' + file,
18
- data: function () {
19
- return fs.createReadStream(dir + file)
20
- }
21
- })
22
- })
23
-
24
- return result
25
- })
8
+ const theme = hexo.theme.config;
9
+ const dir = 'source/_data/' + theme.assets + '/';
10
+ if (!hexo_fs_1.default.existsSync(dir)) {
11
+ return;
12
+ }
13
+ const result = [];
14
+ const files = hexo_fs_1.default.listDirSync(dir);
15
+ files.forEach((file) => {
16
+ result.push({
17
+ path: theme.assets + '/' + file,
18
+ data: function () {
19
+ return hexo_fs_1.default.createReadStream(dir + file);
20
+ }
21
+ });
22
+ });
23
+ return result;
24
+ });
@@ -1,109 +1,104 @@
1
- /* global hexo */
2
- 'use strict'
3
-
4
- const fs = require('hexo-fs')
5
- const pagination = require('hexo-pagination')
6
-
1
+ 'use strict';
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const hexo_fs_1 = __importDefault(require("hexo-fs"));
7
+ const hexo_pagination_1 = __importDefault(require("hexo-pagination"));
7
8
  hexo.config.index_generator = Object.assign({
8
- per_page: typeof hexo.config.per_page === 'undefined' ? 10 : hexo.config.per_page,
9
- order_by: '-date'
10
- }, hexo.config.index_generator)
11
-
9
+ per_page: typeof hexo.config.per_page === 'undefined' ? 10 : hexo.config.per_page,
10
+ order_by: '-date'
11
+ }, hexo.config.index_generator);
12
12
  hexo.extend.generator.register('index', function (locals) {
13
- const covers = []
14
- const catlist = []
15
- let pages
16
- const config = hexo.config
17
- const sticky = locals.posts.find({ sticky: true }).sort(config.index_generator.order_by)
18
- const posts = locals.posts.find({ sticky: { $exists: false } }).sort(config.index_generator.order_by)
19
- const paginationDir = config.pagination_dir || 'page'
20
- const path = config.index_generator.path || ''
21
- const categories = locals.categories
22
-
23
- const getTopcat = function (cat) {
24
- if (cat.parent) {
25
- const pCat = categories.findOne({ _id: cat.parent })
26
- return getTopcat(pCat)
27
- } else {
28
- return cat
29
- }
30
- }
31
-
32
- if (categories && categories.length) {
33
- categories.forEach((cat) => {
34
- const cover = `source/_posts/${cat.slug}`
35
- if (fs.existsSync(cover + '/cover.avif')) {
36
- covers.push({
37
- path: cat.slug + '/cover.avif',
38
- data: function () {
39
- return fs.createReadStream(cover + '/cover.avif')
40
- }
41
- })
42
- } else if (fs.existsSync(cover + '/cover.webp')) {
43
- covers.push({
44
- path: cat.slug + '/cover.webp',
45
- data: function () {
46
- return fs.createReadStream(cover + '/cover.webp')
47
- }
48
- })
49
- } else if (fs.existsSync(cover + '/cover.jpg')) {
50
- covers.push({
51
- path: cat.slug + '/cover.jpg',
52
- data: function () {
53
- return fs.createReadStream(cover + '/cover.jpg')
54
- }
55
- })
56
-
57
- const topcat = getTopcat(cat)
58
-
59
- if (topcat._id !== cat._id) {
60
- cat.top = topcat
13
+ const covers = [];
14
+ const catlist = [];
15
+ let pages;
16
+ const config = hexo.config;
17
+ const sticky = locals.posts.find({ sticky: true }).sort(config.index_generator.order_by);
18
+ const posts = locals.posts.find({ sticky: { $exists: false } }).sort(config.index_generator.order_by);
19
+ const paginationDir = config.pagination_dir || 'page';
20
+ const path = config.index_generator.path || '';
21
+ const categories = locals.categories;
22
+ const getTopcat = function (cat) {
23
+ if (cat.parent) {
24
+ const pCat = categories.findOne({ _id: cat.parent });
25
+ return getTopcat(pCat);
61
26
  }
62
-
63
- const child = categories.find({ parent: cat._id })
64
- let pl = 6
65
-
66
- if (child.length !== 0) {
67
- cat.child = child.length
68
- cat.subs = child.sort({ name: 1 }).limit(6).toArray()
69
- pl = Math.max(0, pl - child.length)
70
- if (pl > 0) {
71
- // TODO 需要测试
72
- cat.subs.push.apply(cat.subs, cat.posts.sort({ title: 1 }).filter(function (item, i) {
73
- return item.categories.last()._id === cat._id
74
- }).limit(pl).toArray())
75
- }
76
- } else {
77
- cat.subs = cat.posts.sort({ title: 1 }).limit(6).toArray()
27
+ else {
28
+ return cat;
78
29
  }
79
-
80
- catlist.push(cat)
81
- }
82
- })
83
- }
84
-
85
- if (posts.length > 0) {
86
- pages = pagination(path, posts, {
87
- perPage: config.index_generator.per_page,
88
- layout: ['index', 'archive'],
89
- format: paginationDir + '/%d/',
90
- data: {
91
- __index: true,
92
- catlist,
93
- sticky
94
- }
95
- })
96
- } else {
97
- pages = [{
98
- path,
99
- layout: ['index', 'archive'],
100
- data: {
101
- __index: true,
102
- catlist,
103
- sticky
104
- }
105
- }]
106
- }
107
-
108
- return [...covers, ...pages]
109
- })
30
+ };
31
+ if (categories && categories.length) {
32
+ categories.forEach((cat) => {
33
+ const cover = `source/_posts/${cat.slug}`;
34
+ if (hexo_fs_1.default.existsSync(cover + '/cover.avif')) {
35
+ covers.push({
36
+ path: cat.slug + '/cover.avif',
37
+ data: function () {
38
+ return hexo_fs_1.default.createReadStream(cover + '/cover.avif');
39
+ }
40
+ });
41
+ }
42
+ else if (hexo_fs_1.default.existsSync(cover + '/cover.webp')) {
43
+ covers.push({
44
+ path: cat.slug + '/cover.webp',
45
+ data: function () {
46
+ return hexo_fs_1.default.createReadStream(cover + '/cover.webp');
47
+ }
48
+ });
49
+ }
50
+ else if (hexo_fs_1.default.existsSync(cover + '/cover.jpg')) {
51
+ covers.push({
52
+ path: cat.slug + '/cover.jpg',
53
+ data: function () {
54
+ return hexo_fs_1.default.createReadStream(cover + '/cover.jpg');
55
+ }
56
+ });
57
+ const topcat = getTopcat(cat);
58
+ if (topcat._id !== cat._id) {
59
+ cat.top = topcat;
60
+ }
61
+ const child = categories.find({ parent: cat._id });
62
+ let pl = 6;
63
+ if (child.length !== 0) {
64
+ cat.child = child.length;
65
+ cat.subs = child.sort({ name: 1 }).limit(6).toArray();
66
+ pl = Math.max(0, pl - child.length);
67
+ if (pl > 0) {
68
+ cat.subs.push(...cat.posts.sort({ title: 1 })
69
+ .filter(function (item, i) { return item.categories.last()._id === cat._id; })
70
+ .limit(pl).toArray());
71
+ }
72
+ }
73
+ else {
74
+ cat.subs = cat.posts.sort({ title: 1 }).limit(6).toArray();
75
+ }
76
+ catlist.push(cat);
77
+ }
78
+ });
79
+ }
80
+ if (posts.length > 0) {
81
+ pages = (0, hexo_pagination_1.default)(path, posts, {
82
+ perPage: config.index_generator.per_page,
83
+ layout: ['index', 'archive'],
84
+ format: paginationDir + '/%d/',
85
+ data: {
86
+ __index: true,
87
+ catlist,
88
+ sticky
89
+ }
90
+ });
91
+ }
92
+ else {
93
+ pages = [{
94
+ path,
95
+ layout: ['index', 'archive'],
96
+ data: {
97
+ __index: true,
98
+ catlist,
99
+ sticky
100
+ }
101
+ }];
102
+ }
103
+ return [...covers, ...pages];
104
+ });
@@ -1,19 +1,16 @@
1
- /* global hexo */
2
- 'use strict'
3
-
1
+ 'use strict';
4
2
  hexo.extend.generator.register('pages', function (locals) {
5
- const config = hexo.config
6
-
7
- return [
8
- {
9
- path: config.category_dir + '/index.html',
10
- data: { type: 'categories' },
11
- layout: ['page']
12
- },
13
- {
14
- path: config.tag_dir + '/index.html',
15
- data: { type: 'tags' },
16
- layout: ['page']
17
- }
18
- ]
19
- })
3
+ const config = hexo.config;
4
+ return [
5
+ {
6
+ path: config.category_dir + '/index.html',
7
+ data: { type: 'categories' },
8
+ layout: ['page']
9
+ },
10
+ {
11
+ path: config.tag_dir + '/index.html',
12
+ data: { type: 'tags' },
13
+ layout: ['page']
14
+ }
15
+ ];
16
+ });
@@ -1,95 +1,96 @@
1
- /* global hexo */
2
- const fs = require('hexo-fs')
3
-
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const package_json_1 = __importDefault(require("../../package.json"));
7
+ const hexo_fs_1 = __importDefault(require("hexo-fs"));
4
8
  hexo.extend.generator.register('script', function (locals) {
5
- const log = hexo.log || console.log
6
- const config = hexo.config
7
- const theme = hexo.theme.config
8
-
9
- const env = require('../../package.json')
10
-
11
- const siteConfig = {
12
- version: env.version,
13
- hostname: config.url,
14
- root: config.root,
15
- statics: theme.statics,
16
- favicon: {
17
- normal: theme.assets + '/favicon.ico',
18
- hidden: theme.assets + '/failure.ico'
19
- },
20
- darkmode: theme.darkmode,
21
- auto_dark: theme.auto_dark,
22
- auto_scroll: theme.auto_scroll,
23
- js: {
24
- chart: theme.vendors.js.chart,
25
- copy_tex: theme.vendors.js.copy_tex,
26
- fancybox: theme.vendors.js.fancybox
27
- },
28
- css: {
29
- valine: theme.css + '/comment.css',
30
- katex: theme.vendors.css.katex,
31
- mermaid: theme.css + '/mermaid.css',
32
- fancybox: theme.vendors.css.fancybox
33
- },
34
- loader: theme.loader,
35
- search: null,
36
- valine: theme.valine, // TODO 废弃属性
37
- outime: {
38
- enable: theme.outime.enable,
39
- days: theme.outime.days
40
- },
41
- quicklink: {
42
- timeout: theme.quicklink.timeout,
43
- priority: theme.quicklink.priority
44
- },
45
- playerAPI: theme.playerAPI,
46
- disableVL: theme.disableVL
47
- }
48
-
49
- if (config?.algolia) {
50
- siteConfig.search = {
51
- appID: config.algolia.appId,
52
- apiKey: config.algolia.apiKey,
53
- indexName: config.algolia.indexName,
54
- hits: theme.search.hits
9
+ const log = hexo.log || console.log;
10
+ const config = hexo.config;
11
+ const theme = hexo.theme.config;
12
+ const siteConfig = {
13
+ version: package_json_1.default.version,
14
+ hostname: config.url,
15
+ root: config.root,
16
+ statics: theme.statics,
17
+ favicon: {
18
+ normal: theme.assets + '/favicon.ico',
19
+ hidden: theme.assets + '/failure.ico'
20
+ },
21
+ darkmode: theme.darkmode,
22
+ auto_dark: theme.auto_dark,
23
+ auto_scroll: theme.auto_scroll,
24
+ js: {
25
+ chart: theme.vendors.js.chart,
26
+ copy_tex: theme.vendors.js.copy_tex,
27
+ fancybox: theme.vendors.js.fancybox
28
+ },
29
+ css: {
30
+ valine: theme.css + '/comment.css',
31
+ katex: theme.vendors.css.katex,
32
+ mermaid: theme.css + '/mermaid.css',
33
+ fancybox: theme.vendors.css.fancybox
34
+ },
35
+ loader: theme.loader,
36
+ search: null,
37
+ valine: theme.valine,
38
+ outime: {
39
+ enable: theme.outime.enable,
40
+ days: theme.outime.days
41
+ },
42
+ quicklink: {
43
+ timeout: theme.quicklink.timeout,
44
+ priority: theme.quicklink.priority
45
+ },
46
+ playerAPI: theme.playerAPI,
47
+ disableVL: theme.disableVL,
48
+ audio: undefined,
49
+ fireworks: undefined
50
+ };
51
+ if (config?.algolia) {
52
+ siteConfig.search = {
53
+ appID: config.algolia.appId,
54
+ apiKey: config.algolia.apiKey,
55
+ indexName: config.algolia.indexName,
56
+ hits: theme.search.hits
57
+ };
55
58
  }
56
- }
57
-
58
- if (theme?.audio) {
59
- siteConfig.audio = theme.audio
60
- }
61
-
62
- let text = '';
63
-
64
- ['library', 'global', 'page', 'vue', 'components'].forEach(function (item) {
65
- if (fs.existsSync(`themes/shokaX/source/js/_app/${item}.js`)) {
66
- text += fs.readFileSync(`themes/shokaX/source/js/_app/${item}.js`).toString()
67
- } else {
68
- text += fs.readFileSync(`node_modules/hexo-theme-shokax/source/js/_app/${item}.js`).toString()
59
+ if (theme?.audio) {
60
+ siteConfig.audio = theme.audio;
69
61
  }
70
- })
71
- if (!theme.experiments?.noPlayer) {
72
- if (fs.existsSync('themes/shokaX/source/js/_app/player.js')) {
73
- text += fs.readFileSync('themes/shokaX/source/js/_app/player.js').toString()
74
- } else {
75
- text += fs.readFileSync('node_modules/hexo-theme-shokax/source/js/_app/player.js').toString()
62
+ let text = '';
63
+ ['library', 'global', 'page', 'vue', 'components'].forEach(function (item) {
64
+ if (hexo_fs_1.default.existsSync(`themes/shokaX/source/js/_app/${item}.js`)) {
65
+ text += hexo_fs_1.default.readFileSync(`themes/shokaX/source/js/_app/${item}.js`).toString();
66
+ }
67
+ else {
68
+ text += hexo_fs_1.default.readFileSync(`node_modules/hexo-theme-shokax/source/js/_app/${item}.js`).toString();
69
+ }
70
+ });
71
+ if (!theme.experiments?.noPlayer) {
72
+ if (hexo_fs_1.default.existsSync('themes/shokaX/source/js/_app/player.js')) {
73
+ text += hexo_fs_1.default.readFileSync('themes/shokaX/source/js/_app/player.js').toString();
74
+ }
75
+ else {
76
+ text += hexo_fs_1.default.readFileSync('node_modules/hexo-theme-shokax/source/js/_app/player.js').toString();
77
+ }
76
78
  }
77
- }
78
- if (theme.fireworks && theme.fireworks.enable) {
79
- if (fs.existsSync('themes/shokaX/source/js/_app/fireworks.js')) {
80
- text += fs.readFileSync('themes/shokaX/source/js/_app/fireworks.js').toString()
81
- } else {
82
- text += fs.readFileSync('node_modules/hexo-theme-shokax/source/js/_app/fireworks.js').toString()
79
+ if (theme.fireworks && theme.fireworks.enable) {
80
+ if (hexo_fs_1.default.existsSync('themes/shokaX/source/js/_app/fireworks.js')) {
81
+ text += hexo_fs_1.default.readFileSync('themes/shokaX/source/js/_app/fireworks.js').toString();
82
+ }
83
+ else {
84
+ text += hexo_fs_1.default.readFileSync('node_modules/hexo-theme-shokax/source/js/_app/fireworks.js').toString();
85
+ }
86
+ siteConfig.fireworks = theme.fireworks.color || ['rgba(255,182,185,.9)', 'rgba(250,227,217,.9)', 'rgba(187,222,214,.9)', 'rgba(138,198,209,.9)'];
83
87
  }
84
- siteConfig.fireworks = theme.fireworks.color || ['rgba(255,182,185,.9)', 'rgba(250,227,217,.9)', 'rgba(187,222,214,.9)', 'rgba(138,198,209,.9)']
85
- }
86
-
87
- text = 'const CONFIG = ' + JSON.stringify(siteConfig) + ';' + text
88
- const result = hexo.render.renderSync({ text, engine: 'js' })
89
- return {
90
- path: theme.js + '/app.js',
91
- data: function () {
92
- return result
93
- }
94
- }
95
- })
88
+ text = 'const CONFIG = ' + JSON.stringify(siteConfig) + ';' + text;
89
+ const result = hexo.render.renderSync({ text, engine: 'js' });
90
+ return {
91
+ path: theme.js + '/app.js',
92
+ data: function () {
93
+ return result;
94
+ }
95
+ };
96
+ });