hexo-theme-shokax 0.5.2 → 0.5.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.
Files changed (161) hide show
  1. package/.vscode/settings.json +6 -0
  2. package/CODE_OF_CONDUCT.md +128 -128
  3. package/LICENSE +660 -660
  4. package/LICENSE-shoka +21 -21
  5. package/README.md +74 -74
  6. package/UsageRestrictions.md +25 -25
  7. package/_config.yml +359 -352
  8. package/languages/README.md +19 -19
  9. package/languages/default.yml +1 -1
  10. package/languages/en.yml +155 -155
  11. package/languages/ja.yml +155 -155
  12. package/languages/zh-CN.yml +155 -155
  13. package/languages/zh-HK.yml +155 -155
  14. package/languages/zh-TW.yml +155 -155
  15. package/layout/_alternate/atom.ejs +30 -30
  16. package/layout/_alternate/json.ejs +16 -16
  17. package/layout/_alternate/rss.ejs +34 -34
  18. package/layout/_mixin/breadcrumb.pug +33 -33
  19. package/layout/_mixin/card.pug +37 -37
  20. package/layout/_mixin/comment.pug +6 -6
  21. package/layout/_mixin/postmeta.pug +29 -29
  22. package/layout/_mixin/segment.pug +35 -35
  23. package/layout/_mixin/sidebar.pug +40 -40
  24. package/layout/_mixin/widgets.pug +28 -28
  25. package/layout/_partials/footer.pug +43 -43
  26. package/layout/_partials/head/head.pug +50 -50
  27. package/layout/_partials/head/head_com.pug +24 -24
  28. package/layout/_partials/head/pwa.pug +18 -18
  29. package/layout/_partials/header.pug +18 -18
  30. package/layout/_partials/layout.pug +138 -137
  31. package/layout/_partials/loading.pug +13 -13
  32. package/layout/_partials/pagination.pug +4 -4
  33. package/layout/_partials/post/copyright.pug +20 -20
  34. package/layout/_partials/post/footer.pug +20 -20
  35. package/layout/_partials/post/nav.pug +17 -17
  36. package/layout/_partials/post/post.pug +42 -42
  37. package/layout/_partials/post/reward.pug +18 -18
  38. package/layout/_partials/sidebar/menu.pug +37 -37
  39. package/layout/_partials/sidebar/overview.pug +42 -42
  40. package/layout/_partials/third-party/baidu-analytics.pug +11 -11
  41. package/layout/_partials/third-party/clarity.pug +8 -8
  42. package/layout/_partials/third-party/google-analytics.pug +9 -9
  43. package/layout/archive.pug +121 -121
  44. package/layout/category.pug +62 -62
  45. package/layout/index.pug +36 -36
  46. package/layout/page.pug +60 -60
  47. package/layout/post.pug +42 -42
  48. package/layout/tag.pug +46 -46
  49. package/package.json +6 -5
  50. package/scripts/generaters/script.js +2 -1
  51. package/scripts/plugin/check.js +2 -2
  52. package/source/assets/algolia_logo.svg +9 -9
  53. package/source/assets/logo.svg +16 -16
  54. package/source/css/_colors.styl +207 -207
  55. package/source/css/_common/components/components.styl +5 -5
  56. package/source/css/_common/components/pages/collapse.styl +119 -119
  57. package/source/css/_common/components/pages/home.styl +391 -391
  58. package/source/css/_common/components/pages/pages.styl +56 -56
  59. package/source/css/_common/components/pages/tag-cloud.styl +12 -12
  60. package/source/css/_common/components/post/breadcrumb.styl +39 -39
  61. package/source/css/_common/components/post/copyright.styl +41 -41
  62. package/source/css/_common/components/post/expand.styl +263 -263
  63. package/source/css/_common/components/post/footer.styl +11 -11
  64. package/source/css/_common/components/post/header.styl +79 -79
  65. package/source/css/_common/components/post/nav.styl +64 -64
  66. package/source/css/_common/components/post/post.styl +29 -29
  67. package/source/css/_common/components/post/reward.styl +50 -50
  68. package/source/css/_common/components/post/rtl.styl +12 -12
  69. package/source/css/_common/components/post/tags.styl +39 -39
  70. package/source/css/_common/components/tags/collapse.styl +72 -72
  71. package/source/css/_common/components/tags/container.styl +49 -49
  72. package/source/css/_common/components/tags/label.styl +12 -12
  73. package/source/css/_common/components/tags/links.styl +77 -77
  74. package/source/css/_common/components/tags/list.styl +131 -131
  75. package/source/css/_common/components/tags/note.styl +70 -70
  76. package/source/css/_common/components/tags/player.styl +361 -361
  77. package/source/css/_common/components/tags/quiz.styl +200 -200
  78. package/source/css/_common/components/tags/tabs.styl +89 -89
  79. package/source/css/_common/components/tags/tags.styl +9 -9
  80. package/source/css/_common/components/third-party/loading.styl +222 -222
  81. package/source/css/_common/components/third-party/mermaid/class.styl +90 -90
  82. package/source/css/_common/components/third-party/mermaid/flowchart.styl +72 -72
  83. package/source/css/_common/components/third-party/mermaid/gantt.styl +251 -251
  84. package/source/css/_common/components/third-party/mermaid/git.styl +7 -7
  85. package/source/css/_common/components/third-party/mermaid/mermaid.styl +37 -37
  86. package/source/css/_common/components/third-party/mermaid/pie.styl +9 -9
  87. package/source/css/_common/components/third-party/mermaid/sequence.styl +95 -95
  88. package/source/css/_common/components/third-party/mermaid/state.styl +130 -130
  89. package/source/css/_common/components/third-party/pace.styl +18 -18
  90. package/source/css/_common/components/third-party/search.styl +167 -167
  91. package/source/css/_common/components/third-party/theme.styl +151 -151
  92. package/source/css/_common/components/third-party/third-party.styl +22 -22
  93. package/source/css/_common/components/third-party/widgets.styl +57 -57
  94. package/source/css/_common/outline/footer/footer.styl +67 -67
  95. package/source/css/_common/outline/header/brand.styl +77 -77
  96. package/source/css/_common/outline/header/header.styl +20 -20
  97. package/source/css/_common/outline/header/image.styl +85 -85
  98. package/source/css/_common/outline/header/menu.styl +117 -117
  99. package/source/css/_common/outline/header/nav.styl +81 -81
  100. package/source/css/_common/outline/header/right.styl +15 -15
  101. package/source/css/_common/outline/header/tool.styl +207 -207
  102. package/source/css/_common/outline/header/waves.styl +57 -57
  103. package/source/css/_common/outline/mobile.styl +46 -46
  104. package/source/css/_common/outline/outline.styl +78 -78
  105. package/source/css/_common/outline/sidebar/author.styl +59 -59
  106. package/source/css/_common/outline/sidebar/dimmer.styl +23 -23
  107. package/source/css/_common/outline/sidebar/menu.styl +63 -63
  108. package/source/css/_common/outline/sidebar/quick.styl +43 -43
  109. package/source/css/_common/outline/sidebar/related.styl +56 -56
  110. package/source/css/_common/outline/sidebar/sidebar.styl +82 -82
  111. package/source/css/_common/outline/sidebar/social.styl +69 -69
  112. package/source/css/_common/outline/sidebar/state.styl +37 -37
  113. package/source/css/_common/outline/sidebar/tab.styl +71 -71
  114. package/source/css/_common/outline/sidebar/toc.styl +47 -47
  115. package/source/css/_common/scaffolding/animate.styl +322 -322
  116. package/source/css/_common/scaffolding/base.styl +192 -192
  117. package/source/css/_common/scaffolding/buttons.styl +48 -48
  118. package/source/css/_common/scaffolding/divider.styl +36 -36
  119. package/source/css/_common/scaffolding/iconfont.styl +443 -443
  120. package/source/css/_common/scaffolding/normalize.styl +273 -273
  121. package/source/css/_common/scaffolding/pagination.styl +81 -81
  122. package/source/css/_common/scaffolding/ribbon.styl +38 -38
  123. package/source/css/_common/scaffolding/scaffolding.styl +14 -14
  124. package/source/css/_common/scaffolding/scrollbar.styl +37 -37
  125. package/source/css/_common/scaffolding/tables.styl +50 -50
  126. package/source/css/_common/scaffolding/tip.styl +19 -19
  127. package/source/css/_common/scaffolding/toggles.styl +59 -59
  128. package/source/css/_iconfont.styl +455 -455
  129. package/source/css/_mixins.styl +148 -148
  130. package/source/css/_variables.styl +89 -89
  131. package/source/css/app.styl +25 -25
  132. package/source/css/mermaid.styl +5 -5
  133. package/source/css/page.styl +2 -2
  134. package/source/css/post.styl +4 -5
  135. package/source/css/scaffolding.styl +4 -4
  136. package/source/js/_app/components/cloudflare.ts +18 -18
  137. package/source/js/_app/components/comments.ts +88 -88
  138. package/source/js/_app/components/sidebar.ts +243 -243
  139. package/source/js/_app/components/tcomments.ts +53 -53
  140. package/source/js/_app/globals/globalVars.ts +84 -84
  141. package/source/js/_app/globals/handles.ts +124 -124
  142. package/source/js/_app/globals/themeColor.ts +62 -62
  143. package/source/js/_app/globals/thirdparty.ts +63 -63
  144. package/source/js/_app/globals/tools.ts +73 -73
  145. package/source/js/_app/library/anime.ts +121 -121
  146. package/source/js/_app/library/declare.d.ts +129 -128
  147. package/source/js/_app/library/proto.ts +70 -70
  148. package/source/js/_app/library/vue.ts +49 -49
  149. package/source/js/_app/page/common.ts +41 -41
  150. package/source/js/_app/page/imageviewer.ts +15 -15
  151. package/source/js/_app/page/post.ts +251 -252
  152. package/source/js/_app/page/search.ts +109 -109
  153. package/source/js/_app/page/tab.ts +59 -59
  154. package/source/js/_app/pjax/domInit.ts +102 -102
  155. package/source/js/_app/pjax/refresh.ts +117 -117
  156. package/source/js/_app/pjax/siteInit.ts +93 -90
  157. package/source/js/_app/player.ts +13 -13
  158. package/toolbox/compiler.mjs +49 -49
  159. package/toolbox/dev-version.mjs +14 -14
  160. package/toolbox/hoistdep.mjs +5 -5
  161. package/toolbox/lib.mjs +63 -63
@@ -1,53 +1,53 @@
1
- import * as twikoo from 'twikoo'
2
- import { CONFIG } from '../globals/globalVars'
3
-
4
- export const twikooComment = function () {
5
- twikoo.init({
6
- envId: CONFIG.twikoo.envId,
7
- el: '#comments',
8
- region: CONFIG.twikoo.region
9
- })
10
- }
11
-
12
- export const twikooRecentComments = async function () {
13
- let comments = []
14
- const root = shokax_siteURL.replace(/^(https?:\/\/)?[^/]*/, '')
15
- const res = await twikoo.getRecentComments({
16
- envId: CONFIG.twikoo.envId,
17
- pageSize: 10
18
- })
19
- res.forEach(function (item) {
20
- let cText = item.commentText
21
- if (item.commentText.length > 50) {
22
- cText = item.commentText.substring(0, 50) + '...'
23
- }
24
- const siteLink = item.url + '#' + item.id
25
- comments.push({
26
- href: siteLink,
27
- nick: item.nick,
28
- time: item.relativeTime,
29
- text: cText
30
- })
31
- })
32
- const newComments = new DocumentFragment()
33
- comments.forEach(function (item) {
34
- const commentEl = document.createElement('li')
35
- const commentLink = document.createElement('a')
36
- const commentTime = document.createElement('span')
37
- const commentText = document.createElement('span')
38
-
39
- commentText.innerText = item.text
40
- commentTime.className = 'breadcrumb'
41
- commentTime.innerText = `${item.nick} @ ${item.time}`
42
- commentLink.href = root + item.href
43
- commentEl.className = 'item'
44
-
45
- commentText.appendChild(document.createElement('br'))
46
- commentLink.appendChild(commentTime)
47
- commentLink.appendChild(commentText)
48
- commentEl.appendChild(commentLink)
49
- newComments.appendChild(commentEl)
50
- })
51
-
52
- document.getElementById('new-comment').appendChild(newComments)
53
- }
1
+ import * as twikoo from 'twikoo'
2
+ import { CONFIG } from '../globals/globalVars'
3
+
4
+ export const twikooComment = function () {
5
+ twikoo.init({
6
+ envId: CONFIG.twikoo.envId,
7
+ el: '#comments',
8
+ region: CONFIG.twikoo.region
9
+ })
10
+ }
11
+
12
+ export const twikooRecentComments = async function () {
13
+ let comments = []
14
+ const root = shokax_siteURL.replace(/^(https?:\/\/)?[^/]*/, '')
15
+ const res = await twikoo.getRecentComments({
16
+ envId: CONFIG.twikoo.envId,
17
+ pageSize: 10
18
+ })
19
+ res.forEach(function (item) {
20
+ let cText = item.commentText
21
+ if (item.commentText.length > 50) {
22
+ cText = item.commentText.substring(0, 50) + '...'
23
+ }
24
+ const siteLink = item.url + '#' + item.id
25
+ comments.push({
26
+ href: siteLink,
27
+ nick: item.nick,
28
+ time: item.relativeTime,
29
+ text: cText
30
+ })
31
+ })
32
+ const newComments = new DocumentFragment()
33
+ comments.forEach(function (item) {
34
+ const commentEl = document.createElement('li')
35
+ const commentLink = document.createElement('a')
36
+ const commentTime = document.createElement('span')
37
+ const commentText = document.createElement('span')
38
+
39
+ commentText.innerText = item.text
40
+ commentTime.className = 'breadcrumb'
41
+ commentTime.innerText = `${item.nick} @ ${item.time}`
42
+ commentLink.href = root + item.href
43
+ commentEl.className = 'item'
44
+
45
+ commentText.appendChild(document.createElement('br'))
46
+ commentLink.appendChild(commentTime)
47
+ commentLink.appendChild(commentText)
48
+ commentEl.appendChild(commentLink)
49
+ newComments.appendChild(commentEl)
50
+ })
51
+
52
+ document.getElementById('new-comment').appendChild(newComments)
53
+ }
@@ -1,84 +1,84 @@
1
- export const CONFIG = shokax_CONFIG
2
- export const statics = CONFIG.statics.indexOf('//') > 0 ? CONFIG.statics : CONFIG.root
3
- export const scrollAction: { x: number, y: number } = { x: 0, y: 0 }
4
- export let diffY = 0
5
- export let originTitle: string, titleTime: NodeJS.Timeout
6
- export const BODY = document.getElementsByTagName('body')[0]
7
- export const HTML = document.documentElement
8
- export const Container = document.getElementById('container')
9
- export const loadCat = document.getElementById('loading')
10
- export const siteNav = document.getElementById('nav')
11
- export const siteHeader = document.getElementById('header')
12
- export const menuToggle = siteNav.querySelector('.toggle')
13
- export const quickBtn = document.getElementById('quick')
14
- export const sideBar = document.getElementById('sidebar')
15
- export const siteBrand = document.getElementById('brand')
16
- export let toolBtn = document.getElementById('tool')
17
- export let backToTop: HTMLElement
18
- export let goToComment
19
- export let showContents: HTMLElement
20
- export let siteSearch = document.getElementById('search')
21
- export let siteNavHeight: number, headerHightInner: number, headerHight: number
22
- export let oWinHeight = window.innerHeight
23
- export let oWinWidth = window.innerWidth
24
- export let LOCAL_HASH = 0
25
- export let LOCAL_URL = window.location.href
26
-
27
- export function setSiteNavHeight (value:number):void {
28
- siteNavHeight = value
29
- }
30
- export function setHeaderHightInner (value:number):void {
31
- headerHightInner = value
32
- }
33
-
34
- export function setHeaderHight (value:number):void {
35
- headerHight = value
36
- }
37
-
38
- export function setOWinHeight (value:number):void {
39
- oWinHeight = value
40
- }
41
-
42
- export function setOWinWidth (value:number):void {
43
- oWinWidth = value
44
- }
45
-
46
- export function setDiffY (value:number):void {
47
- diffY = value
48
- }
49
-
50
- export function setTitleTime (value:NodeJS.Timeout):void {
51
- titleTime = value
52
- }
53
-
54
- export function setLocalHash (value:number):void {
55
- LOCAL_HASH = value
56
- }
57
-
58
- export function setLocalUrl (value:string):void {
59
- LOCAL_URL = value
60
- }
61
-
62
- export function setOriginTitle (value:string):void {
63
- originTitle = value
64
- }
65
-
66
- export function setBackToTop (value:HTMLElement):void {
67
- backToTop = value
68
- }
69
-
70
- export function setGoToComment (value:any):void {
71
- goToComment = value
72
- }
73
-
74
- export function setShowContents (value:any):void {
75
- showContents = value
76
- }
77
-
78
- export function setToolBtn (value:HTMLElement):void {
79
- toolBtn = value
80
- }
81
-
82
- export function setSiteSearch (value:HTMLElement):void {
83
- siteSearch = value
84
- }
1
+ export const CONFIG = shokax_CONFIG
2
+ export const statics = CONFIG.statics.indexOf('//') > 0 ? CONFIG.statics : CONFIG.root
3
+ export const scrollAction: { x: number, y: number } = { x: 0, y: 0 }
4
+ export let diffY = 0
5
+ export let originTitle: string, titleTime: NodeJS.Timeout
6
+ export const BODY = document.getElementsByTagName('body')[0]
7
+ export const HTML = document.documentElement
8
+ export const Container = document.getElementById('container')
9
+ export const loadCat = document.getElementById('loading')
10
+ export const siteNav = document.getElementById('nav')
11
+ export const siteHeader = document.getElementById('header')
12
+ export const menuToggle = siteNav.querySelector('.toggle')
13
+ export const quickBtn = document.getElementById('quick')
14
+ export const sideBar = document.getElementById('sidebar')
15
+ export const siteBrand = document.getElementById('brand')
16
+ export let toolBtn = document.getElementById('tool')
17
+ export let backToTop: HTMLElement
18
+ export let goToComment
19
+ export let showContents: HTMLElement
20
+ export let siteSearch = document.getElementById('search')
21
+ export let siteNavHeight: number, headerHightInner: number, headerHight: number
22
+ export let oWinHeight = window.innerHeight
23
+ export let oWinWidth = window.innerWidth
24
+ export let LOCAL_HASH = 0
25
+ export let LOCAL_URL = window.location.href
26
+
27
+ export function setSiteNavHeight (value:number):void {
28
+ siteNavHeight = value
29
+ }
30
+ export function setHeaderHightInner (value:number):void {
31
+ headerHightInner = value
32
+ }
33
+
34
+ export function setHeaderHight (value:number):void {
35
+ headerHight = value
36
+ }
37
+
38
+ export function setOWinHeight (value:number):void {
39
+ oWinHeight = value
40
+ }
41
+
42
+ export function setOWinWidth (value:number):void {
43
+ oWinWidth = value
44
+ }
45
+
46
+ export function setDiffY (value:number):void {
47
+ diffY = value
48
+ }
49
+
50
+ export function setTitleTime (value:NodeJS.Timeout):void {
51
+ titleTime = value
52
+ }
53
+
54
+ export function setLocalHash (value:number):void {
55
+ LOCAL_HASH = value
56
+ }
57
+
58
+ export function setLocalUrl (value:string):void {
59
+ LOCAL_URL = value
60
+ }
61
+
62
+ export function setOriginTitle (value:string):void {
63
+ originTitle = value
64
+ }
65
+
66
+ export function setBackToTop (value:HTMLElement):void {
67
+ backToTop = value
68
+ }
69
+
70
+ export function setGoToComment (value:any):void {
71
+ goToComment = value
72
+ }
73
+
74
+ export function setShowContents (value:any):void {
75
+ showContents = value
76
+ }
77
+
78
+ export function setToolBtn (value:HTMLElement):void {
79
+ toolBtn = value
80
+ }
81
+
82
+ export function setSiteSearch (value:HTMLElement):void {
83
+ siteSearch = value
84
+ }
@@ -1,124 +1,124 @@
1
- import { sideBarToggleHandle } from '../components/sidebar'
2
- import {
3
- backToTop,
4
- diffY,
5
- headerHight,
6
- headerHightInner,
7
- oWinWidth,
8
- originTitle,
9
- scrollAction,
10
- sideBar,
11
- siteBrand,
12
- siteHeader,
13
- siteNav,
14
- statics,
15
- titleTime,
16
- toolBtn,
17
- setSiteNavHeight,
18
- setHeaderHightInner,
19
- setHeaderHight,
20
- setOWinHeight, setOWinWidth, setDiffY, setTitleTime, CONFIG
21
- } from './globalVars'
22
- import { changeMetaTheme } from './themeColor'
23
- import { Loader } from './thirdparty'
24
- import { getHeight, setWidth } from '../library/proto'
25
-
26
- const wavesEle = document.getElementById('waves')
27
-
28
- export const resizeHandle = () => {
29
- // 获取 siteNav 的高度
30
- setSiteNavHeight(getHeight(siteNav))
31
- // 获取 siteHeader 的高度
32
- setHeaderHightInner(getHeight(siteHeader))
33
- // 获取 #waves 的高度
34
- setHeaderHight(headerHightInner + getHeight(wavesEle))
35
-
36
- // 判断窗口宽度是否改变
37
- if (oWinWidth !== window.innerWidth) {
38
- sideBarToggleHandle(null, 1)
39
- }
40
-
41
- // 记录窗口高度和宽度
42
- setOWinHeight(window.innerHeight)
43
- setOWinWidth(window.innerWidth)
44
- }
45
-
46
- export const scrollHandle = () => {
47
- // 获取窗口高度
48
- const winHeight = window.innerHeight
49
- // 获取文档高度
50
- const docHeight = (document.querySelector('main > .inner') as HTMLElement).offsetHeight
51
- // 计算可见内容高度
52
- const contentVisibilityHeight = docHeight > winHeight ? docHeight - winHeight : document.body.scrollHeight - winHeight
53
- // 判断页面是否滚动超过 headerHightInner
54
- const SHOW = window.scrollY > headerHightInner
55
- // 判断页面是否开始滚动
56
- const startScroll = window.scrollY > 0
57
-
58
- // 根据条件修改 meta theme
59
- if (SHOW) {
60
- changeMetaTheme('#FFF')
61
- } else {
62
- changeMetaTheme('#222')
63
- }
64
-
65
- // 控制导航栏的显示隐藏
66
- siteNav.classList.toggle('show', SHOW)
67
- // 控制网站 logo 的显示隐藏
68
- toolBtn.classList.toggle('affix', startScroll)
69
- // 控制侧边栏的显示隐藏,当滚动高度大于 headerHight 且窗口宽度大于 991px 时显示
70
- siteBrand.classList.toggle('affix', startScroll)
71
- sideBar.classList.toggle('affix', window.scrollY > headerHight && document.body.offsetWidth >= 991)
72
- // 初始化滚动时导航栏的显示方向
73
- if (typeof scrollAction.y === 'undefined') {
74
- scrollAction.y = window.scrollY
75
- }
76
- setDiffY(scrollAction.y - window.scrollY)
77
-
78
- // 控制滑动时导航栏显示
79
- if (diffY < 0) {
80
- siteNav.classList.remove('up')
81
- siteNav.classList.toggle('down', SHOW)
82
- } else if (diffY > 0) {
83
- siteNav.classList.remove('down')
84
- siteNav.classList.toggle('up', SHOW)
85
- } else { /* empty */ }
86
- scrollAction.y = window.scrollY
87
- // 计算滚动百分比
88
- const scrollPercent = Math.round(Math.min(100 * window.scrollY / contentVisibilityHeight, 100)) + '%'
89
- // 更新回到顶部按钮的文字
90
- if (backToTop.querySelector('span').innerText !== scrollPercent) {
91
- backToTop.querySelector('span').innerText = scrollPercent
92
- }
93
- // 更新百分比进度条的宽度
94
- if (document.getElementById('sidebar').classList.contains('affix') || document.getElementById('sidebar').classList.contains('on')) {
95
- setWidth(document.querySelector('.percent'), scrollPercent)
96
- }
97
- }
98
-
99
- // 可见度监听(离开页面和返回时更改document的title)
100
- export const visibilityListener = () => {
101
- const iconNode = document.querySelector('[rel="icon"]')
102
- document.addEventListener('visibilitychange', () => {
103
- switch (document.visibilityState) {
104
- case 'hidden':
105
- iconNode.setAttribute('href', statics + CONFIG.favicon.hidden)
106
- document.title = LOCAL.favicon.hide
107
- if (CONFIG.loader.switch) {
108
- Loader.show()
109
- }
110
- clearTimeout(titleTime)
111
- break
112
- case 'visible':
113
- iconNode.setAttribute('href', statics + CONFIG.favicon.normal)
114
- document.title = LOCAL.favicon.show
115
- if (CONFIG.loader.switch) {
116
- Loader.hide(1000)
117
- }
118
- setTitleTime(setTimeout(() => {
119
- document.title = originTitle
120
- }, 2000))
121
- break
122
- }
123
- }, { passive: true })
124
- }
1
+ import { sideBarToggleHandle } from '../components/sidebar'
2
+ import {
3
+ backToTop,
4
+ diffY,
5
+ headerHight,
6
+ headerHightInner,
7
+ oWinWidth,
8
+ originTitle,
9
+ scrollAction,
10
+ sideBar,
11
+ siteBrand,
12
+ siteHeader,
13
+ siteNav,
14
+ statics,
15
+ titleTime,
16
+ toolBtn,
17
+ setSiteNavHeight,
18
+ setHeaderHightInner,
19
+ setHeaderHight,
20
+ setOWinHeight, setOWinWidth, setDiffY, setTitleTime, CONFIG
21
+ } from './globalVars'
22
+ import { changeMetaTheme } from './themeColor'
23
+ import { Loader } from './thirdparty'
24
+ import { getHeight, setWidth } from '../library/proto'
25
+
26
+ const wavesEle = document.getElementById('waves')
27
+
28
+ export const resizeHandle = () => {
29
+ // 获取 siteNav 的高度
30
+ setSiteNavHeight(getHeight(siteNav))
31
+ // 获取 siteHeader 的高度
32
+ setHeaderHightInner(getHeight(siteHeader))
33
+ // 获取 #waves 的高度
34
+ setHeaderHight(headerHightInner + getHeight(wavesEle))
35
+
36
+ // 判断窗口宽度是否改变
37
+ if (oWinWidth !== window.innerWidth) {
38
+ sideBarToggleHandle(null, 1)
39
+ }
40
+
41
+ // 记录窗口高度和宽度
42
+ setOWinHeight(window.innerHeight)
43
+ setOWinWidth(window.innerWidth)
44
+ }
45
+
46
+ export const scrollHandle = () => {
47
+ // 获取窗口高度
48
+ const winHeight = window.innerHeight
49
+ // 获取文档高度
50
+ const docHeight = (document.querySelector('main > .inner') as HTMLElement).offsetHeight
51
+ // 计算可见内容高度
52
+ const contentVisibilityHeight = docHeight > winHeight ? docHeight - winHeight : document.body.scrollHeight - winHeight
53
+ // 判断页面是否滚动超过 headerHightInner
54
+ const SHOW = window.scrollY > headerHightInner
55
+ // 判断页面是否开始滚动
56
+ const startScroll = window.scrollY > 0
57
+
58
+ // 根据条件修改 meta theme
59
+ if (SHOW) {
60
+ changeMetaTheme('#FFF')
61
+ } else {
62
+ changeMetaTheme('#222')
63
+ }
64
+
65
+ // 控制导航栏的显示隐藏
66
+ siteNav.classList.toggle('show', SHOW)
67
+ // 控制网站 logo 的显示隐藏
68
+ toolBtn.classList.toggle('affix', startScroll)
69
+ // 控制侧边栏的显示隐藏,当滚动高度大于 headerHight 且窗口宽度大于 991px 时显示
70
+ siteBrand.classList.toggle('affix', startScroll)
71
+ sideBar.classList.toggle('affix', window.scrollY > headerHight && document.body.offsetWidth >= 991)
72
+ // 初始化滚动时导航栏的显示方向
73
+ if (typeof scrollAction.y === 'undefined') {
74
+ scrollAction.y = window.scrollY
75
+ }
76
+ setDiffY(scrollAction.y - window.scrollY)
77
+
78
+ // 控制滑动时导航栏显示
79
+ if (diffY < 0) {
80
+ siteNav.classList.remove('up')
81
+ siteNav.classList.toggle('down', SHOW)
82
+ } else if (diffY > 0) {
83
+ siteNav.classList.remove('down')
84
+ siteNav.classList.toggle('up', SHOW)
85
+ } else { /* empty */ }
86
+ scrollAction.y = window.scrollY
87
+ // 计算滚动百分比
88
+ const scrollPercent = Math.round(Math.min(100 * window.scrollY / contentVisibilityHeight, 100)) + '%'
89
+ // 更新回到顶部按钮的文字
90
+ if (backToTop.querySelector('span').innerText !== scrollPercent) {
91
+ backToTop.querySelector('span').innerText = scrollPercent
92
+ }
93
+ // 更新百分比进度条的宽度
94
+ if (document.getElementById('sidebar').classList.contains('affix') || document.getElementById('sidebar').classList.contains('on')) {
95
+ setWidth(document.querySelector('.percent'), scrollPercent)
96
+ }
97
+ }
98
+
99
+ // 可见度监听(离开页面和返回时更改document的title)
100
+ export const visibilityListener = () => {
101
+ const iconNode = document.querySelector('[rel="icon"]')
102
+ document.addEventListener('visibilitychange', () => {
103
+ switch (document.visibilityState) {
104
+ case 'hidden':
105
+ iconNode.setAttribute('href', statics + CONFIG.favicon.hidden)
106
+ document.title = LOCAL.favicon.hide
107
+ if (CONFIG.loader.switch) {
108
+ Loader.show()
109
+ }
110
+ clearTimeout(titleTime)
111
+ break
112
+ case 'visible':
113
+ iconNode.setAttribute('href', statics + CONFIG.favicon.normal)
114
+ document.title = LOCAL.favicon.show
115
+ if (CONFIG.loader.switch) {
116
+ Loader.hide(1000)
117
+ }
118
+ setTitleTime(setTimeout(() => {
119
+ document.title = originTitle
120
+ }, 2000))
121
+ break
122
+ }
123
+ }, { passive: true })
124
+ }
@@ -1,62 +1,62 @@
1
- import { CONFIG, HTML } from './globalVars'
2
-
3
- /**
4
- * 更改日夜模式
5
- */
6
- export const changeTheme = (type?: string) => {
7
- const btn = document.querySelector('.theme .ic')
8
- if (type === 'dark') {
9
- HTML.setAttribute('data-theme', type)
10
- btn.classList.remove('i-sun')
11
- btn.classList.add('i-moon')
12
- } else {
13
- HTML.removeAttribute('data-theme')
14
- btn.classList.remove('i-moon')
15
- btn.classList.add('i-sun')
16
- }
17
- }
18
-
19
- /**
20
- * 自动调整黑夜白天
21
- * 优先级: 手动选择>时间>跟随系统
22
- */
23
- export const autoDarkmode = () => {
24
- if (CONFIG.auto_dark.enable) {
25
- if (new Date().getHours() >= CONFIG.auto_dark.start || new Date().getHours() <= CONFIG.auto_dark.end) {
26
- changeTheme('dark')
27
- } else {
28
- changeTheme()
29
- }
30
- }
31
- }
32
-
33
- /**
34
- * 更改主题的meta
35
- */
36
- export const changeMetaTheme = (color: string): void => {
37
- if (HTML.getAttribute('data-theme') === 'dark') {
38
- color = '#222'
39
- }
40
-
41
- document.querySelector('meta[name="theme-color"]').setAttribute('content', color)
42
- }
43
-
44
- // 记忆日夜模式切换和系统亮暗模式监听
45
- export const themeColorListener = () => {
46
- window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (mediaQueryList) => {
47
- if (mediaQueryList.matches) {
48
- changeTheme('dark')
49
- } else {
50
- changeTheme()
51
- }
52
- })
53
-
54
- const t = localStorage.getItem('theme')
55
- if (t) {
56
- changeTheme(t)
57
- } else {
58
- if (CONFIG.darkmode) {
59
- changeTheme('dark')
60
- }
61
- }
62
- }
1
+ import { CONFIG, HTML } from './globalVars'
2
+
3
+ /**
4
+ * 更改日夜模式
5
+ */
6
+ export const changeTheme = (type?: string) => {
7
+ const btn = document.querySelector('.theme .ic')
8
+ if (type === 'dark') {
9
+ HTML.setAttribute('data-theme', type)
10
+ btn.classList.remove('i-sun')
11
+ btn.classList.add('i-moon')
12
+ } else {
13
+ HTML.removeAttribute('data-theme')
14
+ btn.classList.remove('i-moon')
15
+ btn.classList.add('i-sun')
16
+ }
17
+ }
18
+
19
+ /**
20
+ * 自动调整黑夜白天
21
+ * 优先级: 手动选择>时间>跟随系统
22
+ */
23
+ export const autoDarkmode = () => {
24
+ if (CONFIG.auto_dark.enable) {
25
+ if (new Date().getHours() >= CONFIG.auto_dark.start || new Date().getHours() <= CONFIG.auto_dark.end) {
26
+ changeTheme('dark')
27
+ } else {
28
+ changeTheme()
29
+ }
30
+ }
31
+ }
32
+
33
+ /**
34
+ * 更改主题的meta
35
+ */
36
+ export const changeMetaTheme = (color: string): void => {
37
+ if (HTML.getAttribute('data-theme') === 'dark') {
38
+ color = '#222'
39
+ }
40
+
41
+ document.querySelector('meta[name="theme-color"]').setAttribute('content', color)
42
+ }
43
+
44
+ // 记忆日夜模式切换和系统亮暗模式监听
45
+ export const themeColorListener = () => {
46
+ window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (mediaQueryList) => {
47
+ if (mediaQueryList.matches) {
48
+ changeTheme('dark')
49
+ } else {
50
+ changeTheme()
51
+ }
52
+ })
53
+
54
+ const t = localStorage.getItem('theme')
55
+ if (t) {
56
+ changeTheme(t)
57
+ } else {
58
+ if (CONFIG.darkmode) {
59
+ changeTheme('dark')
60
+ }
61
+ }
62
+ }