hexo-theme-shokax 0.3.12 → 0.3.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. package/CODE_OF_CONDUCT.md +128 -128
  2. package/CONTRIBUTING.md +58 -58
  3. package/LICENSE +660 -660
  4. package/LICENSE-shoka +21 -21
  5. package/README.md +99 -92
  6. package/README_en.MD +90 -82
  7. package/UsageRestrictions.md +25 -25
  8. package/_config.yml +370 -373
  9. package/_images.yml +9 -9
  10. package/languages/README.md +19 -19
  11. package/languages/default.yml +1 -1
  12. package/languages/en.yml +153 -153
  13. package/languages/ja.yml +153 -153
  14. package/languages/zh-CN.yml +153 -153
  15. package/languages/zh-HK.yml +153 -153
  16. package/languages/zh-TW.yml +153 -153
  17. package/layout/_alternate/atom.ejs +30 -30
  18. package/layout/_alternate/json.ejs +16 -16
  19. package/layout/_alternate/rss.ejs +34 -34
  20. package/layout/_mixin/breadcrumb.pug +33 -33
  21. package/layout/_mixin/card.pug +38 -38
  22. package/layout/_mixin/comment.pug +41 -41
  23. package/layout/_mixin/postmeta.pug +29 -29
  24. package/layout/_mixin/segment.pug +32 -32
  25. package/layout/_mixin/sidebar.pug +40 -40
  26. package/layout/_mixin/widgets.pug +33 -33
  27. package/layout/_partials/footer.pug +42 -42
  28. package/layout/_partials/head/head.pug +57 -58
  29. package/layout/_partials/head/head_com.pug +17 -17
  30. package/layout/_partials/head/pwa.pug +18 -18
  31. package/layout/_partials/header.pug +18 -18
  32. package/layout/_partials/layout.pug +139 -139
  33. package/layout/_partials/loading.pug +13 -13
  34. package/layout/_partials/pagination.pug +4 -4
  35. package/layout/_partials/post/copyright.pug +20 -20
  36. package/layout/_partials/post/footer.pug +25 -25
  37. package/layout/_partials/post/nav.pug +13 -13
  38. package/layout/_partials/post/post.pug +41 -41
  39. package/layout/_partials/post/reward.pug +18 -18
  40. package/layout/_partials/sidebar/menu.pug +37 -37
  41. package/layout/_partials/sidebar/overview.pug +42 -42
  42. package/layout/_partials/third-party/baidu-analytics.pug +11 -11
  43. package/layout/_partials/third-party/clarity.pug +8 -8
  44. package/layout/_partials/third-party/google-analytics.pug +9 -9
  45. package/layout/archive.pug +118 -118
  46. package/layout/category.pug +59 -59
  47. package/layout/index.pug +33 -33
  48. package/layout/page.pug +55 -55
  49. package/layout/post.pug +36 -36
  50. package/layout/tag.pug +43 -43
  51. package/package.json +47 -47
  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 +6 -6
  56. package/source/css/_common/components/highlight/highlight.styl +357 -357
  57. package/source/css/_common/components/highlight/operation.styl +21 -21
  58. package/source/css/_common/components/pages/collapse.styl +119 -119
  59. package/source/css/_common/components/pages/home.styl +391 -391
  60. package/source/css/_common/components/pages/pages.styl +56 -56
  61. package/source/css/_common/components/pages/tag-cloud.styl +12 -12
  62. package/source/css/_common/components/post/breadcrumb.styl +39 -39
  63. package/source/css/_common/components/post/copyright.styl +41 -41
  64. package/source/css/_common/components/post/expand.styl +263 -263
  65. package/source/css/_common/components/post/footer.styl +11 -11
  66. package/source/css/_common/components/post/header.styl +79 -79
  67. package/source/css/_common/components/post/nav.styl +63 -63
  68. package/source/css/_common/components/post/post.styl +29 -29
  69. package/source/css/_common/components/post/reward.styl +50 -50
  70. package/source/css/_common/components/post/rtl.styl +12 -12
  71. package/source/css/_common/components/post/tags.styl +39 -39
  72. package/source/css/_common/components/tags/collapse.styl +72 -72
  73. package/source/css/_common/components/tags/container.styl +49 -49
  74. package/source/css/_common/components/tags/label.styl +12 -12
  75. package/source/css/_common/components/tags/links.styl +77 -77
  76. package/source/css/_common/components/tags/list.styl +131 -131
  77. package/source/css/_common/components/tags/note.styl +70 -70
  78. package/source/css/_common/components/tags/player.styl +361 -361
  79. package/source/css/_common/components/tags/quiz.styl +200 -200
  80. package/source/css/_common/components/tags/tabs.styl +89 -87
  81. package/source/css/_common/components/tags/tags.styl +9 -9
  82. package/source/css/_common/components/third-party/loading.styl +222 -222
  83. package/source/css/_common/components/third-party/mermaid/class.styl +90 -90
  84. package/source/css/_common/components/third-party/mermaid/flowchart.styl +72 -72
  85. package/source/css/_common/components/third-party/mermaid/gantt.styl +251 -251
  86. package/source/css/_common/components/third-party/mermaid/git.styl +7 -7
  87. package/source/css/_common/components/third-party/mermaid/mermaid.styl +37 -37
  88. package/source/css/_common/components/third-party/mermaid/pie.styl +9 -9
  89. package/source/css/_common/components/third-party/mermaid/sequence.styl +95 -95
  90. package/source/css/_common/components/third-party/mermaid/state.styl +130 -130
  91. package/source/css/_common/components/third-party/pace.styl +18 -18
  92. package/source/css/_common/components/third-party/search.styl +167 -167
  93. package/source/css/_common/components/third-party/theme.styl +151 -151
  94. package/source/css/_common/components/third-party/third-party.styl +22 -22
  95. package/source/css/_common/components/third-party/widgets.styl +57 -57
  96. package/source/css/_common/outline/footer/footer.styl +69 -69
  97. package/source/css/_common/outline/header/brand.styl +77 -77
  98. package/source/css/_common/outline/header/header.styl +20 -20
  99. package/source/css/_common/outline/header/image.styl +85 -85
  100. package/source/css/_common/outline/header/menu.styl +117 -117
  101. package/source/css/_common/outline/header/nav.styl +81 -81
  102. package/source/css/_common/outline/header/right.styl +15 -15
  103. package/source/css/_common/outline/header/tool.styl +207 -207
  104. package/source/css/_common/outline/header/waves.styl +57 -57
  105. package/source/css/_common/outline/mobile.styl +46 -46
  106. package/source/css/_common/outline/outline.styl +78 -78
  107. package/source/css/_common/outline/sidebar/author.styl +59 -59
  108. package/source/css/_common/outline/sidebar/dimmer.styl +23 -23
  109. package/source/css/_common/outline/sidebar/menu.styl +63 -63
  110. package/source/css/_common/outline/sidebar/quick.styl +43 -43
  111. package/source/css/_common/outline/sidebar/related.styl +56 -56
  112. package/source/css/_common/outline/sidebar/sidebar.styl +75 -75
  113. package/source/css/_common/outline/sidebar/social.styl +69 -69
  114. package/source/css/_common/outline/sidebar/state.styl +37 -37
  115. package/source/css/_common/outline/sidebar/tab.styl +71 -71
  116. package/source/css/_common/outline/sidebar/toc.styl +47 -47
  117. package/source/css/_common/scaffolding/animate.styl +322 -322
  118. package/source/css/_common/scaffolding/base.styl +190 -190
  119. package/source/css/_common/scaffolding/buttons.styl +48 -48
  120. package/source/css/_common/scaffolding/divider.styl +36 -36
  121. package/source/css/_common/scaffolding/iconfont.styl +443 -443
  122. package/source/css/_common/scaffolding/normalize.styl +273 -273
  123. package/source/css/_common/scaffolding/pagination.styl +81 -81
  124. package/source/css/_common/scaffolding/ribbon.styl +38 -38
  125. package/source/css/_common/scaffolding/scaffolding.styl +14 -14
  126. package/source/css/_common/scaffolding/scrollbar.styl +37 -37
  127. package/source/css/_common/scaffolding/tables.styl +50 -50
  128. package/source/css/_common/scaffolding/tip.styl +19 -19
  129. package/source/css/_common/scaffolding/toggles.styl +59 -59
  130. package/source/css/_iconfont.styl +455 -451
  131. package/source/css/_mixins.styl +148 -148
  132. package/source/css/_variables.styl +89 -89
  133. package/source/css/app.styl +41 -41
  134. package/source/css/comment.styl +3 -3
  135. package/source/css/mermaid.styl +5 -5
  136. package/source/css/optimize.styl +5 -5
  137. package/scripts/filters/locals.js +0 -52
  138. package/scripts/filters/post.js +0 -5
  139. package/scripts/generaters/archive.js +0 -133
  140. package/scripts/generaters/config.js +0 -48
  141. package/scripts/generaters/images.js +0 -23
  142. package/scripts/generaters/index.js +0 -107
  143. package/scripts/generaters/pages.js +0 -15
  144. package/scripts/generaters/script.js +0 -115
  145. package/scripts/helpers/asset.js +0 -147
  146. package/scripts/helpers/engine.js +0 -153
  147. package/scripts/helpers/list_categories.js +0 -84
  148. package/scripts/helpers/summary_ai.js +0 -107
  149. package/scripts/helpers/symbols_count_time.js +0 -69
  150. package/scripts/plugin/check.js +0 -32
  151. package/scripts/plugin/index.js +0 -78
  152. package/scripts/plugin/lib/injects-point.js +0 -20
  153. package/scripts/plugin/lib/injects.js +0 -89
  154. package/scripts/tags/links.js +0 -44
  155. package/scripts/tags/media.js +0 -19
  156. package/scripts/utils.js +0 -14
  157. package/source/css/twikoo.css +0 -2002
  158. package/source/js/_app/components/sidebar.js +0 -210
  159. package/source/js/_app/fireworks.js +0 -10
  160. package/source/js/_app/globals/globalVars.js +0 -80
  161. package/source/js/_app/globals/handles.js +0 -138
  162. package/source/js/_app/globals/themeColor.js +0 -62
  163. package/source/js/_app/globals/thirdparty.js +0 -71
  164. package/source/js/_app/globals/tools.js +0 -92
  165. package/source/js/_app/library/anime.js +0 -109
  166. package/source/js/_app/library/dom.js +0 -34
  167. package/source/js/_app/library/loadFile.js +0 -36
  168. package/source/js/_app/library/proto.js +0 -163
  169. package/source/js/_app/library/scriptPjax.js +0 -70
  170. package/source/js/_app/library/storage.js +0 -12
  171. package/source/js/_app/library/vue.js +0 -53
  172. package/source/js/_app/page/comment.js +0 -23
  173. package/source/js/_app/page/common.js +0 -41
  174. package/source/js/_app/page/fancybox.js +0 -65
  175. package/source/js/_app/page/post.js +0 -244
  176. package/source/js/_app/page/search.js +0 -118
  177. package/source/js/_app/page/tab.js +0 -53
  178. package/source/js/_app/pjax/domInit.js +0 -76
  179. package/source/js/_app/pjax/refresh.js +0 -53
  180. package/source/js/_app/pjax/siteInit.js +0 -49
  181. package/source/js/_app/player.js +0 -774
@@ -1,210 +0,0 @@
1
- /* 边栏分区 */
2
- import { Container, diffY, menuToggle, showContents, sideBar } from '../globals/globalVars';
3
- import { clipBoard } from '../globals/tools';
4
- import { pageScroll, transition } from '../library/anime';
5
- import { $dom } from '../library/dom';
6
- export const sideBarToggleHandle = (event, force) => {
7
- if (sideBar.hasClass('on')) {
8
- sideBar.removeClass('on');
9
- menuToggle.removeClass('close');
10
- if (force) {
11
- // @ts-ignore
12
- // noinspection JSConstantReassignment
13
- sideBar.style = '';
14
- }
15
- else {
16
- transition(sideBar, 'slideRightOut');
17
- }
18
- }
19
- else {
20
- if (force) {
21
- // @ts-ignore
22
- // noinspection JSConstantReassignment
23
- sideBar.style = '';
24
- }
25
- else {
26
- transition(sideBar, 'slideRightIn', () => {
27
- sideBar.addClass('on');
28
- menuToggle.addClass('close');
29
- });
30
- }
31
- }
32
- };
33
- export const sideBarTab = () => {
34
- const sideBarInner = sideBar.child('.inner');
35
- if (sideBar.child('.tab')) {
36
- sideBarInner.removeChild(sideBar.child('.tab'));
37
- }
38
- const list = document.createElement('ul');
39
- let active = 'active';
40
- list.className = 'tab';
41
- ['contents', 'related', 'overview'].forEach((item) => {
42
- const element = sideBar.child('.panel.' + item);
43
- if (element.innerHTML.trim().length < 1) {
44
- if (item === 'contents') {
45
- showContents.display('none');
46
- }
47
- return;
48
- }
49
- if (item === 'contents') {
50
- showContents.display('');
51
- }
52
- const tab = document.createElement('li');
53
- const span = document.createElement('span');
54
- const text = document.createTextNode(element.attr('data-title'));
55
- span.appendChild(text);
56
- tab.appendChild(span);
57
- tab.addClass(item + ' item');
58
- if (active) {
59
- element.addClass(active);
60
- tab.addClass(active);
61
- }
62
- else {
63
- element.removeClass('active');
64
- }
65
- tab.addEventListener('click', (event) => {
66
- const target = event.currentTarget;
67
- if (target.hasClass('active'))
68
- return;
69
- sideBar.find('.tab .item').forEach((element) => {
70
- element.removeClass('active');
71
- });
72
- sideBar.find('.panel').forEach((element) => {
73
- element.removeClass('active');
74
- });
75
- sideBar.child('.panel.' + target.className.replace(' item', '')).addClass('active');
76
- target.addClass('active');
77
- });
78
- list.appendChild(tab);
79
- active = '';
80
- });
81
- if (list.childNodes.length > 1) {
82
- sideBarInner.insertBefore(list, sideBarInner.childNodes[0]);
83
- sideBar.child('.panels').style.paddingTop = '';
84
- }
85
- else {
86
- sideBar.child('.panels').style.paddingTop = '.625rem';
87
- }
88
- };
89
- export const sidebarTOC = () => {
90
- const activateNavByIndex = (index) => {
91
- const target = navItems[index];
92
- if (!target)
93
- return;
94
- if (target.hasClass('current')) {
95
- return;
96
- }
97
- $dom.each('.toc .active', (element) => {
98
- element && element.removeClass('active current');
99
- });
100
- sections.forEach((element) => {
101
- element && element.removeClass('active');
102
- });
103
- target.addClass('active current');
104
- sections[index] && sections[index].addClass('active');
105
- let parent = target.parentNode;
106
- while (!parent.matches('.contents')) {
107
- if (parent.matches('li')) {
108
- parent.addClass('active');
109
- const t = $dom(parent.child('a.toc-link').attr('href'));
110
- if (t) {
111
- t.addClass('active');
112
- }
113
- }
114
- parent = parent.parentNode;
115
- }
116
- // Scrolling to center active TOC element if TOC content is taller than viewport.
117
- if (getComputedStyle(sideBar).display !== 'none' && tocElement.hasClass('active')) {
118
- pageScroll(tocElement, target.offsetTop - (tocElement.offsetHeight / 4));
119
- }
120
- };
121
- const navItems = $dom.all('.contents li');
122
- if (navItems.length < 1) {
123
- return;
124
- }
125
- // @ts-ignore
126
- let sections = [...navItems];
127
- let activeLock = null;
128
- sections = sections.map((element, index) => {
129
- const link = element.child('a.toc-link');
130
- const anchor = $dom(decodeURI(link.attr('href')));
131
- if (!anchor)
132
- return null;
133
- const alink = anchor.child('a.anchor');
134
- const anchorScroll = (event) => {
135
- event.preventDefault();
136
- const target = $dom(decodeURI(event.currentTarget.attr('href')));
137
- activeLock = index;
138
- pageScroll(target, null, () => {
139
- activateNavByIndex(index);
140
- activeLock = null;
141
- });
142
- };
143
- // TOC item animation navigate.
144
- link.addEventListener('click', anchorScroll);
145
- alink && alink.addEventListener('click', (event) => {
146
- anchorScroll(event);
147
- clipBoard(CONFIG.hostname + '/' + LOCAL.path + event.currentTarget.attr('href'));
148
- });
149
- return anchor;
150
- });
151
- const tocElement = sideBar.child('.contents.panel');
152
- const findIndex = (entries) => {
153
- let index = 0;
154
- let entry = entries[index];
155
- if (entry.boundingClientRect.top > 0) {
156
- index = sections.indexOf(entry.target);
157
- return index === 0 ? 0 : index - 1;
158
- }
159
- for (; index < entries.length; index++) {
160
- if (entries[index].boundingClientRect.top <= 0) {
161
- entry = entries[index];
162
- }
163
- else {
164
- return sections.indexOf(entry.target);
165
- }
166
- }
167
- return sections.indexOf(entry.target);
168
- };
169
- const createIntersectionObserver = () => {
170
- const observer = new IntersectionObserver((entries) => {
171
- const index = findIndex(entries) + (diffY < 0 ? 1 : 0);
172
- if (activeLock === null) {
173
- activateNavByIndex(index);
174
- }
175
- }, {
176
- rootMargin: '0px 0px -100% 0px', threshold: 0
177
- });
178
- sections.forEach((element) => {
179
- element && observer.observe(element);
180
- });
181
- };
182
- createIntersectionObserver();
183
- };
184
- export const backToTopHandle = () => {
185
- pageScroll(0);
186
- };
187
- export const goToBottomHandle = () => {
188
- pageScroll(parseInt(String(Container.changeOrGetHeight())));
189
- };
190
- export const goToCommentHandle = () => {
191
- pageScroll($dom('#comments'));
192
- };
193
- export const menuActive = () => {
194
- $dom.each('.menu .item:not(.title)', (element) => {
195
- const target = element.child('a[href]');
196
- const parentItem = element.parentNode.parentNode;
197
- if (!target)
198
- return;
199
- const isSamePath = target.pathname === location.pathname || target.pathname === location.pathname.replace('index.html', '');
200
- const isSubPath = !CONFIG.root.startsWith(target.pathname) && location.pathname.startsWith(target.pathname);
201
- const active = target.hostname === location.hostname && (isSamePath || isSubPath);
202
- element.toggleClass('active', active);
203
- if (element.parentNode.child('.active') && parentItem.hasClass('dropdown')) {
204
- parentItem.removeClass('active').addClass('expand');
205
- }
206
- else {
207
- parentItem.removeClass('expand');
208
- }
209
- });
210
- };
@@ -1,10 +0,0 @@
1
- import firework from 'mouse-firework';
2
- /*
3
- * 烟花分区
4
- */
5
- export function initFireworks() {
6
- if (typeof CONFIG.fireworks === 'undefined') {
7
- return;
8
- }
9
- firework(CONFIG.fireworks);
10
- }
@@ -1,80 +0,0 @@
1
- import { $dom } from '../library/dom';
2
- import initProto from '../library/proto';
3
- initProto();
4
- export const statics = CONFIG.statics.indexOf('//') > 0 ? CONFIG.statics : CONFIG.root;
5
- export const scrollAction = { x: 0, y: 0 };
6
- export let diffY = 0;
7
- export let originTitle, titleTime;
8
- export const BODY = document.getElementsByTagName('body')[0];
9
- export const HTML = document.documentElement;
10
- export const Container = $dom('#container');
11
- export const loadCat = $dom('#loading');
12
- export const siteNav = $dom('#nav');
13
- export const siteHeader = $dom('#header');
14
- export const menuToggle = siteNav.child('.toggle');
15
- export const quickBtn = $dom('#quick');
16
- export const sideBar = $dom('#sidebar');
17
- export const siteBrand = $dom('#brand');
18
- export let toolBtn = $dom('#tool');
19
- export let toolPlayer;
20
- export let backToTop;
21
- export let goToComment;
22
- export let showContents;
23
- export let siteSearch = $dom('#search');
24
- export let siteNavHeight, headerHightInner, headerHight;
25
- export let oWinHeight = window.innerHeight;
26
- export let oWinWidth = window.innerWidth;
27
- export let LOCAL_HASH = 0;
28
- export let LOCAL_URL = window.location.href;
29
- export let pjax;
30
- export function setSiteNavHeight(value) {
31
- siteNavHeight = value;
32
- }
33
- export function setHeaderHightInner(value) {
34
- headerHightInner = value;
35
- }
36
- export function setHeaderHight(value) {
37
- headerHight = value;
38
- }
39
- export function setOWinHeight(value) {
40
- oWinHeight = value;
41
- }
42
- export function setOWinWidth(value) {
43
- oWinWidth = value;
44
- }
45
- export function setDiffY(value) {
46
- diffY = value;
47
- }
48
- export function setTitleTime(value) {
49
- titleTime = value;
50
- }
51
- export function setLocalHash(value) {
52
- LOCAL_HASH = value;
53
- }
54
- export function setLocalUrl(value) {
55
- LOCAL_URL = value;
56
- }
57
- export function setPjax(value) {
58
- pjax = value;
59
- }
60
- export function setOriginTitle(value) {
61
- originTitle = value;
62
- }
63
- export function setToolPlayer(value) {
64
- toolPlayer = value;
65
- }
66
- export function setBackToTop(value) {
67
- backToTop = value;
68
- }
69
- export function setGoToComment(value) {
70
- goToComment = value;
71
- }
72
- export function setShowContents(value) {
73
- showContents = value;
74
- }
75
- export function setToolBtn(value) {
76
- toolBtn = value;
77
- }
78
- export function setSiteSearch(value) {
79
- siteSearch = value;
80
- }
@@ -1,138 +0,0 @@
1
- import { sideBarToggleHandle } from '../components/sidebar';
2
- import { $dom, getDocHeight } from '../library/dom';
3
- import { backToTop, diffY, headerHight, headerHightInner, oWinWidth, originTitle, scrollAction, sideBar, siteBrand, siteHeader, siteNav, statics, titleTime, toolBtn, setSiteNavHeight, setHeaderHightInner, setHeaderHight, setOWinHeight, setOWinWidth, setDiffY, setTitleTime } from './globalVars';
4
- import { changeMetaTheme } from './themeColor';
5
- import { Loader } from './thirdparty';
6
- export const resizeHandle = () => {
7
- // 获取 siteNav 的高度
8
- setSiteNavHeight(siteNav.changeOrGetHeight());
9
- // 获取 siteHeader 的高度
10
- setHeaderHightInner(siteHeader.changeOrGetHeight());
11
- // 获取 #waves 的高度
12
- setHeaderHight(headerHightInner + $dom('#waves').changeOrGetHeight());
13
- // 判断窗口宽度是否改变
14
- if (oWinWidth !== window.innerWidth) {
15
- sideBarToggleHandle(null, 1);
16
- }
17
- // 记录窗口高度和宽度
18
- setOWinHeight(window.innerHeight);
19
- setOWinWidth(window.innerWidth);
20
- };
21
- export const scrollHandle = () => {
22
- // 获取窗口高度
23
- const winHeight = window.innerHeight;
24
- // 获取文档高度
25
- const docHeight = getDocHeight();
26
- // 计算可见内容高度
27
- const contentVisibilityHeight = docHeight > winHeight ? docHeight - winHeight : document.body.scrollHeight - winHeight;
28
- // 判断页面是否滚动超过 headerHightInner
29
- const SHOW = window.scrollY > headerHightInner;
30
- // 判断页面是否开始滚动
31
- const startScroll = window.scrollY > 0;
32
- // 根据条件修改 meta theme
33
- if (SHOW) {
34
- changeMetaTheme('#FFF');
35
- }
36
- else {
37
- changeMetaTheme('#222');
38
- }
39
- // 控制导航栏的显示隐藏
40
- siteNav.toggleClass('show', SHOW);
41
- // 控制网站 logo 的显示隐藏
42
- toolBtn.toggleClass('affix', startScroll);
43
- // 控制侧边栏的显示隐藏,当滚动高度大于 headerHight 且窗口宽度大于 991px 时显示
44
- siteBrand.toggleClass('affix', startScroll);
45
- sideBar.toggleClass('affix', window.scrollY > headerHight && document.body.offsetWidth > 991);
46
- // 初始化滚动时导航栏的显示方向
47
- if (typeof scrollAction.y === 'undefined') {
48
- scrollAction.y = window.scrollY;
49
- }
50
- setDiffY(scrollAction.y - window.scrollY);
51
- // 控制滑动时导航栏显示
52
- if (diffY < 0) {
53
- siteNav.removeClass('up');
54
- siteNav.toggleClass('down', SHOW);
55
- }
56
- else if (diffY > 0) {
57
- siteNav.removeClass('down');
58
- siteNav.toggleClass('up', SHOW);
59
- }
60
- else { /* empty */ }
61
- scrollAction.y = window.scrollY;
62
- // 计算滚动百分比
63
- const scrollPercent = Math.round(Math.min(100 * window.scrollY / contentVisibilityHeight, 100)) + '%';
64
- // 更新回到顶部按钮的文字
65
- if (backToTop.child('span').innerText !== scrollPercent) {
66
- backToTop.child('span').innerText = scrollPercent;
67
- }
68
- // 更新百分比进度条的宽度
69
- if ($dom('#sidebar').hasClass('affix') || $dom('#sidebar').hasClass('on')) {
70
- $dom('.percent').changeOrGetWidth(scrollPercent);
71
- }
72
- };
73
- /**
74
- * 此函数用于修改右键点击显示菜单 <br/>
75
- * 需要在document下存在如下元素:
76
- * - id为clickMenu的容器(右键菜单容器)
77
- * - class为clickSubmenu的容器(可以有0到无限个)(子菜单容器)
78
- * CSS应有如下class:
79
- * - clickMenu的active类(控制显示)
80
- */
81
- export const clickMenu = () => {
82
- const menuElement = $dom('#clickMenu');
83
- window.oncontextmenu = function (event) {
84
- if (event.ctrlKey) { // 当按下ctrl键时不触发自定义菜单
85
- return;
86
- }
87
- event.preventDefault();
88
- let x = event.offsetX; // 触发点到页面窗口左边的距离
89
- let y = event.offsetY;
90
- const winWidth = window.innerWidth; // 窗口的内部宽度(包括滚动条)
91
- const winHeight = window.innerHeight;
92
- const menuWidth = menuElement.offsetWidth; // 菜单宽度
93
- const menuHeight = menuElement.offsetHeight;
94
- x = winWidth - menuWidth >= x ? x : winWidth - menuWidth;
95
- y = winHeight - menuHeight >= y ? y : winHeight - menuHeight;
96
- menuElement.style.top = y + 'px';
97
- menuElement.style.left = x + 'px';
98
- menuElement.classList.add('active');
99
- $dom.each('.clickSubmenu', (submenu) => {
100
- if (x > (winWidth - menuWidth - submenu.offsetWidth)) {
101
- submenu.style.left = '-200px';
102
- }
103
- else {
104
- submenu.style.left = '';
105
- submenu.style.right = '-200px';
106
- }
107
- });
108
- };
109
- window.addEventListener('click', () => {
110
- menuElement.classList.remove('active');
111
- });
112
- };
113
- // 可见度监听(离开页面和返回时更改document的title)
114
- export const visibilityListener = () => {
115
- const iconNode = $dom('[rel="icon"]');
116
- document.addEventListener('visibilitychange', () => {
117
- switch (document.visibilityState) {
118
- case 'hidden':
119
- iconNode.attr('href', statics + CONFIG.favicon.hidden);
120
- document.title = LOCAL.favicon.hide;
121
- if (CONFIG.loader.switch) {
122
- Loader.show();
123
- }
124
- clearTimeout(titleTime);
125
- break;
126
- case 'visible':
127
- iconNode.attr('href', statics + CONFIG.favicon.normal);
128
- document.title = LOCAL.favicon.show;
129
- if (CONFIG.loader.switch) {
130
- Loader.hide(1000);
131
- }
132
- setTitleTime(setTimeout(() => {
133
- document.title = originTitle;
134
- }, 2000));
135
- break;
136
- }
137
- });
138
- };
@@ -1,62 +0,0 @@
1
- import { $storage } from '../library/storage';
2
- import { $dom } from '../library/dom';
3
- import { HTML } from './globalVars';
4
- /**
5
- * 更改日夜模式
6
- */
7
- export const changeTheme = (type) => {
8
- const btn = $dom('.theme .ic');
9
- if (type === 'dark') {
10
- HTML.attr('data-theme', type);
11
- btn.removeClass('i-sun');
12
- btn.addClass('i-moon');
13
- }
14
- else {
15
- HTML.attr('data-theme', null);
16
- btn.removeClass('i-moon');
17
- btn.addClass('i-sun');
18
- }
19
- };
20
- /**
21
- * 自动调整黑夜白天
22
- * 优先级: 手动选择>时间>跟随系统
23
- */
24
- export const autoDarkmode = () => {
25
- if (CONFIG.auto_dark.enable) {
26
- if (new Date().getHours() >= CONFIG.auto_dark.start || new Date().getHours() <= CONFIG.auto_dark.end) {
27
- changeTheme('dark');
28
- }
29
- else {
30
- changeTheme();
31
- }
32
- }
33
- };
34
- /**
35
- * 更改主题的meta
36
- */
37
- export const changeMetaTheme = (color) => {
38
- if (HTML.attr('data-theme') === 'dark') {
39
- color = '#222';
40
- }
41
- $dom('meta[name="theme-color"]').attr('content', color);
42
- };
43
- // 记忆日夜模式切换和系统亮暗模式监听
44
- export const themeColorListener = () => {
45
- window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (mediaQueryList) => {
46
- if (mediaQueryList.matches) {
47
- changeTheme('dark');
48
- }
49
- else {
50
- changeTheme();
51
- }
52
- });
53
- const t = $storage.get('theme');
54
- if (t) {
55
- changeTheme(t);
56
- }
57
- else {
58
- if (CONFIG.darkmode) {
59
- changeTheme('dark');
60
- }
61
- }
62
- };
@@ -1,71 +0,0 @@
1
- // 与第三方js的交互或第三方嵌入js
2
- import lozad from 'lozad';
3
- import { loadCat } from './globalVars';
4
- import { transition } from '../library/anime';
5
- /**
6
- * 懒加载图片
7
- */
8
- export const lazyload = lozad('img, [data-background-image]', {
9
- loaded(el) {
10
- el.addClass('lozaded');
11
- }
12
- });
13
- // 加载动画
14
- export const Loader = {
15
- timer: undefined,
16
- lock: false,
17
- show() {
18
- clearTimeout(this.timer);
19
- document.body.removeClass('loaded');
20
- loadCat.attr('style', 'display:block');
21
- Loader.lock = false;
22
- },
23
- hide(sec) {
24
- if (!CONFIG.loader.start) {
25
- sec = -1;
26
- }
27
- this.timer = setTimeout(this.vanish, sec || 3000);
28
- },
29
- vanish() {
30
- if (Loader.lock) {
31
- return;
32
- }
33
- if (CONFIG.loader.start) {
34
- transition(loadCat, 0);
35
- }
36
- document.body.addClass('loaded');
37
- Loader.lock = true;
38
- }
39
- };
40
- export const isOutime = () => {
41
- let updateTime;
42
- if (CONFIG.outime.enable && LOCAL.outime) {
43
- const times = document.getElementsByTagName('time');
44
- if (times.length === 0) {
45
- return;
46
- }
47
- const posts = document.getElementsByClassName('body md');
48
- if (posts.length === 0) {
49
- return;
50
- }
51
- const now = Date.now(); // 当前时间戳
52
- const pubTime = new Date(times[0].dateTime); // 文章发布时间戳
53
- if (times.length === 1) {
54
- updateTime = pubTime; // 文章发布时间亦是最后更新时间
55
- }
56
- else {
57
- updateTime = new Date(times[1].dateTime); // 文章最后更新时间戳
58
- }
59
- // @ts-ignore
60
- const interval = parseInt(String(now - updateTime)); // 时间差
61
- const days = parseInt(String(CONFIG.outime.days)) || 30; // 设置时效,默认硬编码 30 天
62
- // 最后一次更新时间超过 days 天(毫秒)
63
- if (interval > (days * 86400000)) {
64
- // @ts-ignore
65
- const publish = parseInt(String((now - pubTime) / 86400000));
66
- const updated = parseInt(String(interval / 86400000));
67
- const template = LOCAL.template.replace('{{publish}}', String(publish)).replace('{{updated}}', String(updated));
68
- posts[0].insertAdjacentHTML('afterbegin', template);
69
- }
70
- }
71
- };
@@ -1,92 +0,0 @@
1
- import { pageScroll } from '../library/anime';
2
- import { $dom } from '../library/dom';
3
- import { $storage } from '../library/storage';
4
- import { BODY, LOCAL_HASH, LOCAL_URL, scrollAction, setLocalHash } from './globalVars';
5
- // 显示提示(现阶段用于版权及复制结果提示)
6
- export const showtip = (msg) => {
7
- if (!msg) {
8
- return;
9
- }
10
- const tipbox = BODY.createChild('div', {
11
- innerHTML: msg,
12
- className: 'tip'
13
- });
14
- setTimeout(() => {
15
- tipbox.addClass('hide');
16
- setTimeout(() => {
17
- BODY.removeChild(tipbox);
18
- }, 300);
19
- }, 3000);
20
- };
21
- export const pagePosition = () => {
22
- // 判断配置项是否开启了自动记录滚动位置
23
- if (CONFIG.auto_scroll) {
24
- // 将当前页面的滚动位置存入本地缓存
25
- $storage.set(LOCAL_URL, String(scrollAction.y));
26
- }
27
- };
28
- export const positionInit = (comment) => {
29
- // 获取页面锚点
30
- const anchor = window.location.hash;
31
- let target = null;
32
- if (LOCAL_HASH) {
33
- $storage.del(LOCAL_URL);
34
- return;
35
- }
36
- if (anchor) {
37
- target = $dom(decodeURI(anchor));
38
- }
39
- else {
40
- target = CONFIG.auto_scroll ? parseInt($storage.get(LOCAL_URL)) : 0;
41
- }
42
- if (target) {
43
- pageScroll(target);
44
- setLocalHash(1);
45
- }
46
- if (comment && anchor && !LOCAL_HASH) {
47
- pageScroll(target);
48
- setLocalHash(1);
49
- }
50
- };
51
- /*
52
- 这段代码是用来复制文本的。它使用了浏览器的 Clipboard API,如果浏览器支持该 API 并且当前页面是安全协议 (https),
53
- 它将使用 Clipboard API 将文本复制到剪贴板。如果不支持,它会创建一个隐藏的文本区域并使用 document.execCommand('copy') 将文本复制到剪贴板。
54
- 最后,它会回调传入的函数并传入一个布尔值表示是否成功复制。
55
- */
56
- export const clipBoard = (str, callback) => {
57
- if (navigator.clipboard && window.isSecureContext) {
58
- navigator.clipboard.writeText(str).then(() => {
59
- // eslint-disable-next-line chai-friendly/no-unused-expressions
60
- callback && callback(true);
61
- }, () => {
62
- // eslint-disable-next-line chai-friendly/no-unused-expressions
63
- callback && callback(false);
64
- });
65
- }
66
- else {
67
- // TODO 根据caniuse,需要此polyfill的设备不足5%,应考虑删除
68
- const ta = BODY.createChild('textarea', {
69
- style: {
70
- top: window.scrollY + 'px',
71
- position: 'absolute',
72
- opacity: '0'
73
- },
74
- readOnly: true,
75
- value: str
76
- });
77
- const selection = document.getSelection();
78
- const selected = selection.rangeCount > 0 ? selection.getRangeAt(0) : false;
79
- ta.select();
80
- ta.setSelectionRange(0, str.length);
81
- ta.readOnly = false;
82
- const result = document.execCommand('copy');
83
- // eslint-disable-next-line chai-friendly/no-unused-expressions
84
- callback && callback(result);
85
- ta.blur(); // For iOS
86
- if (selected) {
87
- selection.removeAllRanges();
88
- selection.addRange(selected);
89
- }
90
- BODY.removeChild(ta);
91
- }
92
- };