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,140 +1,111 @@
1
- 'use strict'
2
- /* global hexo */
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
  const prepareQuery = (categories, parent) => {
7
- const query = {}
8
-
9
- if (parent) {
10
- query.parent = parent
11
- } else {
12
- query.parent = { $exists: false }
13
- }
14
-
15
- return categories.find(query).sort('name', 1).filter(cat => cat.length)
16
- }
17
-
8
+ const query = {
9
+ parent: undefined
10
+ };
11
+ if (parent) {
12
+ query.parent = parent;
13
+ }
14
+ else {
15
+ query.parent = { $exists: false };
16
+ }
17
+ return categories.find(query).sort('name', 1).filter(cat => cat.length);
18
+ };
18
19
  hexo.extend.helper.register('_list_categories', function (depth = 0) {
19
- // let hexo = this
20
- const categories = this.site.categories
21
-
22
- if (!categories || !categories.length) return ''
23
-
24
- const hierarchicalList = (level, parent) => {
25
- let result = ''
26
-
27
- prepareQuery(categories, parent).forEach((cat, i) => {
28
- let child
29
-
30
- if (level + 1 < depth) {
31
- child = hierarchicalList(level + 1, cat._id)
32
- }
33
-
34
- const catname = `<a itemprop="url" href="${this.url_for(cat.path)}">${cat.name}</a><small>( ${cat.length} )</small>`
35
-
36
- switch (level) {
37
- case 0:
38
- result += `<div><h2 class="item header">${catname}</h2>`
39
- break
40
-
41
- case 1:
42
- result += `<h3 class="item section">${catname}</h3>`
43
- break
44
-
45
- case 2:
46
- result += `<div class="item normal"><div class="title">${catname}</div></div>`
47
- break
48
- }
49
-
50
- if (child) {
51
- result += `${child}`
52
- }
53
-
54
- if (level === 0) {
55
- result += '</div>'
56
- }
57
- })
58
-
59
- return result
60
- }
61
-
62
- return hierarchicalList(0)
63
- })
64
-
20
+ const categories = this.site.categories;
21
+ if (!categories || !categories.length)
22
+ return '';
23
+ const hierarchicalList = (level, parent) => {
24
+ let result = '';
25
+ prepareQuery(categories, parent).forEach((cat, i) => {
26
+ let child;
27
+ if (level + 1 < depth) {
28
+ child = hierarchicalList(level + 1, cat._id);
29
+ }
30
+ const catname = `<a itemprop="url" href="${this.url_for(cat.path)}">${cat.name}</a><small>( ${cat.length} )</small>`;
31
+ switch (level) {
32
+ case 0:
33
+ result += `<div><h2 class="item header">${catname}</h2>`;
34
+ break;
35
+ case 1:
36
+ result += `<h3 class="item section">${catname}</h3>`;
37
+ break;
38
+ case 2:
39
+ result += `<div class="item normal"><div class="title">${catname}</div></div>`;
40
+ break;
41
+ }
42
+ if (child) {
43
+ result += `${child}`;
44
+ }
45
+ if (level === 0) {
46
+ result += '</div>';
47
+ }
48
+ });
49
+ return result;
50
+ };
51
+ return hierarchicalList(0);
52
+ });
65
53
  hexo.extend.helper.register('_categories', function () {
66
- // let hexo = this
67
- const categories = this.site.categories
68
- if (!categories || !categories.length) return ''
69
-
70
- const pangu = this.theme.pangu
71
- ? require('pangu')
72
- : {
54
+ const categories = this.site.categories;
55
+ if (!categories || !categories.length)
56
+ return '';
57
+ const pangu = {
73
58
  spacing: data => {
74
- return data
59
+ return data;
75
60
  }
76
- }
77
-
78
- const result = {}
79
-
80
- categories.forEach((cat, i) => {
81
- const child = prepareQuery(categories, cat._id)
82
- const cover = 'source/_posts' + cat.path.replace(this.config.category_dir, '') + 'cover.jpg'
83
-
84
- if (fs.existsSync(cover)) {
85
- const className = cat.slug.split('/')
86
- className.pop()
87
- cat.class = className.join(' ')
88
- cat.name = pangu.spacing(cat.name)
89
-
90
- if (child.length !== 0) {
91
- cat.child = child
92
- }
93
-
94
- result[cat._id] = cat
95
- }
96
- })
97
-
98
- return result
99
- })
100
-
61
+ };
62
+ const result = {};
63
+ categories.forEach((cat, i) => {
64
+ const child = prepareQuery(categories, cat._id);
65
+ const cover = 'source/_posts' + cat.path.replace(this.config.category_dir, '') + 'cover.jpg';
66
+ if (hexo_fs_1.default.existsSync(cover)) {
67
+ const className = cat.slug.split('/');
68
+ className.pop();
69
+ cat.class = className.join(' ');
70
+ cat.name = pangu.spacing(cat.name);
71
+ if (child.length !== 0) {
72
+ cat.child = child;
73
+ }
74
+ result[cat._id] = cat;
75
+ }
76
+ });
77
+ return result;
78
+ });
101
79
  hexo.extend.helper.register('_category_prev', function (name) {
102
- // let hexo = this
103
- const categories = this.site.categories
104
- if (!categories || !categories.length) return ''
105
-
106
- let result = ''
107
-
108
- categories.find({ name }).forEach((current) => {
109
- if (current.parent) {
110
- categories.find({ _id: current.parent }).forEach((cat, i) => {
111
- result += `<a href="${this.url_for(cat.path)}">${cat.name}</a>`
112
- })
113
- }
114
- })
115
-
116
- return result
117
- })
118
-
80
+ const categories = this.site.categories;
81
+ if (!categories || !categories.length)
82
+ return '';
83
+ let result = '';
84
+ categories.find({ name }).forEach((current) => {
85
+ if (current.parent) {
86
+ categories.find({ _id: current.parent }).forEach((cat, i) => {
87
+ result += `<a href="${this.url_for(cat.path)}">${cat.name}</a>`;
88
+ });
89
+ }
90
+ });
91
+ return result;
92
+ });
119
93
  hexo.extend.helper.register('_category_posts', function (page) {
120
- // let hexo = this
121
- const categories = this.site.categories
122
- if (!categories || !categories.length || !page.categories || !page.categories.length) return ''
123
-
124
- let result = ''
125
- const cat = page.categories.toArray()
126
-
127
- categories.find({ _id: cat[cat.length - 1]._id }).forEach((category) => {
128
- if (category.posts) {
129
- category.posts.sort('date', 1).forEach((post) => {
130
- let current = ''
131
- if (post.path === page.path) {
132
- current = ' class="active"'
94
+ const categories = this.site.categories;
95
+ if (!categories || !categories.length || !page.categories || !page.categories.length)
96
+ return '';
97
+ let result = '';
98
+ const cat = page.categories.toArray();
99
+ categories.find({ _id: cat[cat.length - 1]._id }).forEach((category) => {
100
+ if (category.posts) {
101
+ category.posts.sort('date', 1).forEach((post) => {
102
+ let current = '';
103
+ if (post.path === page.path) {
104
+ current = ' class="active"';
105
+ }
106
+ result += `<li ${current}><a href="${this.url_for(post.path)}" rel="bookmark" title="${post.title}">${post.title}</a></li>`;
107
+ });
133
108
  }
134
- result += `<li ${current}><a href="${this.url_for(post.path)}" rel="bookmark" title="${post.title}">${post.title}</a></li>`
135
- })
136
- }
137
- })
138
-
139
- return result
140
- })
109
+ });
110
+ return result;
111
+ });
@@ -1,76 +1,63 @@
1
- 'use strict'
2
- /* global hexo */
3
- /*!
4
- hexo-symbols-count-time by theme-next
5
- under GNU Lesser General Public License v3.0
6
- https://github.com/theme-next/hexo-symbols-count-time/blob/master/LICENSE
7
- */
8
-
9
- const { stripHTML } = require('hexo-util')
10
-
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const hexo_util_1 = require("hexo-util");
11
4
  const config = hexo.config.symbols_count_time = Object.assign({
12
- symbols: true,
13
- time: true,
14
- total_symbols: true,
15
- total_time: true,
16
- exclude_codeblock: false,
17
- awl: 4,
18
- wpm: 275,
19
- suffix: 'mins.'
20
- }, hexo.config.symbols_count_time)
21
-
22
- function getSymbols (post) {
23
- return post?._content?.length ?? post?.content?.length ?? post.length
5
+ symbols: true,
6
+ time: true,
7
+ total_symbols: true,
8
+ total_time: true,
9
+ exclude_codeblock: false,
10
+ awl: 4,
11
+ wpm: 275,
12
+ suffix: 'mins.'
13
+ }, hexo.config.symbols_count_time);
14
+ function getSymbols(post) {
15
+ return post?._content?.length ?? post?.content?.length ?? post.length;
24
16
  }
25
-
26
- function getSymbolsTotal (site) {
27
- let symbolsResultCount = 0
28
- site.posts.forEach((post) => {
29
- symbolsResultCount += getSymbols(post)
30
- })
31
- return symbolsResultCount
17
+ function getSymbolsTotal(site) {
18
+ let symbolsResultCount = 0;
19
+ site.posts.forEach((post) => {
20
+ symbolsResultCount += getSymbols(post);
21
+ });
22
+ return symbolsResultCount;
32
23
  }
33
-
34
- function getFormatTime (minutes, suffix) {
35
- const fHours = Math.floor(minutes / 60)
36
- let fMinutes = Math.floor(minutes - (fHours * 60))
37
- if (fMinutes < 1) {
38
- fMinutes = 1 // 0 => 1
39
- }
40
- return fHours < 1
41
- ? fMinutes + ' ' + suffix // < 59 => 59 mins.
42
- : fHours + ':' + ('00' + fMinutes).slice(-2) // = 61 => 1:01
24
+ function getFormatTime(minutes, suffix) {
25
+ const fHours = Math.floor(minutes / 60);
26
+ let fMinutes = Math.floor(minutes - (fHours * 60));
27
+ if (fMinutes < 1) {
28
+ fMinutes = 1;
29
+ }
30
+ return fHours < 1
31
+ ? fMinutes + ' ' + suffix
32
+ : fHours + ':' + ('00' + fMinutes).slice(-2);
43
33
  }
44
-
45
34
  hexo.extend.helper.register('symbolsCount', function (post) {
46
- let symbolsResult = getSymbols(post)
47
- if (symbolsResult > 9999) {
48
- symbolsResult = Math.round(symbolsResult / 1000) + 'k' // > 9999 => 11k
49
- } else if (symbolsResult > 999) {
50
- symbolsResult = Math.round(symbolsResult / 100) / 10 + 'k' // > 999 => 1.1k
51
- } // < 999 => 111
52
- return symbolsResult
53
- })
54
-
35
+ let symbolsResult = getSymbols(post);
36
+ if (symbolsResult > 9999) {
37
+ symbolsResult = Math.round(symbolsResult / 1000) + 'k';
38
+ }
39
+ else if (symbolsResult > 999) {
40
+ symbolsResult = Math.round(symbolsResult / 100) / 10 + 'k';
41
+ }
42
+ return symbolsResult;
43
+ });
55
44
  hexo.extend.helper.register('symbolsTime', function (post, awl = config.awl, wpm = config.wpm, suffix = config.suffix) {
56
- const minutes = Math.round(getSymbols(post) / (awl * wpm))
57
- return getFormatTime(minutes, suffix)
58
- })
59
-
45
+ const minutes = Math.round(getSymbols(post) / (awl * wpm));
46
+ return getFormatTime(minutes, suffix);
47
+ });
60
48
  hexo.extend.helper.register('symbolsCountTotal', function (site) {
61
- const symbolsResultTotal = getSymbolsTotal(site)
62
- return symbolsResultTotal < 1000000
63
- ? Math.round(symbolsResultTotal / 1000) + 'k' // < 999k => 111k
64
- : Math.round(symbolsResultTotal / 100000) / 10 + 'm' // > 999k => 1.1m
65
- })
66
-
49
+ const symbolsResultTotal = getSymbolsTotal(site);
50
+ return symbolsResultTotal < 1000000
51
+ ? Math.round(symbolsResultTotal / 1000) + 'k'
52
+ : Math.round(symbolsResultTotal / 100000) / 10 + 'm';
53
+ });
67
54
  hexo.extend.helper.register('symbolsTimeTotal', function (site, awl = config.awl, wpm = config.wpm, suffix = config.suffix) {
68
- const minutes = Math.round(getSymbolsTotal(site) / (awl * wpm))
69
- return getFormatTime(minutes, suffix)
70
- })
71
-
55
+ const minutes = Math.round(getSymbolsTotal(site) / (awl * wpm));
56
+ return getFormatTime(minutes, suffix);
57
+ });
72
58
  hexo.extend.filter.register('after_post_render', (data) => {
73
- let { content } = data
74
- if (config.exclude_codeblock) content = content.replace(/<pre>.*?<\/pre>/g, '')
75
- data.length = stripHTML(content).replace(/\r?\n|\r/g, '').replace(/\s+/g, '').length
76
- }, 0)
59
+ let { content } = data;
60
+ if (config.exclude_codeblock)
61
+ content = content.replace(/<pre>.*?<\/pre>/g, '');
62
+ data.length = (0, hexo_util_1.stripHTML)(content).replace(/\r?\n|\r/g, '').replace(/\s+/g, '').length;
63
+ }, 0);
@@ -1,49 +1,50 @@
1
- /* global hexo */
2
-
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 injects_1 = __importDefault(require("./lib/injects"));
7
+ const node_https_1 = __importDefault(require("node:https"));
8
+ const package_json_1 = require("../../package.json");
3
9
  hexo.on('generateBefore', () => {
4
- // 加载`theme_injects`过滤器
5
- require('./lib/injects')(hexo)
6
- })
7
-
10
+ (0, injects_1.default)(hexo);
11
+ });
8
12
  hexo.on('generateAfter', () => {
9
- // 检查版本更新
10
- const https = require('https')
11
- const path = require('path')
12
- const { version } = require(path.normalize('../../package.json'))
13
- https.get('https://api.github.com/repos/zkz098/hexo-theme-shokaX/releases/latest', {
14
- headers: {
15
- 'User-Agent': 'Theme ShokaX Client'
16
- }
17
- }, (res) => {
18
- let result = ''
19
- res.on('data', (data) => {
20
- result += data
21
- })
22
- res.on('end', () => {
23
- try {
24
- const latest = JSON.parse(result).tag_name.replace('v', '').split('.')
25
- const current = version.split('.')
26
- let isOutdated = false
27
- for (let i = 0; i < Math.max(latest.length, current.length); i++) {
28
- if (!current[i] || latest[i] > current[i]) {
29
- isOutdated = true
30
- break
31
- }
32
- if (latest[i] < current[i]) {
33
- break
34
- }
13
+ node_https_1.default.get('https://api.github.com/repos/theme-shoka-x/hexo-theme-shokaX/releases/latest', {
14
+ headers: {
15
+ 'User-Agent': 'Theme ShokaX Client'
35
16
  }
36
- if (isOutdated) {
37
- hexo.log.warn(`Your theme ShokaX is outdated. Current version: v${current.join('.')}, latest version: v${latest.join('.')}`)
38
- hexo.log.warn('Visit https://github.com/zkz098/hexo-theme-shokaX/releases for more information.')
39
- }
40
- } catch (err) {
41
- hexo.log.error('Failed to detect version info. Error message:')
42
- hexo.log.error(err)
43
- }
44
- })
45
- }).on('error', err => {
46
- hexo.log.error('Failed to detect version info. Error message:')
47
- hexo.log.error(err)
48
- })
49
- })
17
+ }, (res) => {
18
+ let result = '';
19
+ res.on('data', (data) => {
20
+ result += data;
21
+ });
22
+ res.on('end', () => {
23
+ try {
24
+ const latest = JSON.parse(result).tag_name.replace('v', '').split('.');
25
+ const current = package_json_1.version.split('.');
26
+ let isOutdated = false;
27
+ for (let i = 0; i < Math.max(latest.length, current.length); i++) {
28
+ if (!current[i] || latest[i] > current[i]) {
29
+ isOutdated = true;
30
+ break;
31
+ }
32
+ if (latest[i] < current[i]) {
33
+ break;
34
+ }
35
+ }
36
+ if (isOutdated) {
37
+ hexo.log.warn(`Your theme ShokaX is outdated. Current version: v${current.join('.')}, latest version: v${latest.join('.')}`);
38
+ hexo.log.warn('Visit https://github.com/theme-shoka-x/hexo-theme-shokaX/releases for more information.');
39
+ }
40
+ }
41
+ catch (err) {
42
+ hexo.log.error('Failed to detect version info. Error message:');
43
+ hexo.log.error(err);
44
+ }
45
+ });
46
+ }).on('error', err => {
47
+ hexo.log.error('Failed to detect version info. Error message:');
48
+ hexo.log.error(err);
49
+ });
50
+ });
@@ -1,20 +1,20 @@
1
- 'use strict'
2
-
3
- module.exports = {
4
- views: [
5
- 'head',
6
- 'sidebar',
7
- 'rightNav',
8
- 'postMeta',
9
- 'postBodyEnd',
10
- 'footer',
11
- 'bodyEnd',
12
- 'comment',
13
- 'status'
14
- ],
15
- styles: [
16
- 'variable',
17
- 'mixin',
18
- 'style'
19
- ]
20
- }
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {
4
+ views: [
5
+ 'head',
6
+ 'sidebar',
7
+ 'rightNav',
8
+ 'postMeta',
9
+ 'postBodyEnd',
10
+ 'footer',
11
+ 'bodyEnd',
12
+ 'comment',
13
+ 'status'
14
+ ],
15
+ styles: [
16
+ 'variable',
17
+ 'mixin',
18
+ 'style'
19
+ ]
20
+ };