hexo-theme-shokax 0.4.6-dev1 → 0.4.6-dev3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. package/package.json +1 -1
  2. package/toolbox/lib.mjs +38 -23
  3. package/scripts/filters/locals.js +0 -52
  4. package/scripts/filters/post.js +0 -5
  5. package/scripts/generaters/archive.js +0 -133
  6. package/scripts/generaters/config.js +0 -51
  7. package/scripts/generaters/images.js +0 -23
  8. package/scripts/generaters/index.js +0 -107
  9. package/scripts/generaters/pages.js +0 -15
  10. package/scripts/generaters/script.js +0 -156
  11. package/scripts/helpers/asset.js +0 -73
  12. package/scripts/helpers/engine.js +0 -177
  13. package/scripts/helpers/list_categories.js +0 -80
  14. package/scripts/helpers/summary_ai.js +0 -107
  15. package/scripts/helpers/symbols_count_time.js +0 -69
  16. package/scripts/plugin/check.js +0 -32
  17. package/scripts/plugin/index.js +0 -81
  18. package/scripts/plugin/lib/injects-point.js +0 -20
  19. package/scripts/plugin/lib/injects.js +0 -89
  20. package/scripts/tags/links.js +0 -44
  21. package/scripts/tags/media.js +0 -19
  22. package/scripts/utils.js +0 -13
  23. package/source/js/_app/components/comments.js +0 -59
  24. package/source/js/_app/components/sidebar.js +0 -244
  25. package/source/js/_app/components/tcomments.js +0 -47
  26. package/source/js/_app/globals/handles.js +0 -105
  27. package/source/js/_app/library/loadFile.js +0 -43
  28. package/source/js/_app/library/vue.js +0 -52
  29. package/source/js/_app/page/common.js +0 -45
  30. package/source/js/_app/page/fancybox.js +0 -70
  31. package/source/js/_app/page/post.js +0 -253
  32. package/source/js/_app/page/search.js +0 -111
  33. package/source/js/_app/pjax/domInit.js +0 -80
  34. package/source/js/_app/pjax/refresh.js +0 -137
  35. package/source/js/_app/pjax/siteInit.js +0 -115
  36. package/source/js/_app/player.js +0 -777
@@ -1,89 +0,0 @@
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
- /*!
7
- inject.js in next-theme/hexo-theme-next by next-theme
8
- under GNU AFFERO GENERAL PUBLIC LICENSE v3.0 OR LATER
9
- https://github.com/next-theme/hexo-theme-next/blob/master/LICENSE.md
10
- */
11
- const node_fs_1 = __importDefault(require("node:fs"));
12
- const node_path_1 = __importDefault(require("node:path"));
13
- const injects_point_1 = __importDefault(require("./injects-point"));
14
- const defaultExtname = '.pug';
15
- class StylusInject {
16
- files;
17
- base_dir;
18
- constructor(base_dir) {
19
- this.base_dir = base_dir;
20
- this.files = [];
21
- }
22
- push(file) {
23
- this.files.push(node_path_1.default.resolve(this.base_dir, file));
24
- }
25
- }
26
- // Defining view types
27
- class ViewInject {
28
- base_dir;
29
- raws;
30
- constructor(base_dir) {
31
- this.base_dir = base_dir;
32
- this.raws = [];
33
- }
34
- raw(name, raw, ...args) {
35
- // Set default extname
36
- if (node_path_1.default.extname(name) === '') {
37
- name += defaultExtname;
38
- }
39
- this.raws.push({ name, raw, args });
40
- }
41
- file(name, file, ...args) {
42
- // Set default extname from file's extname
43
- if (node_path_1.default.extname(name) === '') {
44
- name += node_path_1.default.extname(file);
45
- }
46
- // Get absolute path base on hexo dir
47
- this.raw(name, node_fs_1.default.readFileSync(node_path_1.default.resolve(this.base_dir, file), 'utf8'), ...args);
48
- }
49
- }
50
- // Init injects
51
- function initInject(base_dir) {
52
- const injects = {};
53
- injects_point_1.default.styles.forEach(item => {
54
- injects[item] = new StylusInject(base_dir);
55
- });
56
- injects_point_1.default.views.forEach(item => {
57
- injects[item] = new ViewInject(base_dir);
58
- });
59
- return injects;
60
- }
61
- exports.default = (hexo) => {
62
- // Exec theme_inject filter
63
- const injects = initInject(hexo.base_dir);
64
- hexo.execFilterSync('theme_inject', injects);
65
- hexo.theme.config.injects = {};
66
- // Inject stylus
67
- injects_point_1.default.styles.forEach(type => {
68
- hexo.theme.config.injects[type] = injects[type].files;
69
- });
70
- // Inject views
71
- injects_point_1.default.views.forEach(type => {
72
- const configs = Object.create(null);
73
- hexo.theme.config.injects[type] = [];
74
- // Add or override view.
75
- injects[type].raws.forEach((injectObj, index) => {
76
- const name = `inject/${type}/${injectObj.name}`;
77
- hexo.theme.setView(name, injectObj.raw);
78
- configs[name] = {
79
- layout: name,
80
- locals: injectObj.args[0],
81
- options: injectObj.args[1],
82
- order: injectObj.args[2] || index
83
- };
84
- });
85
- // Views sort.
86
- hexo.theme.config.injects[type] = Object.values(configs)
87
- .sort((x, y) => x.order - y.order);
88
- });
89
- };
@@ -1,44 +0,0 @@
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 node_fs_1 = __importDefault(require("node:fs"));
7
- const node_path_1 = __importDefault(require("node:path"));
8
- const js_yaml_1 = __importDefault(require("js-yaml"));
9
- function linkGrid(args, content) {
10
- const theme = hexo.theme.config;
11
- if (!args[0] && !content) {
12
- return;
13
- }
14
- if (args[0]) {
15
- const filepath = node_path_1.default.join(hexo.source_dir, args[0]);
16
- if (node_fs_1.default.existsSync(filepath)) {
17
- content = node_fs_1.default.readFileSync(filepath, { encoding: 'utf-8' });
18
- }
19
- }
20
- if (!content) {
21
- return;
22
- }
23
- const list = js_yaml_1.default.load(content);
24
- let result = '';
25
- list.forEach((item) => {
26
- if (!item.url || !item.site) {
27
- return;
28
- }
29
- let item_image = item.image || theme.assets + '/404.png';
30
- if (!item_image.startsWith('//') && !item_image.startsWith('http')) {
31
- item_image = theme.statics + item_image;
32
- }
33
- item.color = item.color ? ` style="--block-color:${item.color};"` : '';
34
- result += `<div class="item" title="${item.owner || item.site}"${item.color}>`;
35
- result += `<a href="${item.url}" class="image" data-background-image="${item_image}"></a>
36
- <div class="info">
37
- <a href="${item.url}" class="title">${item.site}</a>
38
- <p class="desc">${item.desc || item.url}</p>
39
- </div></div>`;
40
- });
41
- return `<div class="links">${result}</div>`;
42
- }
43
- hexo.extend.tag.register('links', linkGrid, { ends: true });
44
- hexo.extend.tag.register('linksfile', linkGrid, { ends: false, async: true });
@@ -1,19 +0,0 @@
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
- /* global hexo */
7
- const js_yaml_1 = __importDefault(require("js-yaml"));
8
- function postMedia(args, content) {
9
- if (!args[0] || !content) {
10
- return;
11
- }
12
- const list = js_yaml_1.default.load(content);
13
- switch (args[0]) {
14
- case 'video':
15
- case 'audio':
16
- return `<div class="media-container"><div class="player" data-type="${args[0]}" data-src='${JSON.stringify(list)}'></div></div>`;
17
- }
18
- }
19
- hexo.extend.tag.register('media', postMedia, { ends: true });
package/scripts/utils.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getVendorLink = getVendorLink;
4
- function getVendorLink(hexo, source) {
5
- const VendorsCfg = hexo.theme.config.vendors;
6
- const tagIdx = source.indexOf('|');
7
- if (tagIdx !== -1) {
8
- return `${VendorsCfg.cdns[source.substring(0, tagIdx)]}/${source.substring(tagIdx + 1)}`;
9
- }
10
- else {
11
- return source;
12
- }
13
- }
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.walineRecentComments = exports.walinePageview = exports.walineComment = void 0;
4
- const globalVars_1 = require("../globals/globalVars");
5
- const client_1 = require("@waline/client");
6
- const vue_1 = require("vue");
7
- const walineComment = function () {
8
- (0, client_1.init)({
9
- el: '#comments',
10
- serverURL: globalVars_1.CONFIG.waline.serverURL,
11
- lang: globalVars_1.CONFIG.waline.lang,
12
- locale: globalVars_1.CONFIG.waline.locale,
13
- emoji: globalVars_1.CONFIG.waline.emoji,
14
- meta: globalVars_1.CONFIG.waline.meta,
15
- requiredMeta: globalVars_1.CONFIG.waline.requiredMeta,
16
- wordLimit: globalVars_1.CONFIG.waline.wordLimit,
17
- pageSize: globalVars_1.CONFIG.waline.pageSize,
18
- pageview: globalVars_1.CONFIG.waline.pageview,
19
- path: window.location.pathname,
20
- dark: 'html[data-theme="dark"]'
21
- });
22
- };
23
- exports.walineComment = walineComment;
24
- const walinePageview = function () {
25
- (0, client_1.pageviewCount)({
26
- serverURL: globalVars_1.CONFIG.waline.serverURL,
27
- path: window.location.pathname
28
- });
29
- };
30
- exports.walinePageview = walinePageview;
31
- const walineRecentComments = async function () {
32
- const root = shokax_siteURL.replace(/^(https?:\/\/)?[^/]*/, '');
33
- let items = [];
34
- const { comments } = await (0, client_1.RecentComments)({
35
- serverURL: globalVars_1.CONFIG.waline.serverURL.replace(/\/+$/, ''),
36
- count: 10
37
- });
38
- comments.forEach(function (item) {
39
- let cText = (item.orig.length > 50) ? item.orig.substring(0, 50) + '...' : item.orig;
40
- item.url = item.url.startsWith('/') ? item.url : '/' + item.url;
41
- const siteLink = item.url + '#' + item.objectId;
42
- items.push({
43
- href: siteLink,
44
- nick: item.nick,
45
- // @ts-ignore
46
- time: item.insertedAt.split('T').shift(),
47
- text: cText
48
- });
49
- });
50
- (0, vue_1.createApp)({
51
- data() {
52
- return {
53
- coms: items,
54
- root
55
- };
56
- }
57
- }).mount('#new-comment');
58
- };
59
- exports.walineRecentComments = walineRecentComments;
@@ -1,244 +0,0 @@
1
- "use strict";
2
- /* 边栏分区 */
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.menuActive = exports.goToCommentHandle = exports.goToBottomHandle = exports.backToTopHandle = exports.sidebarTOC = exports.sideBarTab = exports.sideBarToggleHandle = void 0;
28
- const globalVars_1 = require("../globals/globalVars");
29
- const tools_1 = require("../globals/tools");
30
- const anime_1 = require("../library/anime");
31
- const dom_1 = require("../library/dom");
32
- const proto_1 = __importStar(require("../library/proto"));
33
- (0, proto_1.default)();
34
- const sideBarToggleHandle = (event, force) => {
35
- if (globalVars_1.sideBar.hasClass('on')) {
36
- globalVars_1.sideBar.removeClass('on');
37
- globalVars_1.menuToggle.removeClass('close');
38
- if (force) {
39
- // @ts-ignore
40
- // noinspection JSConstantReassignment
41
- globalVars_1.sideBar.style = '';
42
- }
43
- else {
44
- (0, anime_1.transition)(globalVars_1.sideBar, 'slideRightOut');
45
- }
46
- }
47
- else {
48
- if (force) {
49
- // @ts-ignore
50
- // noinspection JSConstantReassignment
51
- globalVars_1.sideBar.style = '';
52
- }
53
- else {
54
- (0, anime_1.transition)(globalVars_1.sideBar, 'slideRightIn', () => {
55
- globalVars_1.sideBar.addClass('on');
56
- globalVars_1.menuToggle.addClass('close');
57
- });
58
- }
59
- }
60
- };
61
- exports.sideBarToggleHandle = sideBarToggleHandle;
62
- const sideBarTab = () => {
63
- const sideBarInner = (0, proto_1.child)(globalVars_1.sideBar, '.inner');
64
- if (globalVars_1.sideBar.child('.tab')) {
65
- sideBarInner.removeChild(globalVars_1.sideBar.child('.tab'));
66
- }
67
- const list = document.createElement('ul');
68
- let active = 'active';
69
- list.className = 'tab';
70
- ['contents', 'related', 'overview'].forEach((item) => {
71
- const element = globalVars_1.sideBar.child('.panel.' + item);
72
- if (element.innerHTML.trim().length < 1) {
73
- if (item === 'contents') {
74
- (0, proto_1.setDisplay)(globalVars_1.showContents, 'none');
75
- }
76
- return;
77
- }
78
- if (item === 'contents') {
79
- (0, proto_1.setDisplay)(globalVars_1.showContents, '');
80
- }
81
- const tab = document.createElement('li');
82
- const span = document.createElement('span');
83
- const text = document.createTextNode(element.getAttribute('data-title'));
84
- span.appendChild(text);
85
- tab.appendChild(span);
86
- tab.addClass(item + ' item');
87
- if (active) {
88
- element.addClass(active);
89
- tab.addClass(active);
90
- }
91
- else {
92
- element.removeClass('active');
93
- }
94
- tab.addEventListener('click', (event) => {
95
- const target = event.currentTarget;
96
- if (target.hasClass('active'))
97
- return;
98
- globalVars_1.sideBar.find('.tab .item').forEach((element) => {
99
- element.removeClass('active');
100
- });
101
- globalVars_1.sideBar.find('.panel').forEach((element) => {
102
- element.removeClass('active');
103
- });
104
- globalVars_1.sideBar.child('.panel.' + target.className.replace(' item', '')).addClass('active');
105
- target.addClass('active');
106
- });
107
- list.appendChild(tab);
108
- active = '';
109
- });
110
- if (list.childNodes.length > 1) {
111
- sideBarInner.insertBefore(list, sideBarInner.childNodes[0]);
112
- globalVars_1.sideBar.child('.panels').style.paddingTop = '';
113
- }
114
- else {
115
- globalVars_1.sideBar.child('.panels').style.paddingTop = '.625rem';
116
- }
117
- };
118
- exports.sideBarTab = sideBarTab;
119
- const sidebarTOC = () => {
120
- const activateNavByIndex = (index) => {
121
- const target = navItems[index];
122
- if (!target)
123
- return;
124
- if (target.hasClass('current')) {
125
- return;
126
- }
127
- dom_1.$dom.each('.toc .active', (element) => {
128
- element && element.removeClass('active current');
129
- });
130
- sections.forEach((element) => {
131
- element && element.removeClass('active');
132
- });
133
- target.addClass('active current');
134
- sections[index] && sections[index].addClass('active');
135
- let parent = target.parentNode;
136
- while (!parent.matches('.contents')) {
137
- if (parent.matches('li')) {
138
- parent.addClass('active');
139
- const t = (0, dom_1.$dom)(parent.child('a.toc-link').getAttribute('href'));
140
- if (t) {
141
- t.addClass('active');
142
- }
143
- }
144
- parent = parent.parentNode;
145
- }
146
- // Scrolling to center active TOC element if TOC content is taller than viewport.
147
- if (getComputedStyle(globalVars_1.sideBar).display !== 'none' && tocElement.hasClass('active')) {
148
- (0, anime_1.pageScroll)(tocElement, target.offsetTop - (tocElement.offsetHeight / 4));
149
- }
150
- };
151
- const navItems = dom_1.$dom.all('.contents li');
152
- if (navItems.length < 1) {
153
- return;
154
- }
155
- let sections = [...navItems];
156
- let activeLock = null;
157
- sections = sections.map((element, index) => {
158
- const link = element.child('a.toc-link');
159
- const anchor = (0, dom_1.$dom)(decodeURI(link.getAttribute('href')));
160
- if (!anchor)
161
- return null;
162
- const alink = anchor.child('a.anchor');
163
- const anchorScroll = (event) => {
164
- event.preventDefault();
165
- const target = (0, dom_1.$dom)(decodeURI(event.currentTarget.getAttribute('href')));
166
- activeLock = index;
167
- (0, anime_1.pageScroll)(target, null, () => {
168
- activateNavByIndex(index);
169
- activeLock = null;
170
- });
171
- };
172
- // TOC item animation navigate.
173
- link.addEventListener('click', anchorScroll);
174
- alink && alink.addEventListener('click', (event) => {
175
- anchorScroll(event);
176
- (0, tools_1.clipBoard)(globalVars_1.CONFIG.hostname + '/' + LOCAL.path + event.currentTarget.getAttribute('href'));
177
- });
178
- return anchor;
179
- });
180
- const tocElement = globalVars_1.sideBar.child('.contents.panel');
181
- const findIndex = (entries) => {
182
- let index = 0;
183
- let entry = entries[index];
184
- if (entry.boundingClientRect.top > 0) {
185
- index = sections.indexOf(entry.target);
186
- return index === 0 ? 0 : index - 1;
187
- }
188
- for (; index < entries.length; index++) {
189
- if (entries[index].boundingClientRect.top <= 0) {
190
- entry = entries[index];
191
- }
192
- else {
193
- return sections.indexOf(entry.target);
194
- }
195
- }
196
- return sections.indexOf(entry.target);
197
- };
198
- const createIntersectionObserver = () => {
199
- const observer = new IntersectionObserver((entries) => {
200
- const index = findIndex(entries) + (globalVars_1.diffY < 0 ? 1 : 0);
201
- if (activeLock === null) {
202
- activateNavByIndex(index);
203
- }
204
- }, {
205
- rootMargin: '0px 0px -100% 0px', threshold: 0
206
- });
207
- sections.forEach((element) => {
208
- element && observer.observe(element);
209
- });
210
- };
211
- createIntersectionObserver();
212
- };
213
- exports.sidebarTOC = sidebarTOC;
214
- const backToTopHandle = () => {
215
- (0, anime_1.pageScroll)(0);
216
- };
217
- exports.backToTopHandle = backToTopHandle;
218
- const goToBottomHandle = () => {
219
- (0, anime_1.pageScroll)(parseInt(String((0, proto_1.getHeight)(globalVars_1.Container))));
220
- };
221
- exports.goToBottomHandle = goToBottomHandle;
222
- const goToCommentHandle = () => {
223
- (0, anime_1.pageScroll)((0, dom_1.$dom)('#comments'));
224
- };
225
- exports.goToCommentHandle = goToCommentHandle;
226
- const menuActive = () => {
227
- dom_1.$dom.each('.menu .item:not(.title)', (element) => {
228
- const target = element.child('a[href]');
229
- const parentItem = element.parentNode.parentNode;
230
- if (!target)
231
- return;
232
- const isSamePath = target.pathname === location.pathname || target.pathname === location.pathname.replace('index.html', '');
233
- const isSubPath = !globalVars_1.CONFIG.root.startsWith(target.pathname) && location.pathname.startsWith(target.pathname);
234
- const active = target.hostname === location.hostname && (isSamePath || isSubPath);
235
- element.toggleClass('active', active);
236
- if (element.parentNode.child('.active') && parentItem.hasClass('dropdown')) {
237
- parentItem.removeClass('active').addClass('expand');
238
- }
239
- else {
240
- parentItem.removeClass('expand');
241
- }
242
- });
243
- };
244
- exports.menuActive = menuActive;
@@ -1,47 +0,0 @@
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
- exports.twikooRecentComments = exports.twikooComment = void 0;
7
- const twikoo_1 = __importDefault(require("twikoo"));
8
- const globalVars_1 = require("../globals/globalVars");
9
- const vue_1 = require("vue");
10
- const twikooComment = function () {
11
- twikoo_1.default.init({
12
- envId: globalVars_1.CONFIG.twikoo.envId,
13
- el: '#comments',
14
- region: globalVars_1.CONFIG.twikoo.region
15
- });
16
- };
17
- exports.twikooComment = twikooComment;
18
- const twikooRecentComments = async function () {
19
- let comments = [];
20
- const root = shokax_siteURL.replace(/^(https?:\/\/)?[^/]*/, '');
21
- const res = await twikoo_1.default.getRecentComments({
22
- envId: globalVars_1.CONFIG.twikoo.envId,
23
- pageSize: 10
24
- });
25
- res.forEach(function (item) {
26
- let cText = item.commentText;
27
- if (item.commentText.length > 50) {
28
- cText = item.commentText.substring(0, 50) + '...';
29
- }
30
- const siteLink = item.url + '#' + item.id;
31
- comments.push({
32
- href: siteLink,
33
- nick: item.nick,
34
- time: item.relativeTime,
35
- text: cText
36
- });
37
- });
38
- (0, vue_1.createApp)({
39
- data() {
40
- return {
41
- coms: comments,
42
- root
43
- };
44
- }
45
- }).mount('#new-comment');
46
- };
47
- exports.twikooRecentComments = twikooRecentComments;
@@ -1,105 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.visibilityListener = exports.scrollHandle = exports.resizeHandle = void 0;
4
- const sidebar_1 = require("../components/sidebar");
5
- const dom_1 = require("../library/dom");
6
- const globalVars_1 = require("./globalVars");
7
- const themeColor_1 = require("./themeColor");
8
- const thirdparty_1 = require("./thirdparty");
9
- const proto_1 = require("../library/proto");
10
- const resizeHandle = () => {
11
- // 获取 siteNav 的高度
12
- (0, globalVars_1.setSiteNavHeight)((0, proto_1.getHeight)(globalVars_1.siteNav));
13
- // 获取 siteHeader 的高度
14
- (0, globalVars_1.setHeaderHightInner)((0, proto_1.getHeight)(globalVars_1.siteHeader));
15
- // 获取 #waves 的高度
16
- (0, globalVars_1.setHeaderHight)(globalVars_1.headerHightInner + (0, proto_1.getHeight)((0, dom_1.$dom)('#waves')));
17
- // 判断窗口宽度是否改变
18
- if (globalVars_1.oWinWidth !== window.innerWidth) {
19
- (0, sidebar_1.sideBarToggleHandle)(null, 1);
20
- }
21
- // 记录窗口高度和宽度
22
- (0, globalVars_1.setOWinHeight)(window.innerHeight);
23
- (0, globalVars_1.setOWinWidth)(window.innerWidth);
24
- };
25
- exports.resizeHandle = resizeHandle;
26
- const scrollHandle = () => {
27
- // 获取窗口高度
28
- const winHeight = window.innerHeight;
29
- // 获取文档高度
30
- const docHeight = (0, dom_1.getDocHeight)();
31
- // 计算可见内容高度
32
- const contentVisibilityHeight = docHeight > winHeight ? docHeight - winHeight : document.body.scrollHeight - winHeight;
33
- // 判断页面是否滚动超过 headerHightInner
34
- const SHOW = window.scrollY > globalVars_1.headerHightInner;
35
- // 判断页面是否开始滚动
36
- const startScroll = window.scrollY > 0;
37
- // 根据条件修改 meta theme
38
- if (SHOW) {
39
- (0, themeColor_1.changeMetaTheme)('#FFF');
40
- }
41
- else {
42
- (0, themeColor_1.changeMetaTheme)('#222');
43
- }
44
- // 控制导航栏的显示隐藏
45
- globalVars_1.siteNav.toggleClass('show', SHOW);
46
- // 控制网站 logo 的显示隐藏
47
- globalVars_1.toolBtn.toggleClass('affix', startScroll);
48
- // 控制侧边栏的显示隐藏,当滚动高度大于 headerHight 且窗口宽度大于 991px 时显示
49
- globalVars_1.siteBrand.toggleClass('affix', startScroll);
50
- globalVars_1.sideBar.toggleClass('affix', window.scrollY > globalVars_1.headerHight && document.body.offsetWidth > 991);
51
- // 初始化滚动时导航栏的显示方向
52
- if (typeof globalVars_1.scrollAction.y === 'undefined') {
53
- globalVars_1.scrollAction.y = window.scrollY;
54
- }
55
- (0, globalVars_1.setDiffY)(globalVars_1.scrollAction.y - window.scrollY);
56
- // 控制滑动时导航栏显示
57
- if (globalVars_1.diffY < 0) {
58
- globalVars_1.siteNav.removeClass('up');
59
- globalVars_1.siteNav.toggleClass('down', SHOW);
60
- }
61
- else if (globalVars_1.diffY > 0) {
62
- globalVars_1.siteNav.removeClass('down');
63
- globalVars_1.siteNav.toggleClass('up', SHOW);
64
- }
65
- else { /* empty */ }
66
- globalVars_1.scrollAction.y = window.scrollY;
67
- // 计算滚动百分比
68
- const scrollPercent = Math.round(Math.min(100 * window.scrollY / contentVisibilityHeight, 100)) + '%';
69
- // 更新回到顶部按钮的文字
70
- if (globalVars_1.backToTop.child('span').innerText !== scrollPercent) {
71
- globalVars_1.backToTop.child('span').innerText = scrollPercent;
72
- }
73
- // 更新百分比进度条的宽度
74
- if ((0, dom_1.$dom)('#sidebar').hasClass('affix') || (0, dom_1.$dom)('#sidebar').hasClass('on')) {
75
- (0, proto_1.setWidth)((0, dom_1.$dom)('.percent'), scrollPercent);
76
- }
77
- };
78
- exports.scrollHandle = scrollHandle;
79
- // 可见度监听(离开页面和返回时更改document的title)
80
- const visibilityListener = () => {
81
- const iconNode = (0, dom_1.$dom)('[rel="icon"]');
82
- document.addEventListener('visibilitychange', () => {
83
- switch (document.visibilityState) {
84
- case 'hidden':
85
- iconNode.setAttribute('href', globalVars_1.statics + globalVars_1.CONFIG.favicon.hidden);
86
- document.title = LOCAL.favicon.hide;
87
- if (globalVars_1.CONFIG.loader.switch) {
88
- thirdparty_1.Loader.show();
89
- }
90
- clearTimeout(globalVars_1.titleTime);
91
- break;
92
- case 'visible':
93
- iconNode.setAttribute('href', globalVars_1.statics + globalVars_1.CONFIG.favicon.normal);
94
- document.title = LOCAL.favicon.show;
95
- if (globalVars_1.CONFIG.loader.switch) {
96
- thirdparty_1.Loader.hide(1000);
97
- }
98
- (0, globalVars_1.setTitleTime)(setTimeout(() => {
99
- document.title = globalVars_1.originTitle;
100
- }, 2000));
101
- break;
102
- }
103
- }, { passive: true });
104
- };
105
- exports.visibilityListener = visibilityListener;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.vendorCss = exports.vendorJs = void 0;
4
- const scriptPjax_1 = require("./scriptPjax");
5
- const globalVars_1 = require("../globals/globalVars");
6
- const proto_1 = require("./proto");
7
- /**
8
- * 用途是根据不同的资源名称和类型生成相应的资源 URL。
9
- */
10
- const assetUrl = (asset, type) => {
11
- const str = globalVars_1.CONFIG[asset][type];
12
- if (str.includes('http')) {
13
- return str;
14
- }
15
- if (str.includes('gh') || str.includes('combine')) {
16
- return `https://cdn.jsdelivr.net/${str}`;
17
- }
18
- if (str.includes('npm')) {
19
- return `https://cdn.jsdelivr.net/${str}`;
20
- }
21
- return `/${str}`;
22
- };
23
- const vendorJs = (type, callback, condition) => {
24
- if (LOCAL[type]) {
25
- (0, scriptPjax_1.getScript)(assetUrl('js', type), callback || function () {
26
- window[type] = true;
27
- }, condition || window[type]);
28
- }
29
- };
30
- exports.vendorJs = vendorJs;
31
- const vendorCss = (type, condition) => {
32
- if (window['css' + type]) {
33
- return;
34
- }
35
- if (LOCAL[type]) {
36
- (0, proto_1.createChild)(document.head, 'link', {
37
- rel: 'stylesheet',
38
- href: assetUrl('css', type)
39
- });
40
- window['css' + type] = true;
41
- }
42
- };
43
- exports.vendorCss = vendorCss;