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,85 +1,58 @@
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
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import yaml from 'js-yaml';
5
+ function linkGrid(args, content) {
6
+ const theme = hexo.theme.config;
7
+ if (!args[0] && !content) {
8
+ return;
31
9
  }
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
10
+ if (args[0]) {
11
+ const filepath = path.join(hexo.source_dir, args[0]);
12
+ if (fs.existsSync(filepath)) {
13
+ content = fs.readFileSync(filepath);
14
+ }
47
15
  }
48
-
49
- let urlparam = {}
50
-
51
- if (item.url) {
52
- urlparam = new URL(item.url, hexo.config.url)
16
+ if (!content) {
17
+ return;
53
18
  }
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>
19
+ const siteHost = new URL(hexo.config.url).hostname || hexo.config.url;
20
+ const list = yaml.load(content);
21
+ let result = '';
22
+ list.forEach((item) => {
23
+ if (!item.url || !item.site) {
24
+ return;
25
+ }
26
+ let urlparam = {
27
+ protocol: undefined,
28
+ hostname: undefined
29
+ };
30
+ if (item.url) {
31
+ urlparam = new URL(item.url, hexo.config.url);
32
+ }
33
+ let item_image = item.image || theme.assets + '/404.png';
34
+ if (!item_image.startsWith('//') && !item_image.startsWith('http')) {
35
+ item_image = theme.statics + item_image;
36
+ }
37
+ item.color = item.color ? ` style="--block-color:${item.color};"` : '';
38
+ result += `<div class="item" title="${item.owner || item.site}"${item.color}>`;
39
+ if (urlparam.protocol && urlparam.hostname !== siteHost) {
40
+ const durl = Buffer.from(item.url).toString('base64');
41
+ result += `<span class="exturl image" data-url="${durl}" data-background-image="${item_image}"></span>
68
42
  <div class="info">
69
43
  <span class="exturl title" data-url="${durl}">${item.site}</span>
70
44
  <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>
45
+ </div></div>`;
46
+ }
47
+ else {
48
+ result += `<a href="${item.url}" class="image" data-background-image="${item_image}"></a>
74
49
  <div class="info">
75
50
  <a href="${item.url}" class="title">${item.site}</a>
76
51
  <p class="desc">${item.desc || item.url}</p>
77
- </div></div>`
78
- }
79
- })
80
-
81
- return `<div class="links">${result}</div>`
52
+ </div></div>`;
53
+ }
54
+ });
55
+ return `<div class="links">${result}</div>`;
82
56
  }
83
-
84
- hexo.extend.tag.register('links', linkGrid, { ends: true })
85
- hexo.extend.tag.register('linksfile', linkGrid, { ends: false, async: true })
57
+ hexo.extend.tag.register('links', linkGrid, { ends: true });
58
+ hexo.extend.tag.register('linksfile', linkGrid, { ends: false, async: true });
@@ -1,19 +1,14 @@
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
+ import yaml from 'js-yaml';
3
+ function postMedia(args, content) {
4
+ if (!args[0] || !content) {
5
+ return;
6
+ }
7
+ const list = yaml.load(content);
8
+ switch (args[0]) {
9
+ case 'video':
10
+ case 'audio':
11
+ return `<div class="media-container"><div class="player" data-type="${args[0]}" data-src='${JSON.stringify(list)}'></div></div>`;
12
+ }
15
13
  }
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>`;
14
+ 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
  }
@@ -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();