hexo-theme-shokax 0.3.10 → 0.3.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. package/_config.yml +26 -5
  2. package/package.json +8 -7
  3. package/scripts/filters/locals.js +6 -0
  4. package/scripts/filters/post.js +2 -0
  5. package/scripts/generaters/archive.js +13 -1
  6. package/scripts/generaters/config.js +4 -1
  7. package/scripts/generaters/images.js +2 -0
  8. package/scripts/generaters/index.js +2 -0
  9. package/scripts/generaters/pages.js +0 -2
  10. package/scripts/generaters/script.js +34 -9
  11. package/scripts/helpers/asset.js +16 -7
  12. package/scripts/helpers/engine.js +24 -1
  13. package/scripts/helpers/list_categories.js +4 -0
  14. package/scripts/helpers/summary_ai.js +4 -0
  15. package/scripts/helpers/symbols_count_time.js +14 -8
  16. package/scripts/plugin/check.js +5 -3
  17. package/scripts/plugin/index.js +36 -9
  18. package/scripts/plugin/lib/injects.js +15 -0
  19. package/scripts/tags/media.js +1 -0
  20. package/source/js/_app/components/sidebar.js +54 -56
  21. package/source/js/_app/fireworks.js +6 -137
  22. package/source/js/_app/globals/globalVars.js +80 -96
  23. package/source/js/_app/globals/handles.js +81 -60
  24. package/source/js/_app/globals/themeColor.js +30 -26
  25. package/source/js/_app/globals/thirdparty.js +25 -24
  26. package/source/js/_app/globals/tools.js +36 -30
  27. package/source/js/_app/library/anime.js +30 -15
  28. package/source/js/_app/library/dom.js +12 -5
  29. package/source/js/_app/library/loadFile.js +7 -9
  30. package/source/js/_app/library/proto.js +59 -7
  31. package/source/js/_app/library/scriptPjax.js +14 -9
  32. package/source/js/_app/library/storage.js +2 -4
  33. package/source/js/_app/library/vue.js +16 -19
  34. package/source/js/_app/page/comment.js +10 -11
  35. package/source/js/_app/page/common.js +8 -12
  36. package/source/js/_app/page/fancybox.js +13 -14
  37. package/source/js/_app/page/post.js +43 -45
  38. package/source/js/_app/page/search.js +20 -20
  39. package/source/js/_app/page/tab.js +7 -10
  40. package/source/js/_app/pjax/domInit.js +29 -29
  41. package/source/js/_app/pjax/refresh.js +45 -50
  42. package/source/js/_app/pjax/siteInit.js +27 -31
  43. package/source/js/_app/player.js +44 -27
  44. package/test/dom.test.js +0 -86
@@ -1,23 +1,18 @@
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 domInit_1 = __importDefault(require("./domInit"));
7
- const refresh_1 = require("./refresh");
8
- const scriptPjax_1 = require("../library/scriptPjax");
9
- const search_1 = require("../page/search");
10
- const globalVars_1 = require("../globals/globalVars");
11
- const themeColor_1 = require("../globals/themeColor");
12
- const handles_1 = require("../globals/handles");
13
- const tools_1 = require("../globals/tools");
14
- const fireworks_1 = require("../fireworks");
15
- const theme_shokax_pjax_1 = __importDefault(require("theme-shokax-pjax"));
16
- const vue_1 = require("../library/vue");
1
+ import domInit from './domInit';
2
+ import { pjaxReload, siteRefresh } from './refresh';
3
+ import { cloudflareInit } from '../library/scriptPjax';
4
+ import { algoliaSearch } from '../page/search';
5
+ import { pjax, setPjax } from '../globals/globalVars';
6
+ import { autoDarkmode, themeColorListener } from '../globals/themeColor';
7
+ import { resizeHandle, scrollHandle, visibilityListener } from '../globals/handles';
8
+ import { pagePosition } from '../globals/tools';
9
+ import { initFireworks } from '../fireworks';
10
+ import Pjax from 'theme-shokax-pjax';
11
+ import { initVue } from '../library/vue';
17
12
  const siteInit = () => {
18
- (0, domInit_1.default)();
19
- (0, vue_1.initVue)();
20
- (0, globalVars_1.setPjax)(new theme_shokax_pjax_1.default({
13
+ domInit();
14
+ initVue();
15
+ setPjax(new Pjax({
21
16
  selectors: [
22
17
  'head title',
23
18
  '.languages',
@@ -30,23 +25,24 @@ const siteInit = () => {
30
25
  }));
31
26
  CONFIG.quicklink.ignores = LOCAL.ignores;
32
27
  quicklink.listen(CONFIG.quicklink);
33
- (0, themeColor_1.autoDarkmode)();
28
+ autoDarkmode();
34
29
  if (!CONFIG.disableVL) {
35
- (0, handles_1.visibilityListener)();
30
+ visibilityListener();
36
31
  }
37
- (0, themeColor_1.themeColorListener)();
38
- (0, search_1.algoliaSearch)(globalVars_1.pjax);
39
- (0, fireworks_1.initFireworks)();
40
- window.addEventListener('scroll', handles_1.scrollHandle);
41
- window.addEventListener('resize', handles_1.resizeHandle);
42
- window.addEventListener('pjax:send', refresh_1.pjaxReload);
43
- window.addEventListener('pjax:success', refresh_1.siteRefresh);
32
+ themeColorListener();
33
+ algoliaSearch(pjax);
34
+ initFireworks();
35
+ window.addEventListener('scroll', scrollHandle);
36
+ window.addEventListener('resize', resizeHandle);
37
+ window.addEventListener('pjax:send', pjaxReload);
38
+ window.addEventListener('pjax:success', siteRefresh); // 默认会传入一个event参数
44
39
  window.addEventListener('beforeunload', () => {
45
- (0, tools_1.pagePosition)();
40
+ pagePosition();
46
41
  });
47
- (0, refresh_1.siteRefresh)(1);
42
+ // clickMenu() TODO 暂时禁用
43
+ siteRefresh(1);
48
44
  };
49
- (0, scriptPjax_1.cloudflareInit)();
45
+ cloudflareInit();
50
46
  window.addEventListener('DOMContentLoaded', siteInit, {
51
47
  passive: true
52
48
  });
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mediaPlayer = void 0;
4
- const globalVars_1 = require("./globals/globalVars");
5
- const tools_1 = require("./globals/tools");
6
- const anime_1 = require("./library/anime");
7
- const dom_1 = require("./library/dom");
8
- const storage_1 = require("./library/storage");
9
- const tab_1 = require("./page/tab");
1
+ import { originTitle } from './globals/globalVars';
2
+ import { showtip } from './globals/tools';
3
+ import { pageScroll } from './library/anime';
4
+ import { $dom } from './library/dom';
5
+ import { $storage } from './library/storage';
6
+ import { tabFormat } from './page/tab';
10
7
  let NOWPLAYING = null;
11
8
  const isMobile = /mobile/i.test(window.navigator.userAgent);
12
- const mediaPlayer = (t, config) => {
9
+ export const mediaPlayer = (t, config) => {
13
10
  if (CONFIG.noPlayer) {
14
11
  return;
15
12
  }
@@ -87,7 +84,7 @@ const mediaPlayer = (t, config) => {
87
84
  t.player.options.mode = 'loop';
88
85
  }
89
86
  controller.btns.mode.className = 'mode ' + t.player.options.mode + ' btn';
90
- storage_1.$storage.set('_PlayerMode', t.player.options.mode);
87
+ $storage.set('_PlayerMode', t.player.options.mode);
91
88
  },
92
89
  volume(e) {
93
90
  e.preventDefault();
@@ -246,7 +243,7 @@ const mediaPlayer = (t, config) => {
246
243
  return null;
247
244
  }
248
245
  const id = 'list-' + t.player._id + '-' + item.group;
249
- let tab = (0, dom_1.$dom)('#' + id);
246
+ let tab = $dom('#' + id);
250
247
  if (!tab) {
251
248
  tab = el.createChild('div', {
252
249
  id,
@@ -255,6 +252,7 @@ const mediaPlayer = (t, config) => {
255
252
  });
256
253
  if (t.player.group) {
257
254
  tab.attr('data-title', t.player.options.rawList[item.group].title)
255
+ // @ts-ignore
258
256
  .attr('data-id', t.player._id);
259
257
  }
260
258
  }
@@ -278,7 +276,7 @@ const mediaPlayer = (t, config) => {
278
276
  });
279
277
  return item;
280
278
  });
281
- (0, tab_1.tabFormat)();
279
+ tabFormat();
282
280
  },
283
281
  current() {
284
282
  return this.data[this.index];
@@ -293,7 +291,7 @@ const mediaPlayer = (t, config) => {
293
291
  li && li.addClass('active');
294
292
  tab = this.el.find('.tab')[item.group];
295
293
  tab && tab.addClass('active');
296
- (0, anime_1.pageScroll)(item.el, item.el.offsetTop);
294
+ pageScroll(item.el, item.el.offsetTop);
297
295
  return this;
298
296
  },
299
297
  title() {
@@ -301,7 +299,7 @@ const mediaPlayer = (t, config) => {
301
299
  return;
302
300
  }
303
301
  const current = this.current();
304
- document.title = 'Now Playing...' + current.name + ' - ' + current.artist + ' | ' + globalVars_1.originTitle;
302
+ document.title = 'Now Playing...' + current.name + ' - ' + current.artist + ' | ' + originTitle;
305
303
  },
306
304
  error() {
307
305
  const current = this.current();
@@ -394,8 +392,9 @@ const mediaPlayer = (t, config) => {
394
392
  const meta = utils.parse(raw);
395
393
  if (meta[0]) {
396
394
  const skey = JSON.stringify(meta);
397
- const playlist = storage_1.$storage.get(skey);
395
+ const playlist = $storage.get(skey);
398
396
  if (playlist) {
397
+ // list.push.apply(list, JSON.parse(playlist))
399
398
  list.push(...JSON.parse(playlist));
400
399
  resolve(list);
401
400
  }
@@ -404,10 +403,12 @@ const mediaPlayer = (t, config) => {
404
403
  .then((response) => {
405
404
  return response.json();
406
405
  }).then((json) => {
407
- storage_1.$storage.set(skey, JSON.stringify(json));
406
+ $storage.set(skey, JSON.stringify(json));
407
+ // list.push.apply(list, json)
408
408
  list.push(...json);
409
409
  resolve(list);
410
410
  }).catch((ex) => {
411
+ // (不)处理catch的异常
411
412
  });
412
413
  }
413
414
  }
@@ -437,16 +438,19 @@ const mediaPlayer = (t, config) => {
437
438
  t.player = {
438
439
  _id: utils.random(999999),
439
440
  group: true,
441
+ // 加载播放列表
440
442
  load(newList) {
441
443
  let d = '';
442
444
  if (newList && newList.length > 0) {
443
445
  if (this.options.rawList !== newList) {
444
446
  this.options.rawList = newList;
445
447
  playlist.clear();
448
+ // 获取新列表
446
449
  this.fetch();
447
450
  }
448
451
  }
449
452
  else {
453
+ // 没有列表时,隐藏按钮
450
454
  d = 'none';
451
455
  this.pause();
452
456
  }
@@ -495,6 +499,7 @@ const mediaPlayer = (t, config) => {
495
499
  }
496
500
  });
497
501
  },
502
+ // 根据模式切换当前曲目index
498
503
  mode() {
499
504
  const total = playlist.data.length;
500
505
  if (!total || playlist.errnum === total) {
@@ -535,6 +540,7 @@ const mediaPlayer = (t, config) => {
535
540
  }
536
541
  this.init();
537
542
  },
543
+ // 直接设置当前曲目index
538
544
  switch(index) {
539
545
  if (typeof index === 'number' &&
540
546
  index !== playlist.index &&
@@ -544,6 +550,7 @@ const mediaPlayer = (t, config) => {
544
550
  this.init();
545
551
  }
546
552
  },
553
+ // 更新source为当前曲目index
547
554
  init() {
548
555
  const item = playlist.current();
549
556
  if (!item || item.error) {
@@ -557,8 +564,8 @@ const mediaPlayer = (t, config) => {
557
564
  }
558
565
  source.attr('src', item.url);
559
566
  source.attr('title', item.name + ' - ' + item.artist);
560
- this.volume(storage_1.$storage.get('_PlayerVolume') || '0.7');
561
- this.muted(storage_1.$storage.get('_PlayerMuted'));
567
+ this.volume($storage.get('_PlayerVolume') || '0.7');
568
+ this.muted($storage.get('_PlayerMuted'));
562
569
  progress.create();
563
570
  if (this.options.type === 'audio') {
564
571
  preview.create();
@@ -576,16 +583,17 @@ const mediaPlayer = (t, config) => {
576
583
  source.play().then(() => {
577
584
  playlist.scroll();
578
585
  }).catch((e) => {
586
+ // 不处理错误
579
587
  });
580
588
  },
581
589
  pause() {
582
590
  source.pause();
583
- document.title = globalVars_1.originTitle;
591
+ document.title = originTitle;
584
592
  },
585
593
  stop() {
586
594
  source.pause();
587
595
  source.currentTime = 0;
588
- document.title = globalVars_1.originTitle;
596
+ document.title = originTitle;
589
597
  },
590
598
  seek(time) {
591
599
  time = Math.max(time, 0);
@@ -596,11 +604,11 @@ const mediaPlayer = (t, config) => {
596
604
  muted(status) {
597
605
  if (status === 'muted') {
598
606
  source.muted = status;
599
- storage_1.$storage.set('_PlayerMuted', status);
607
+ $storage.set('_PlayerMuted', status);
600
608
  controller.update(0);
601
609
  }
602
610
  else {
603
- storage_1.$storage.del('_PlayerMuted');
611
+ $storage.del('_PlayerMuted');
604
612
  source.muted = false;
605
613
  controller.update(source.volume);
606
614
  }
@@ -608,7 +616,7 @@ const mediaPlayer = (t, config) => {
608
616
  volume(percentage) {
609
617
  if (!isNaN(percentage)) {
610
618
  controller.update(percentage);
611
- storage_1.$storage.set('_PlayerVolume', percentage);
619
+ $storage.set('_PlayerVolume', percentage);
612
620
  source.volume = percentage;
613
621
  }
614
622
  },
@@ -622,6 +630,7 @@ const mediaPlayer = (t, config) => {
622
630
  index: 0,
623
631
  create(box) {
624
632
  const current = playlist.index;
633
+ // const that = this
625
634
  const raw = playlist.current().lrc;
626
635
  const callback = (body) => {
627
636
  if (current !== playlist.index) {
@@ -655,6 +664,7 @@ const mediaPlayer = (t, config) => {
655
664
  this.index = i;
656
665
  const y = -(this.index - 1);
657
666
  this.el.style.transform = 'translateY(' + y + 'rem)';
667
+ // this.el.style.webkitTransform = 'translateY(' + y + 'rem)';
658
668
  this.el.getElementsByClassName('current')[0].removeClass('current');
659
669
  this.el.getElementsByTagName('p')[i].addClass('current');
660
670
  }
@@ -670,12 +680,15 @@ const mediaPlayer = (t, config) => {
670
680
  let lrc = [];
671
681
  const lyricLen = lyric.length;
672
682
  for (let i = 0; i < lyricLen; i++) {
683
+ // match lrc time
673
684
  const lrcTimes = lyric[i].match(/\[(\d{2}):(\d{2})(\.(\d{2,3}))?]/g);
685
+ // match lrc text
674
686
  const lrcText = lyric[i]
675
687
  .replace(/.*\[(\d{2}):(\d{2})(\.(\d{2,3}))?]/g, '')
676
688
  .replace(/<(\d{2}):(\d{2})(\.(\d{2,3}))?>/g, '')
677
689
  .trim();
678
690
  if (lrcTimes) {
691
+ // handle multiple time tag
679
692
  const timeLen = lrcTimes.length;
680
693
  for (let j = 0; j < timeLen; j++) {
681
694
  const oneTime = /\[(\d{2}):(\d{2})(\.(\d{2,3}))?]/.exec(lrcTimes[j]);
@@ -687,6 +700,7 @@ const mediaPlayer = (t, config) => {
687
700
  }
688
701
  }
689
702
  }
703
+ // sort by time
690
704
  lrc = lrc.filter((item) => item[1]);
691
705
  lrc.sort((a, b) => a[0] - b[0]);
692
706
  return lrc;
@@ -702,6 +716,7 @@ const mediaPlayer = (t, config) => {
702
716
  }).then((body) => {
703
717
  callback(body);
704
718
  }).catch((ex) => {
719
+ // 不处理错误
705
720
  });
706
721
  }
707
722
  };
@@ -721,7 +736,7 @@ const mediaPlayer = (t, config) => {
721
736
  },
722
737
  onplay() {
723
738
  t.parentNode.addClass('playing');
724
- (0, tools_1.showtip)(this.attr('title'));
739
+ showtip(this.attr('title'));
725
740
  NOWPLAYING = t;
726
741
  },
727
742
  onpause() {
@@ -744,9 +759,12 @@ const mediaPlayer = (t, config) => {
744
759
  return;
745
760
  }
746
761
  t.player.options = Object.assign(option, config);
747
- t.player.options.mode = storage_1.$storage.get('_PlayerMode') || t.player.options.mode;
762
+ t.player.options.mode = $storage.get('_PlayerMode') || t.player.options.mode;
763
+ // 初始化button、controls以及click事件
748
764
  buttons.create();
765
+ // 初始化audio or video
749
766
  source = t.createChild(t.player.options.type, events);
767
+ // 初始化播放列表、预览、控件按钮等
750
768
  info.create();
751
769
  t.parentNode.addClass(t.player.options.type);
752
770
  t.player.created = true;
@@ -754,4 +772,3 @@ const mediaPlayer = (t, config) => {
754
772
  init(config);
755
773
  return t;
756
774
  };
757
- exports.mediaPlayer = mediaPlayer;
package/test/dom.test.js DELETED
@@ -1,86 +0,0 @@
1
- const { describe, beforeEach, afterEach, it } = require('mocha')
2
- const jsdom = require('jsdom')
3
- const { $dom } = require('../source/js/_app/library/dom')
4
- const { expect } = require('chai')
5
-
6
- describe('$dom', function () {
7
- // 在每个测试用例之前创建一个虚拟文档
8
- beforeEach(function () {
9
- const html = `
10
- <html lang="zh-cn">
11
- <head><title>Test Page</title></head>
12
- <body>
13
- <div id="container">
14
- <p class="text">Hello</p>
15
- <p class="text">World</p>
16
- </div>
17
- </body>
18
- </html>
19
- `
20
- const dom = new jsdom.JSDOM(html)
21
- global.document = dom.window.document
22
- global.HTMLElement = dom.window.HTMLElement
23
- })
24
-
25
- // 在每个测试用例之后清除虚拟文档
26
- afterEach(function () {
27
- global.document = null
28
- })
29
-
30
- it('should return the element with the given id selector', function () {
31
- const element = $dom('#container')
32
- expect(element).to.exist
33
- expect(element).to.be.instanceOf(HTMLElement)
34
- expect(element.id).to.equal('container')
35
- })
36
-
37
- it('should return the first element that matches the given selector', function () {
38
- const element = $dom('.text')
39
- expect(element).to.exist
40
- expect(element).to.be.instanceOf(HTMLElement)
41
- expect(element.textContent).to.equal('Hello')
42
- })
43
-
44
- it('should return null if no element matches the given selector', function () {
45
- const element = $dom('.foo')
46
- expect(element).to.be.null
47
- })
48
- })
49
-
50
- describe('$dom.all & $dom.each', function () {
51
- beforeEach(function () {
52
- const html = `
53
- <html lang="zh-cn">
54
- <head><title>Test Page</title></head>
55
- <body>
56
- <div id="container">
57
- <p class="text">Hello</p>
58
- <p class="text">World</p>
59
- </div>
60
- </body>
61
- </html>
62
- `
63
- const dom = new jsdom.JSDOM(html)
64
- global.document = dom.window.document
65
- global.HTMLElement = dom.window.HTMLElement
66
- })
67
-
68
- afterEach(function () {
69
- global.document = null
70
- })
71
-
72
- it('should return all elements with the given selector', () => {
73
- const elements = $dom.all('p')
74
- expect(elements).to.be.exist
75
- expect(elements).length(2)
76
- })
77
-
78
- it('should run callback with the given selector', () => {
79
- $dom.each('p', function (value){
80
- value.innerText = 'test'
81
- })
82
- const elements = $dom.all('p')
83
- expect(elements[0].innerText).equal('test')
84
- expect(elements[1].innerText).equal('test')
85
- })
86
- })