hexo-theme-shokax 0.2.1 → 0.2.3

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.
@@ -1,89 +1,70 @@
1
- 'use strict'
2
-
3
- // 插件部分参考自theme-next
4
- const fs = require('fs')
5
- const path = require('path')
6
- const points = require('./injects-point')
7
- const defaultExtname = '.pug'
8
-
9
- // Defining stylus types
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 node_fs_1 = __importDefault(require("node:fs"));
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const injects_point_1 = __importDefault(require("./injects-point"));
9
+ const defaultExtname = '.pug';
10
10
  class StylusInject {
11
- constructor (base_dir) {
12
- this.base_dir = base_dir
13
- this.files = []
14
- }
15
-
16
- push (file) {
17
- // Get absolute path base on hexo dir
18
- this.files.push(path.resolve(this.base_dir, file))
19
- }
11
+ constructor(base_dir) {
12
+ this.base_dir = base_dir;
13
+ this.files = [];
14
+ }
15
+ push(file) {
16
+ this.files.push(node_path_1.default.resolve(this.base_dir, file));
17
+ }
20
18
  }
21
-
22
- // Defining view types
23
19
  class ViewInject {
24
- constructor (base_dir) {
25
- this.base_dir = base_dir
26
- this.raws = []
27
- }
28
-
29
- raw (name, raw, ...args) {
30
- // Set default extname
31
- if (path.extname(name) === '') {
32
- name += defaultExtname
20
+ constructor(base_dir) {
21
+ this.base_dir = base_dir;
22
+ this.raws = [];
33
23
  }
34
- this.raws.push({ name, raw, args })
35
- }
36
-
37
- file (name, file, ...args) {
38
- // Set default extname from file's extname
39
- if (path.extname(name) === '') {
40
- name += path.extname(file)
24
+ raw(name, raw, ...args) {
25
+ if (node_path_1.default.extname(name) === '') {
26
+ name += defaultExtname;
27
+ }
28
+ this.raws.push({ name, raw, args });
29
+ }
30
+ file(name, file, ...args) {
31
+ if (node_path_1.default.extname(name) === '') {
32
+ name += node_path_1.default.extname(file);
33
+ }
34
+ this.raw(name, node_fs_1.default.readFileSync(node_path_1.default.resolve(this.base_dir, file), 'utf8'), ...args);
41
35
  }
42
- // Get absolute path base on hexo dir
43
- this.raw(name, fs.readFileSync(path.resolve(this.base_dir, file), 'utf8'), ...args)
44
- }
45
- }
46
-
47
- // Init injects
48
- function initInject (base_dir) {
49
- const injects = {}
50
- points.styles.forEach(item => {
51
- injects[item] = new StylusInject(base_dir)
52
- })
53
- points.views.forEach(item => {
54
- injects[item] = new ViewInject(base_dir)
55
- })
56
- return injects
57
36
  }
58
-
59
- module.exports = (hexo) => {
60
- // Exec theme_inject filter
61
- const injects = initInject(hexo.base_dir)
62
- hexo.execFilterSync('theme_inject', injects)
63
- hexo.theme.config.injects = {}
64
-
65
- // Inject stylus
66
- points.styles.forEach(type => {
67
- hexo.theme.config.injects[type] = injects[type].files
68
- })
69
-
70
- // Inject views
71
- points.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)
88
- })
37
+ function initInject(base_dir) {
38
+ const injects = {};
39
+ injects_point_1.default.styles.forEach(item => {
40
+ injects[item] = new StylusInject(base_dir);
41
+ });
42
+ injects_point_1.default.views.forEach(item => {
43
+ injects[item] = new ViewInject(base_dir);
44
+ });
45
+ return injects;
89
46
  }
47
+ exports.default = (hexo) => {
48
+ const injects = initInject(hexo.base_dir);
49
+ hexo.execFilterSync('theme_inject', injects);
50
+ hexo.theme.config.injects = {};
51
+ injects_point_1.default.styles.forEach(type => {
52
+ hexo.theme.config.injects[type] = injects[type].files;
53
+ });
54
+ injects_point_1.default.views.forEach(type => {
55
+ const configs = Object.create(null);
56
+ hexo.theme.config.injects[type] = [];
57
+ injects[type].raws.forEach((injectObj, index) => {
58
+ const name = `inject/${type}/${injectObj.name}`;
59
+ hexo.theme.setView(name, injectObj.raw);
60
+ configs[name] = {
61
+ layout: name,
62
+ locals: injectObj.args[0],
63
+ options: injectObj.args[1],
64
+ order: injectObj.args[2] || index
65
+ };
66
+ });
67
+ hexo.theme.config.injects[type] = Object.values(configs)
68
+ .sort((x, y) => x.order - y.order);
69
+ });
70
+ };
@@ -1,85 +1,62 @@
1
- /* global hexo */
2
- 'use strict'
3
- /*
4
- {% links %}
5
- - site: #main title
6
- owner: #alternate title for image tooltip (nullable)
7
- url: #link of site
8
- desc: #description (nullable)
9
- image: #icon image (nullable)
10
- color: #block color (nullable)
11
- {% endlinks %}
12
-
13
- {% linksfile [path] %}
14
- */
15
-
16
- const fs = require('fs')
17
- const path = require('path')
18
- const yaml = require('js-yaml')
19
-
20
- function linkGrid (args, content) {
21
- const theme = hexo.theme.config
22
-
23
- if (!args[0] && !content) {
24
- return
25
- }
26
-
27
- if (args[0]) {
28
- const filepath = path.join(hexo.source_dir, args[0])
29
- if (fs.existsSync(filepath)) {
30
- content = fs.readFileSync(filepath)
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 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"));
9
+ function linkGrid(args, content) {
10
+ const theme = hexo.theme.config;
11
+ if (!args[0] && !content) {
12
+ return;
31
13
  }
32
- }
33
-
34
- if (!content) {
35
- return
36
- }
37
-
38
- const siteHost = new URL(hexo.config.url).hostname || hexo.config.url
39
-
40
- const list = yaml.load(content)
41
-
42
- let result = ''
43
-
44
- list.forEach((item) => {
45
- if (!item.url || !item.site) {
46
- return
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);
18
+ }
47
19
  }
48
-
49
- let urlparam = {}
50
-
51
- if (item.url) {
52
- urlparam = new URL(item.url, hexo.config.url)
20
+ if (!content) {
21
+ return;
53
22
  }
54
-
55
- let item_image = item.image || theme.assets + '/404.png'
56
-
57
- if (!item_image.startsWith('//') && !item_image.startsWith('http')) {
58
- item_image = theme.statics + item_image
59
- }
60
-
61
- item.color = item.color ? ` style="--block-color:${item.color};"` : ''
62
-
63
- result += `<div class="item" title="${item.owner || item.site}"${item.color}>`
64
-
65
- if (urlparam.protocol && urlparam.hostname !== siteHost) {
66
- const durl = Buffer.from(item.url).toString('base64')
67
- result += `<span class="exturl image" data-url="${durl}" data-background-image="${item_image}"></span>
23
+ const siteHost = new URL(hexo.config.url).hostname || hexo.config.url;
24
+ const list = js_yaml_1.default.load(content);
25
+ let result = '';
26
+ list.forEach((item) => {
27
+ if (!item.url || !item.site) {
28
+ return;
29
+ }
30
+ let urlparam = {
31
+ protocol: undefined,
32
+ hostname: undefined
33
+ };
34
+ if (item.url) {
35
+ urlparam = new URL(item.url, hexo.config.url);
36
+ }
37
+ let item_image = item.image || theme.assets + '/404.png';
38
+ if (!item_image.startsWith('//') && !item_image.startsWith('http')) {
39
+ item_image = theme.statics + item_image;
40
+ }
41
+ item.color = item.color ? ` style="--block-color:${item.color};"` : '';
42
+ result += `<div class="item" title="${item.owner || item.site}"${item.color}>`;
43
+ if (urlparam.protocol && urlparam.hostname !== siteHost) {
44
+ const durl = Buffer.from(item.url).toString('base64');
45
+ result += `<span class="exturl image" data-url="${durl}" data-background-image="${item_image}"></span>
68
46
  <div class="info">
69
47
  <span class="exturl title" data-url="${durl}">${item.site}</span>
70
48
  <p class="desc">${item.desc || item.url}</p>
71
- </div></div>`
72
- } else {
73
- result += `<a href="${item.url}" class="image" data-background-image="${item_image}"></a>
49
+ </div></div>`;
50
+ }
51
+ else {
52
+ result += `<a href="${item.url}" class="image" data-background-image="${item_image}"></a>
74
53
  <div class="info">
75
54
  <a href="${item.url}" class="title">${item.site}</a>
76
55
  <p class="desc">${item.desc || item.url}</p>
77
- </div></div>`
78
- }
79
- })
80
-
81
- return `<div class="links">${result}</div>`
56
+ </div></div>`;
57
+ }
58
+ });
59
+ return `<div class="links">${result}</div>`;
82
60
  }
83
-
84
- hexo.extend.tag.register('links', linkGrid, { ends: true })
85
- hexo.extend.tag.register('linksfile', linkGrid, { ends: false, async: true })
61
+ hexo.extend.tag.register('links', linkGrid, { ends: true });
62
+ hexo.extend.tag.register('linksfile', linkGrid, { ends: false, async: true });
@@ -1,19 +1,18 @@
1
- 'use strict'
2
- /* global hexo */
3
- const yaml = require('js-yaml')
4
-
5
- function postMedia (args, content) {
6
- if (!args[0] || !content) {
7
- return
8
- }
9
- const list = yaml.load(content)
10
- switch (args[0]) {
11
- case 'video':
12
- case 'audio':
13
- return `<div class="media-container"><div class="player" data-type="${args[0]}" data-src='${JSON.stringify(list)}'></div></div>`
14
- }
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 js_yaml_1 = __importDefault(require("js-yaml"));
7
+ function postMedia(args, content) {
8
+ if (!args[0] || !content) {
9
+ return;
10
+ }
11
+ const list = js_yaml_1.default.load(content);
12
+ switch (args[0]) {
13
+ case 'video':
14
+ case 'audio':
15
+ return `<div class="media-container"><div class="player" data-type="${args[0]}" data-src='${JSON.stringify(list)}'></div></div>`;
16
+ }
15
17
  }
16
-
17
- hexo.extend.tag.register('media', postMedia, { ends: true })
18
-
19
- // return `<video src="${args}" preload="metadata" controls playsinline poster="">Sorry, your browser does not support the video tag.</video>`;
18
+ hexo.extend.tag.register('media', postMedia, { ends: true });
@@ -246,6 +246,10 @@ code,
246
246
  .ic {
247
247
  margin-top: 1rem;
248
248
  @extend .up-down;
249
+
250
+ &.stop-animation {
251
+ animation-play-state: paused;
252
+ }
249
253
  }
250
254
 
251
255
  &.open {
@@ -10,6 +10,10 @@
10
10
  background-color: #363636;
11
11
  content-visibility: auto;
12
12
  contain-intrinsic-size: 100vw 70vh;
13
+
14
+ li.stop-animation {
15
+ animation-play-state: paused;
16
+ }
13
17
 
14
18
  img {
15
19
  width: 100%;
@@ -18,6 +18,10 @@
18
18
  animation: wave 25s cubic-bezier(.55, .5, .45, .5) infinite;
19
19
  }
20
20
 
21
+ use.stop-animation {
22
+ animation-play-state: paused;
23
+ }
24
+
21
25
  .parallax>use:nth-child(1) {
22
26
  animation-delay: -2s;
23
27
  animation-duration: 7s;
@@ -4,6 +4,10 @@
4
4
  animation: rotate 6s linear infinite;
5
5
  }
6
6
 
7
+ .rotate.stop-animation {
8
+ animation-play-state: paused;
9
+ }
10
+
7
11
  .beat {
8
12
  animation: beat 1.33s ease-in-out infinite;
9
13
  }
@@ -1,3 +1,5 @@
1
+ $mobile-wdith = hexo-config('experiments.mobileWidth')
2
+
1
3
  the-transition(duration = .2s, function = ease-in-out, delay = 0s, property = all) {
2
4
  transition:property duration function delay;
3
5
  }
@@ -15,7 +17,7 @@ mobile-small() {
15
17
  }
16
18
 
17
19
  mobile() {
18
- @media (max-width: 820px) {
20
+ @media (max-width: $mobile-wdith) {
19
21
  {block};
20
22
  }
21
23
  }
@@ -27,13 +29,13 @@ tablet-mobile() {
27
29
  }
28
30
 
29
31
  tablet-desktop() {
30
- @media (min-width: 820px) {
32
+ @media (min-width: $mobile-wdith) {
31
33
  {block};
32
34
  }
33
35
  }
34
36
 
35
37
  tablet() {
36
- @media (min-width: 820px) and (max-width: 1043px) {
38
+ @media (min-width: $mobile-wdith) and (max-width: 1043px) {
37
39
  {block};
38
40
  }
39
41
  }
@@ -1,12 +1,14 @@
1
1
  @import "_variables";
2
2
 
3
- for $inject_variable in hexo-config('injects.variable')
4
- @import $inject_variable;
3
+ if hexo-config('injects.variable')
4
+ for $inject_variable in hexo-config('injects.variable')
5
+ @import $inject_variable
5
6
 
6
7
  @import "_mixins";
7
8
 
8
- for $inject_mixin in hexo-config('injects.mixin')
9
- @import $inject_mixin;
9
+ if hexo-config('injects.mixin')
10
+ for $inject_mixin in hexo-config('injects.mixin')
11
+ @import $inject_mixin;
10
12
 
11
13
  if $colors = hexo-config('style.colors')
12
14
  @import $colors;
@@ -30,8 +32,9 @@ else
30
32
  if $custom = hexo-config('style.custom')
31
33
  @import $custom;
32
34
 
33
- for $inject_style in hexo-config('injects.style')
34
- @import $inject_style;
35
+ if hexo-config('injects.style')
36
+ for $inject_style in hexo-config('injects.style')
37
+ @import $inject_style;
35
38
 
36
39
  if $optimize = hexo-config('experiments.optimizeLongPosts')
37
40
  @import "optimize.styl"
@@ -120,8 +120,18 @@ const render = anime({
120
120
  ctx.clearRect(0, 0, canvasEl.width, canvasEl.height);
121
121
  }
122
122
  });
123
+ const hasAncestor = function (node, name) {
124
+ name = name.toUpperCase();
125
+ do {
126
+ if (node === null || node === undefined)
127
+ break;
128
+ if (node.nodeName === name)
129
+ return true;
130
+ } while (node = node.parentNode);
131
+ return false;
132
+ };
123
133
  document.addEventListener(tap, function (e) {
124
- if (e.target.nodeName === 'A') {
134
+ if (hasAncestor(e.target, 'a')) {
125
135
  return;
126
136
  }
127
137
  render.play();
@@ -184,8 +184,12 @@ const scrollHandle = function (event) {
184
184
  else { }
185
185
  scrollAction.y = window.scrollY;
186
186
  const scrollPercent = Math.round(Math.min(100 * window.scrollY / contentVisibilityHeight, 100)) + '%';
187
- backToTop.child('span').innerText = scrollPercent;
188
- $dom('.percent').changeOrGetWidth(scrollPercent);
187
+ if (backToTop.child('span').innerText !== scrollPercent) {
188
+ backToTop.child('span').innerText = scrollPercent;
189
+ }
190
+ if ($dom('#sidebar').hasClass('affix') || $dom('#sidebar').hasClass('on')) {
191
+ $dom('.percent').changeOrGetWidth(scrollPercent);
192
+ }
189
193
  };
190
194
  const pagePosition = function () {
191
195
  if (CONFIG.auto_scroll) {
@@ -332,6 +332,31 @@ const postBeauty = function () {
332
332
  btns: []
333
333
  }).player.load(JSON.parse(element.attr('data-src'))).fetch();
334
334
  });
335
+ const angleDown = document.querySelectorAll('.show-btn .i-angle-down');
336
+ if (angleDown.length) {
337
+ if (!window.IntersectionObserver)
338
+ return;
339
+ const io = new IntersectionObserver((entries) => {
340
+ entries.forEach(entry => {
341
+ if (entry.isIntersecting) {
342
+ angleDown.forEach(i => {
343
+ i.classList.remove('stop-animation');
344
+ });
345
+ }
346
+ else {
347
+ angleDown.forEach(i => {
348
+ i.classList.add('stop-animation');
349
+ });
350
+ }
351
+ });
352
+ }, {
353
+ root: null,
354
+ threshold: 0.5
355
+ });
356
+ angleDown.forEach(i => {
357
+ io.observe(i);
358
+ });
359
+ }
335
360
  };
336
361
  const tabFormat = function () {
337
362
  let first_tab;
@@ -546,6 +571,47 @@ const domInit = function () {
546
571
  toolPlayer.player.mini();
547
572
  });
548
573
  }
574
+ const createIntersectionObserver = function () {
575
+ if (!window.IntersectionObserver)
576
+ return;
577
+ new IntersectionObserver(([entry]) => {
578
+ if (entry.isIntersecting) {
579
+ document.querySelectorAll('.parallax>use').forEach(i => {
580
+ i.classList.remove('stop-animation');
581
+ });
582
+ document.querySelectorAll('#imgs .item').forEach(i => {
583
+ i.classList.remove('stop-animation');
584
+ });
585
+ }
586
+ else {
587
+ document.querySelectorAll('.parallax>use').forEach(i => {
588
+ i.classList.add('stop-animation');
589
+ });
590
+ document.querySelectorAll('#imgs .item').forEach(i => {
591
+ i.classList.add('stop-animation');
592
+ });
593
+ }
594
+ }, {
595
+ root: null,
596
+ threshold: 0.2
597
+ }).observe(document.getElementById('waves'));
598
+ new IntersectionObserver(([entry]) => {
599
+ if (entry.isIntersecting) {
600
+ document.querySelectorAll('.with-love>i').forEach(i => {
601
+ i.classList.remove('stop-animation');
602
+ });
603
+ }
604
+ else {
605
+ document.querySelectorAll('.with-love>i').forEach(i => {
606
+ i.classList.add('stop-animation');
607
+ });
608
+ }
609
+ }, {
610
+ root: null,
611
+ threshold: 0.2
612
+ }).observe(document.querySelector('.with-love'));
613
+ };
614
+ createIntersectionObserver();
549
615
  };
550
616
  const pjaxReload = function () {
551
617
  pagePosition();