hexo-theme-shokax 0.3.13 → 0.4.0-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. package/_config.yml +11 -5
  2. package/layout/_mixin/comment.pug +4 -4
  3. package/package.json +4 -4
  4. package/scripts/filters/locals.d.ts +1 -0
  5. package/scripts/filters/locals.ts +59 -0
  6. package/scripts/filters/post.d.ts +0 -0
  7. package/scripts/filters/post.ts +6 -0
  8. package/scripts/generaters/archive.d.ts +1 -0
  9. package/scripts/generaters/archive.ts +144 -0
  10. package/scripts/generaters/config.d.ts +1 -0
  11. package/scripts/generaters/config.ts +52 -0
  12. package/scripts/generaters/images.d.ts +1 -0
  13. package/scripts/generaters/images.ts +26 -0
  14. package/scripts/generaters/index.d.ts +1 -0
  15. package/scripts/generaters/index.ts +110 -0
  16. package/scripts/generaters/pages.d.ts +0 -0
  17. package/scripts/generaters/pages.ts +16 -0
  18. package/scripts/generaters/script.d.ts +1 -0
  19. package/scripts/generaters/script.js +22 -6
  20. package/scripts/generaters/script.ts +110 -0
  21. package/scripts/helpers/asset.d.ts +1 -0
  22. package/scripts/helpers/asset.ts +158 -0
  23. package/scripts/helpers/engine.d.ts +1 -0
  24. package/scripts/helpers/engine.ts +171 -0
  25. package/scripts/helpers/list_categories.d.ts +1 -0
  26. package/scripts/helpers/list_categories.ts +104 -0
  27. package/scripts/helpers/summary_ai.d.ts +1 -0
  28. package/scripts/helpers/summary_ai.ts +100 -0
  29. package/scripts/helpers/symbols_count_time.d.ts +1 -0
  30. package/scripts/helpers/symbols_count_time.ts +76 -0
  31. package/scripts/plugin/check.d.ts +1 -0
  32. package/scripts/plugin/check.ts +35 -0
  33. package/scripts/plugin/index.d.ts +6 -0
  34. package/scripts/plugin/index.ts +52 -0
  35. package/scripts/plugin/lib/injects-point.d.ts +5 -0
  36. package/scripts/plugin/lib/injects-point.ts +20 -0
  37. package/scripts/plugin/lib/injects.d.ts +2 -0
  38. package/scripts/plugin/lib/injects.ts +101 -0
  39. package/scripts/tags/links.d.ts +1 -0
  40. package/scripts/tags/links.ts +75 -0
  41. package/scripts/tags/media.d.ts +1 -0
  42. package/scripts/tags/media.ts +19 -0
  43. package/source/js/_app/components/sidebar.ts +237 -0
  44. package/source/js/_app/globals/globalVars.ts +98 -0
  45. package/source/js/_app/globals/handles.ts +122 -0
  46. package/source/js/_app/globals/themeColor.ts +64 -0
  47. package/source/js/_app/globals/thirdparty.ts +63 -0
  48. package/source/js/_app/globals/tools.ts +74 -0
  49. package/source/js/_app/library/anime.ts +109 -0
  50. package/source/js/_app/library/declare.d.ts +117 -0
  51. package/source/js/_app/library/dom.ts +26 -0
  52. package/source/js/_app/library/libtype.d.ts +4 -0
  53. package/source/js/_app/library/loadFile.ts +41 -0
  54. package/source/js/_app/library/proto.ts +143 -0
  55. package/source/js/_app/library/scriptPjax.ts +72 -0
  56. package/source/js/_app/library/storage.ts +12 -0
  57. package/source/js/_app/library/vue.ts +60 -0
  58. package/source/js/_app/page/common.ts +42 -0
  59. package/source/js/_app/page/fancybox.ts +70 -0
  60. package/source/js/_app/page/post.ts +265 -0
  61. package/source/js/_app/page/search.ts +129 -0
  62. package/source/js/_app/page/tab.ts +59 -0
  63. package/source/js/_app/pjax/domInit.ts +95 -0
  64. package/source/js/_app/pjax/refresh.ts +75 -0
  65. package/source/js/_app/pjax/siteInit.ts +67 -0
  66. package/source/js/_app/player.ts +798 -0
  67. package/source/js/_app/components/sidebar.js +0 -209
  68. package/source/js/_app/fireworks.js +0 -10
  69. package/source/js/_app/globals/globalVars.js +0 -80
  70. package/source/js/_app/globals/handles.js +0 -98
  71. package/source/js/_app/globals/themeColor.js +0 -62
  72. package/source/js/_app/globals/thirdparty.js +0 -62
  73. package/source/js/_app/globals/tools.js +0 -66
  74. package/source/js/_app/library/anime.js +0 -106
  75. package/source/js/_app/library/dom.js +0 -34
  76. package/source/js/_app/library/loadFile.js +0 -36
  77. package/source/js/_app/library/proto.js +0 -163
  78. package/source/js/_app/library/scriptPjax.js +0 -70
  79. package/source/js/_app/library/storage.js +0 -12
  80. package/source/js/_app/library/vue.js +0 -53
  81. package/source/js/_app/page/comment.js +0 -23
  82. package/source/js/_app/page/common.js +0 -41
  83. package/source/js/_app/page/fancybox.js +0 -65
  84. package/source/js/_app/page/post.js +0 -244
  85. package/source/js/_app/page/search.js +0 -118
  86. package/source/js/_app/page/tab.js +0 -53
  87. package/source/js/_app/pjax/domInit.js +0 -76
  88. package/source/js/_app/pjax/refresh.js +0 -52
  89. package/source/js/_app/pjax/siteInit.js +0 -51
  90. package/source/js/_app/player.js +0 -771
@@ -0,0 +1,41 @@
1
+ import { getScript } from './scriptPjax'
2
+
3
+ /**
4
+ * 用途是根据不同的资源名称和类型生成相应的资源 URL。
5
+ */
6
+ const assetUrl = (asset: string, type: string): string => {
7
+ const str = CONFIG[asset][type]
8
+ if (str.includes('http')) {
9
+ return str
10
+ }
11
+ if (str.includes('gh') || str.includes('combine')) {
12
+ return `https://cdn.jsdelivr.net/${str}`
13
+ }
14
+ if (str.includes('npm')) {
15
+ return `https://cdn.jsdelivr.net/${str}`
16
+ }
17
+ return `/${str}`
18
+ }
19
+
20
+ export const vendorJs = (type: string, callback?: Function, condition?: string) => {
21
+ if (LOCAL[type]) {
22
+ getScript(assetUrl('js', type), callback || function () {
23
+ window[type] = true
24
+ }, condition || window[type])
25
+ }
26
+ }
27
+
28
+ export const vendorCss = (type: string, condition?: string): void => {
29
+ if (window['css' + type]) {
30
+ return
31
+ }
32
+
33
+ if (LOCAL[type]) {
34
+ document.head.createChild('link', {
35
+ rel: 'stylesheet',
36
+ href: assetUrl('css', type)
37
+ })
38
+
39
+ window['css' + type] = true
40
+ }
41
+ }
@@ -0,0 +1,143 @@
1
+ import { $dom } from './dom'
2
+
3
+ export default function initProto () {
4
+ Object.assign(HTMLElement.prototype, {
5
+ /**
6
+ * 创建一个子节点并放置
7
+ */
8
+ createChild (tag: string, obj: ElementCreationOptions, positon?: string): HTMLElement {
9
+ const child = document.createElement(tag)
10
+ Object.assign(child, obj)
11
+ switch (positon) {
12
+ case 'after':
13
+ this.insertAfter(child)
14
+ break
15
+ case 'replace':
16
+ this.innerHTML = ''
17
+ this.appendChild(child)
18
+ break
19
+ default:
20
+ this.appendChild(child)
21
+ }
22
+ return child
23
+ },
24
+ /**
25
+ * 此方法使用`<div>`包装一个 DOM 元素
26
+ * @param obj 需要被包装的对象
27
+ */
28
+ wrapObject (obj: HTMLElement) {
29
+ const box = document.createElement('div')
30
+ Object.assign(box, obj)
31
+ this.parentNode.insertBefore(box, this)
32
+ this.parentNode.removeChild(this)
33
+ box.appendChild(this)
34
+ },
35
+ changeOrGetHeight (h?: number | string): number {
36
+ if (h) {
37
+ // TODO 0rem是期望的值吗?
38
+ this.style.height = typeof h === 'number' ? h + 'rem' : h
39
+ }
40
+ return this.getBoundingClientRect().height
41
+ },
42
+ /**
43
+ 此函数将元素的宽度设置为指定值,如果未提供值,则返回元素的宽度.<br />
44
+ 宽度可以作为数字提供(假定它以`rem`为单位).作为字符串提供则直接设置为元素宽度
45
+ */
46
+ changeOrGetWidth (w?: number | string): number {
47
+ if (w) {
48
+ // TODO 0rem是期望的值吗?
49
+ this.style.width = typeof w === 'number' ? w + 'rem' : w
50
+ }
51
+ return this.getBoundingClientRect().width
52
+ },
53
+ getTop (): number {
54
+ return this.getBoundingClientRect().top
55
+ },
56
+ left (): number {
57
+ return this.getBoundingClientRect().left
58
+ },
59
+ /**
60
+ * 将此节点插入父节点的下一个节点之前
61
+ */
62
+ insertAfter (element: HTMLElement): void {
63
+ const parent = this.parentNode
64
+ if (parent.lastChild === this) {
65
+ parent.appendChild(element)
66
+ } else {
67
+ parent.insertBefore(element, this.nextSibling)
68
+ }
69
+ },
70
+ /**
71
+ * 当d为空时返回此节点的CSSStyle display属性 <br />
72
+ * 反之,将d设置为此节点的CSSStyle display属性
73
+ */
74
+ display (d?: string): string | EventTarget {
75
+ if (d == null) {
76
+ return this.style.display
77
+ } else {
78
+ this.style.display = d
79
+ return this
80
+ }
81
+ },
82
+ /**
83
+ * 找到此节点第一个符合selector选择器的子节点
84
+ */
85
+ child (selector: string): HTMLElement {
86
+ return $dom(selector, this)
87
+ },
88
+ /**
89
+ * 找到此节点所有符合selector选择器的子节点
90
+ */
91
+ find (selector: string): NodeListOf<HTMLElement> {
92
+ return $dom.all(selector, this)
93
+ },
94
+ /**
95
+ * 这个方法接受三个参数:
96
+ * type 表示操作类型('add'、'remove'、'toggle'),
97
+ * className 是一个或多个要操作的类名,
98
+ * display 是一个可选的布尔值,用于在执行切换操作时指定类名是否应显示或隐藏。
99
+ * 该方法会根据操作类型执行相应的类名操作。
100
+ */
101
+ _class (type: string, className: string, display?: boolean): void {
102
+ const classNames = className.indexOf(' ') ? className.split(' ') : [className]
103
+ classNames.forEach((name) => {
104
+ if (type === 'toggle') {
105
+ this.classList.toggle(name, display)
106
+ } else {
107
+ this.classList[type](name)
108
+ }
109
+ })
110
+ },
111
+ /**
112
+ * 这个方法是对 _class 方法的封装,调用时会将操作类型设为 'add',然后执行添加类名的操作。
113
+ * 最后,它返回当前的 EventTarget,通常是 DOM 元素本身,以支持链式调用。
114
+ */
115
+ addClass (className: string): EventTarget {
116
+ this._class('add', className)
117
+ return this
118
+ },
119
+ /**
120
+ * 这个方法是对 _class 方法的封装,调用时会将操作类型设为 'remove',然后执行移除类名的操作。
121
+ * 最后,它返回当前的 EventTarget,通常是 DOM 元素本身,以支持链式调用。
122
+ */
123
+ removeClass (className: string): EventTarget {
124
+ this._class('remove', className)
125
+ return this
126
+ },
127
+ /**
128
+ * 这个方法是对 _class 方法的封装,调用时会将操作类型设为 'toggle',然后执行切换类名的操作。
129
+ * 如果提供了 display 参数,它将根据布尔值决定是否显示或隐藏类名。
130
+ * 最后,它返回当前的 EventTarget,通常是 DOM 元素本身,以支持链式调用。
131
+ */
132
+ toggleClass (className: string, display?: boolean): EventTarget {
133
+ this._class('toggle', className, display)
134
+ return this
135
+ },
136
+ /**
137
+ * 这个方法返回一个布尔值,表示元素是否包含指定的类名。
138
+ */
139
+ hasClass (className: string): boolean {
140
+ return this.classList.contains(className)
141
+ }
142
+ })
143
+ }
@@ -0,0 +1,72 @@
1
+ // rocket-loader & Auto minify(cloudflare) 补丁
2
+ // cloudflare 的上述功能会导致DOMContentLoaded事件无法触发,此补丁会将DOMContentLoaded重定向为load事件
3
+ export function cloudflareInit () {
4
+ let inCloudFlare = true
5
+ window.addEventListener('DOMContentLoaded', function () {
6
+ inCloudFlare = false
7
+ })
8
+
9
+ if (document.readyState === 'loading') {
10
+ window.addEventListener('load', function () {
11
+ if (inCloudFlare) {
12
+ window.dispatchEvent(new Event('DOMContentLoaded'))
13
+ console.log('%c ☁️cloudflare patch ' + '%c running(rocket & minify)', 'color: white; background: #ff8c00; padding: 5px 3px;', 'padding: 4px;border:1px solid #ff8c00')
14
+ }
15
+ })
16
+ }
17
+ }
18
+
19
+ export const getScript = (url: string, callback?: Function, condition?: string): void => {
20
+ // url: 脚本文件的URL地址
21
+ // callback: 当脚本加载完成时要执行的回调函数
22
+ // condition: 可选的条件参数,如果存在,则执行callback
23
+ if (condition) {
24
+ // 如果条件存在,则执行回调函数
25
+ callback()
26
+ } else {
27
+ let script = document.createElement('script')
28
+
29
+ // @ts-ignore
30
+ script.onload = function (_, isAbort: boolean) {
31
+ // _: 事件对象
32
+ // isAbort: 是否中止
33
+ // @ts-ignore
34
+ if (isAbort || !script.readyState) {
35
+ console.log('abort!')
36
+ script.onload = null
37
+ script = undefined
38
+ if (!isAbort && callback) setTimeout(callback, 0)
39
+ }
40
+ }
41
+ script.src = url
42
+ document.head.appendChild(script)
43
+ }
44
+ }
45
+
46
+ export const pjaxScript = (element: HTMLScriptElement) => {
47
+ const { text, parentNode, id, className, type, src, dataset } = element
48
+ const code = text || element.textContent || element.innerHTML || ''
49
+ parentNode.removeChild(element)
50
+ const script = document.createElement('script')
51
+ if (id) {
52
+ script.id = id
53
+ }
54
+ if (className) {
55
+ script.className = className
56
+ }
57
+ if (type) {
58
+ script.type = type
59
+ }
60
+ if (src) {
61
+ // Force synchronous loading of peripheral JS.
62
+ script.src = src
63
+ script.async = false
64
+ }
65
+ if (dataset.pjax !== undefined) {
66
+ script.dataset.pjax = ''
67
+ }
68
+ if (code !== '') {
69
+ script.appendChild(document.createTextNode(code))
70
+ }
71
+ parentNode.appendChild(script)
72
+ }
@@ -0,0 +1,12 @@
1
+ // Html5LocalStorage的一个API
2
+ export const $storage = {
3
+ set (key: string, value: string): void {
4
+ localStorage.setItem(key, value)
5
+ },
6
+ get (key: string): string {
7
+ return localStorage.getItem(key)
8
+ },
9
+ del (key: string): void {
10
+ localStorage.removeItem(key)
11
+ }
12
+ }
@@ -0,0 +1,60 @@
1
+ import { $storage } from './storage'
2
+ import { transition } from './anime'
3
+ import { $dom } from './dom'
4
+ import { BODY } from '../globals/globalVars'
5
+ import { changeTheme } from '../globals/themeColor'
6
+
7
+ export function initVue () {
8
+ Vue.createApp(
9
+ {
10
+ data () {
11
+ return {
12
+
13
+ }
14
+ },
15
+ methods: {
16
+ changeThemeByBtn () {
17
+ let c: { (): void; (): void; (): void }
18
+ const btn = $dom('.theme').child('.ic')
19
+
20
+ const neko = BODY.createChild('div', {
21
+ id: 'neko',
22
+ innerHTML: '<div class="planet"><div class="sun"></div><div class="moon"></div></div><div class="body"><div class="face"><section class="eyes left"><span class="pupil"></span></section><section class="eyes right"><span class="pupil"></span></section><span class="nose"></span></div></div>'
23
+ })
24
+
25
+ const hideNeko = () => {
26
+ transition(neko, {
27
+ // @ts-ignore
28
+ delay: 2500,
29
+ opacity: 0
30
+ }, () => {
31
+ BODY.removeChild(neko)
32
+ })
33
+ }
34
+
35
+ if (btn.hasClass('i-sun')) {
36
+ c = () => {
37
+ neko.addClass('dark')
38
+ changeTheme('dark')
39
+ $storage.set('theme', 'dark')
40
+ hideNeko()
41
+ }
42
+ } else {
43
+ neko.addClass('dark')
44
+ c = () => {
45
+ neko.removeClass('dark')
46
+ changeTheme()
47
+ $storage.set('theme', 'light')
48
+ hideNeko()
49
+ }
50
+ }
51
+ transition(neko, 1, () => {
52
+ setTimeout(c, 210)
53
+ }, () => {
54
+ neko.display('block')
55
+ })
56
+ }
57
+ }
58
+ }
59
+ ).mount('#rightNav')
60
+ }
@@ -0,0 +1,42 @@
1
+ import { $dom } from '../library/dom'
2
+
3
+ export const cardActive = () => {
4
+ if (!$dom('.index.wrap')) { return }
5
+ const io = new IntersectionObserver((entries) => {
6
+ entries.forEach((article) => {
7
+ if (article.target.hasClass('show')) {
8
+ io.unobserve(article.target)
9
+ } else {
10
+ if (article.isIntersecting || article.intersectionRatio > 0) {
11
+ article.target.addClass('show')
12
+ io.unobserve(article.target)
13
+ }
14
+ }
15
+ })
16
+ }, {
17
+ root: null,
18
+ threshold: [0.3]
19
+ })
20
+
21
+ $dom.each('.index.wrap article.item, .index.wrap section.item', (article) => {
22
+ io.observe(article)
23
+ })
24
+
25
+ $dom('.index.wrap .item:first-child').addClass('show')
26
+
27
+ $dom.each('.cards .item', (element) => {
28
+ ['mouseenter', 'touchstart'].forEach((item) => {
29
+ element.addEventListener(item, () => {
30
+ if ($dom('.cards .item.active')) {
31
+ $dom('.cards .item.active').removeClass('active')
32
+ }
33
+ element.addClass('active')
34
+ }, { passive: true })
35
+ });
36
+ ['mouseleave'].forEach((item) => {
37
+ element.addEventListener(item, () => {
38
+ element.removeClass('active')
39
+ }, { passive: true })
40
+ })
41
+ })
42
+ }
@@ -0,0 +1,70 @@
1
+ import { $dom } from '../library/dom'
2
+ import { vendorCss, vendorJs } from '../library/loadFile'
3
+
4
+ export const postFancybox = (p:string) => {
5
+ if ($dom(p + ' .md img')) {
6
+ vendorCss('fancybox')
7
+ vendorCss('justifiedGallery')
8
+ vendorJs('fancybox', () => {
9
+ const q = jQuery.noConflict()
10
+
11
+ $dom.each(p + ' p.gallery', (element) => {
12
+ const box = document.createElement('div')
13
+ box.className = 'gallery'
14
+ box.setAttribute('data-height', String(element.getAttribute('data-height') || 220))
15
+
16
+ box.innerHTML = element.innerHTML.replace(/<br>/g, '')
17
+
18
+ element.parentNode.insertBefore(box, element)
19
+ element.remove()
20
+ })
21
+
22
+ $dom.each(p + ' .md img:not(.emoji):not(.vemoji)', (element) => {
23
+ const $image = q(element)
24
+ const imageLink = $image.attr('data-src') || $image.attr('src') // 替换
25
+ const $imageWrapLink = $image.wrap('<a class="fancybox" href="' + imageLink + '" itemscope itemtype="https://schema.org/ImageObject" itemprop="url"></a>').parent('a')
26
+ let info; let captionClass = 'image-info'
27
+ if (!$image.is('a img')) {
28
+ $image.data('safe-src', imageLink)
29
+ if (!$image.is('.gallery img')) {
30
+ $imageWrapLink.attr('data-fancybox', 'default').attr('rel', 'default')
31
+ } else {
32
+ captionClass = 'jg-caption'
33
+ }
34
+ }
35
+ if ((info = element.getAttribute('title'))) {
36
+ $imageWrapLink.attr('data-caption', info)
37
+ const para = document.createElement('span')
38
+ const txt = document.createTextNode(info)
39
+ para.appendChild(txt)
40
+ para.addClass(captionClass)
41
+ element.insertAfter(para)
42
+ }
43
+ })
44
+
45
+ $dom.each(p + ' div.gallery', (el, i) => {
46
+ // @ts-ignore
47
+ q(el).justifiedGallery({
48
+ rowHeight: q(el).data('height') || 120,
49
+ rel: 'gallery-' + i
50
+ }).on('jg.complete', function () {
51
+ q(this).find('a').each((k, ele) => {
52
+ ele.setAttribute('data-fancybox', 'gallery-' + i)
53
+ })
54
+ })
55
+ })
56
+
57
+ q.fancybox.defaults.hash = false
58
+ q(p + ' .fancybox').fancybox({
59
+ loop: true,
60
+ // @ts-ignore
61
+ helpers: {
62
+ overlay: {
63
+ locked: false
64
+ }
65
+ }
66
+ })
67
+ // @ts-ignore
68
+ }, window.jQuery)
69
+ }
70
+ }