hexo-theme-shokax 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,25 +1,20 @@
1
- /* global hexo */
2
- 'use strict'
3
-
4
- const fs = require('hexo-fs')
5
-
1
+ 'use strict';
2
+ const fs = require('hexo-fs');
6
3
  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
- })
4
+ const theme = hexo.theme.config;
5
+ const dir = 'source/_data/' + theme.assets + '/';
6
+ if (!fs.existsSync(dir)) {
7
+ return;
8
+ }
9
+ const result = [];
10
+ const files = fs.listDirSync(dir);
11
+ files.forEach((file) => {
12
+ result.push({
13
+ path: theme.assets + '/' + file,
14
+ data: function () {
15
+ return fs.createReadStream(dir + file);
16
+ }
17
+ });
18
+ });
19
+ return result;
20
+ });
@@ -1,109 +1,100 @@
1
- /* global hexo */
2
- 'use strict'
3
-
4
- const fs = require('hexo-fs')
5
- const pagination = require('hexo-pagination')
6
-
1
+ 'use strict';
2
+ const fs = require('hexo-fs');
3
+ const pagination = require('hexo-pagination');
7
4
  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
-
5
+ per_page: typeof hexo.config.per_page === 'undefined' ? 10 : hexo.config.per_page,
6
+ order_by: '-date'
7
+ }, hexo.config.index_generator);
12
8
  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
9
+ const covers = [];
10
+ const catlist = [];
11
+ let pages;
12
+ const config = hexo.config;
13
+ const sticky = locals.posts.find({ sticky: true }).sort(config.index_generator.order_by);
14
+ const posts = locals.posts.find({ sticky: { $exists: false } }).sort(config.index_generator.order_by);
15
+ const paginationDir = config.pagination_dir || 'page';
16
+ const path = config.index_generator.path || '';
17
+ const categories = locals.categories;
18
+ const getTopcat = function (cat) {
19
+ if (cat.parent) {
20
+ const pCat = categories.findOne({ _id: cat.parent });
21
+ return getTopcat(pCat);
61
22
  }
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()
23
+ else {
24
+ return cat;
78
25
  }
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
- })
26
+ };
27
+ if (categories && categories.length) {
28
+ categories.forEach((cat) => {
29
+ const cover = `source/_posts/${cat.slug}`;
30
+ if (fs.existsSync(cover + '/cover.avif')) {
31
+ covers.push({
32
+ path: cat.slug + '/cover.avif',
33
+ data: function () {
34
+ return fs.createReadStream(cover + '/cover.avif');
35
+ }
36
+ });
37
+ }
38
+ else if (fs.existsSync(cover + '/cover.webp')) {
39
+ covers.push({
40
+ path: cat.slug + '/cover.webp',
41
+ data: function () {
42
+ return fs.createReadStream(cover + '/cover.webp');
43
+ }
44
+ });
45
+ }
46
+ else if (fs.existsSync(cover + '/cover.jpg')) {
47
+ covers.push({
48
+ path: cat.slug + '/cover.jpg',
49
+ data: function () {
50
+ return fs.createReadStream(cover + '/cover.jpg');
51
+ }
52
+ });
53
+ const topcat = getTopcat(cat);
54
+ if (topcat._id !== cat._id) {
55
+ cat.top = topcat;
56
+ }
57
+ const child = categories.find({ parent: cat._id });
58
+ let pl = 6;
59
+ if (child.length !== 0) {
60
+ cat.child = child.length;
61
+ cat.subs = child.sort({ name: 1 }).limit(6).toArray();
62
+ pl = Math.max(0, pl - child.length);
63
+ if (pl > 0) {
64
+ cat.subs.push(...cat.posts.sort({ title: 1 })
65
+ .filter(function (item, i) { return item.categories.last()._id === cat._id; })
66
+ .limit(pl).toArray());
67
+ }
68
+ }
69
+ else {
70
+ cat.subs = cat.posts.sort({ title: 1 }).limit(6).toArray();
71
+ }
72
+ catlist.push(cat);
73
+ }
74
+ });
75
+ }
76
+ if (posts.length > 0) {
77
+ pages = pagination(path, posts, {
78
+ perPage: config.index_generator.per_page,
79
+ layout: ['index', 'archive'],
80
+ format: paginationDir + '/%d/',
81
+ data: {
82
+ __index: true,
83
+ catlist,
84
+ sticky
85
+ }
86
+ });
87
+ }
88
+ else {
89
+ pages = [{
90
+ path,
91
+ layout: ['index', 'archive'],
92
+ data: {
93
+ __index: true,
94
+ catlist,
95
+ sticky
96
+ }
97
+ }];
98
+ }
99
+ return [...covers, ...pages];
100
+ });
@@ -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,91 @@
1
- /* global hexo */
2
- const fs = require('hexo-fs')
3
-
1
+ const fs = require('hexo-fs');
4
2
  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
3
+ const log = hexo.log || console.log;
4
+ const config = hexo.config;
5
+ const theme = hexo.theme.config;
6
+ const env = require('../../package.json');
7
+ const siteConfig = {
8
+ version: env.version,
9
+ hostname: config.url,
10
+ root: config.root,
11
+ statics: theme.statics,
12
+ favicon: {
13
+ normal: theme.assets + '/favicon.ico',
14
+ hidden: theme.assets + '/failure.ico'
15
+ },
16
+ darkmode: theme.darkmode,
17
+ auto_dark: theme.auto_dark,
18
+ auto_scroll: theme.auto_scroll,
19
+ js: {
20
+ chart: theme.vendors.js.chart,
21
+ copy_tex: theme.vendors.js.copy_tex,
22
+ fancybox: theme.vendors.js.fancybox
23
+ },
24
+ css: {
25
+ valine: theme.css + '/comment.css',
26
+ katex: theme.vendors.css.katex,
27
+ mermaid: theme.css + '/mermaid.css',
28
+ fancybox: theme.vendors.css.fancybox
29
+ },
30
+ loader: theme.loader,
31
+ search: null,
32
+ valine: theme.valine,
33
+ outime: {
34
+ enable: theme.outime.enable,
35
+ days: theme.outime.days
36
+ },
37
+ quicklink: {
38
+ timeout: theme.quicklink.timeout,
39
+ priority: theme.quicklink.priority
40
+ },
41
+ playerAPI: theme.playerAPI,
42
+ disableVL: theme.disableVL,
43
+ audio: undefined,
44
+ fireworks: undefined
45
+ };
46
+ if (config?.algolia) {
47
+ siteConfig.search = {
48
+ appID: config.algolia.appId,
49
+ apiKey: config.algolia.apiKey,
50
+ indexName: config.algolia.indexName,
51
+ hits: theme.search.hits
52
+ };
55
53
  }
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()
54
+ if (theme?.audio) {
55
+ siteConfig.audio = theme.audio;
69
56
  }
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()
57
+ let text = '';
58
+ ['library', 'global', 'page', 'vue', 'components'].forEach(function (item) {
59
+ if (fs.existsSync(`themes/shokaX/source/js/_app/${item}.js`)) {
60
+ text += fs.readFileSync(`themes/shokaX/source/js/_app/${item}.js`).toString();
61
+ }
62
+ else {
63
+ text += fs.readFileSync(`node_modules/hexo-theme-shokax/source/js/_app/${item}.js`).toString();
64
+ }
65
+ });
66
+ if (!theme.experiments?.noPlayer) {
67
+ if (fs.existsSync('themes/shokaX/source/js/_app/player.js')) {
68
+ text += fs.readFileSync('themes/shokaX/source/js/_app/player.js').toString();
69
+ }
70
+ else {
71
+ text += fs.readFileSync('node_modules/hexo-theme-shokax/source/js/_app/player.js').toString();
72
+ }
76
73
  }
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()
74
+ if (theme.fireworks && theme.fireworks.enable) {
75
+ if (fs.existsSync('themes/shokaX/source/js/_app/fireworks.js')) {
76
+ text += fs.readFileSync('themes/shokaX/source/js/_app/fireworks.js').toString();
77
+ }
78
+ else {
79
+ text += fs.readFileSync('node_modules/hexo-theme-shokax/source/js/_app/fireworks.js').toString();
80
+ }
81
+ 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
82
  }
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
- })
83
+ text = 'const CONFIG = ' + JSON.stringify(siteConfig) + ';' + text;
84
+ const result = hexo.render.renderSync({ text, engine: 'js' });
85
+ return {
86
+ path: theme.js + '/app.js',
87
+ data: function () {
88
+ return result;
89
+ }
90
+ };
91
+ });