hexo-theme-shokax 0.4.0-alpha.3 → 0.4.0-beta.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -2
- package/_config.yml +11 -2
- package/languages/README.md +0 -22
- package/layout/_mixin/segment.pug +5 -2
- package/layout/_partials/footer.pug +1 -1
- package/layout/_partials/head/head.pug +3 -8
- package/layout/_partials/header.pug +1 -1
- package/layout/_partials/layout.pug +11 -9
- package/layout/_partials/post/post.pug +1 -1
- package/layout/_partials/sidebar/overview.pug +2 -2
- package/layout/index.pug +2 -2
- package/package.json +1 -1
- package/scripts/generaters/script.js +2 -4
- package/scripts/helpers/asset.js +3 -3
- package/scripts/helpers/engine.js +15 -1
- package/scripts/plugin/index.js +1 -0
- package/source/css/_common/outline/sidebar/sidebar.styl +5 -0
- package/source/css/_common/scaffolding/base.styl +6 -6
- package/source/js/_app/components/comments.ts +0 -3
- package/source/js/_app/globals/handles.ts +2 -2
- package/source/js/_app/page/search.ts +0 -20
- package/source/js/_app/pjax/domInit.ts +1 -0
- package/source/js/_app/pjax/refresh.ts +56 -12
- package/source/js/_app/pjax/siteInit.ts +41 -10
- package/languages/ar.yml +0 -153
- package/languages/de.yml +0 -153
- package/languages/es.yml +0 -153
- package/languages/fr.yml +0 -153
- package/languages/hi.yml +0 -153
- package/languages/id.yml +0 -153
- package/languages/it.yml +0 -153
- package/languages/ko.yml +0 -153
- package/languages/nl.yml +0 -153
- package/languages/pl.yml +0 -153
- package/languages/pt.yml +0 -153
- package/languages/ru.yml +0 -153
- package/languages/tr.yml +0 -153
- package/languages/vi.yml +0 -153
- package/source/css/comment.styl +0 -3
package/README.md
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# 📣 公告
|
2
|
-
[关于ShokaX
|
3
|
-
[关于删除部分评论系统的讨论](https://github.com/theme-shoka-x/hexo-theme-shokaX/discussions/175)
|
2
|
+
[关于 ShokaX 部署平台和 Astro 迁移的调查](https://github.com/theme-shoka-x/hexo-theme-shokaX/discussions/229)
|
4
3
|
|
5
4
|
# hexo-theme-shokaX
|
6
5
|
![LICENSE]( https://img.shields.io/github/license/theme-shoka-x/hexo-theme-shokaX)
|
package/_config.yml
CHANGED
@@ -21,8 +21,6 @@ pwa:
|
|
21
21
|
|
22
22
|
# 实验性特性
|
23
23
|
experiments:
|
24
|
-
gradient: false # 使用CSS渐变作为文章封面
|
25
|
-
fixedCover: "" # 主页面cover(为空则使用bing随机图片)
|
26
24
|
debug: false # 使用debug模式启动
|
27
25
|
disableThemeComment: false # 禁用主题评论系统(一般用于关闭评论或让插件接管评论系统)
|
28
26
|
usingRelative: false # _image.yml 使用相对路径
|
@@ -30,6 +28,11 @@ experiments:
|
|
30
28
|
# 具体见https://docs.kaitaku.xyz/guide/theme.html#%E9%95%BF%E6%96%87%E7%AB%A0%E4%BC%98%E5%8C%96
|
31
29
|
mobileWidth: 820px # 移动版和桌面版导航栏最短切换长度
|
32
30
|
|
31
|
+
homeConfig:
|
32
|
+
gradient: false # 使用CSS渐变作为文章封面
|
33
|
+
# fixedCover 性能比默认的更好,且开启时将启用LCP优化和预加载 TODO
|
34
|
+
fixedCover: "" # 主页面cover(为空则使用bing随机图片)
|
35
|
+
|
33
36
|
# ShokaX 模块化分包引入设置
|
34
37
|
# 请关闭所有不使用的模块以优化主题 js 体积和性能
|
35
38
|
modules:
|
@@ -41,11 +44,17 @@ modules:
|
|
41
44
|
quiz: true # 启用文章内问题扩展支持
|
42
45
|
fancybox: true # 启用 fancybox 支持(不建议禁用)
|
43
46
|
|
47
|
+
styles:
|
48
|
+
postprocess: true # 启用后处理器
|
49
|
+
modules:
|
50
|
+
mermaid: false
|
51
|
+
|
44
52
|
# 优化性能区
|
45
53
|
performance:
|
46
54
|
# 使用preconnect预加载的网址(不建议超过三个)
|
47
55
|
preConnect:
|
48
56
|
- "https://lf9-cdn-tos.bytecdntp.com"
|
57
|
+
- "https://at.alicdn.com"
|
49
58
|
# 使用dns-prefetch预解析的网址
|
50
59
|
dnsPrefetch:
|
51
60
|
|
package/languages/README.md
CHANGED
@@ -17,25 +17,3 @@ If you would like to customize the default translation, you do not need to modif
|
|
17
17
|
menu:
|
18
18
|
schedule: Calendar
|
19
19
|
```
|
20
|
-
|
21
|
-
# Current language packs
|
22
|
-
|
23
|
-
- ### English (en)
|
24
|
-
- ### 日本語 (ja)
|
25
|
-
- ### 中文-简体 (zh-CN)
|
26
|
-
- ### 中文-繁体 (zh-HK)
|
27
|
-
- ### 中文-台湾 (zh-TW)
|
28
|
-
- ### Español (es)
|
29
|
-
- ### Deutsch (de)
|
30
|
-
- ### Français (fr)
|
31
|
-
- ### Italiano (it)
|
32
|
-
- ### Português (pt)
|
33
|
-
- ### Русский (ru)
|
34
|
-
- ### العربية (ar)
|
35
|
-
- ### हिंदी (hi)
|
36
|
-
- ### 한국어 (ko)
|
37
|
-
- ### Nederlands (nl)
|
38
|
-
- ### Polski (pl)
|
39
|
-
- ### Türkçe (tr)
|
40
|
-
- ### Bahasa Indonesia (id)
|
41
|
-
- ### Tiếng Việt (vi)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
include postmeta.pug
|
2
2
|
|
3
|
-
mixin SMRender(item)
|
3
|
+
mixin SMRender(item, lazy)
|
4
4
|
- var link1 = item.link || item.path
|
5
5
|
- var gradient = theme?.experiments?.gradient
|
6
6
|
if item.link
|
@@ -11,7 +11,10 @@ mixin SMRender(item)
|
|
11
11
|
div(class="cover" style=`background: linear-gradient(to bottom right, ${random_color()}, ${random_color()});`)
|
12
12
|
else
|
13
13
|
div(class="cover")
|
14
|
-
|
14
|
+
if lazy
|
15
|
+
!= _url(link1, '<img loading="lazy" decoding="async" data-src="'+ _cover(item) +'" alt="article cover">', {itemprop: 'url', title: postText})
|
16
|
+
else
|
17
|
+
!= _url(link1, '<img loading="eager" decoding="async" src="'+ _cover(item) +'" alt="article cover">', {itemprop: 'url', title: postText})
|
15
18
|
div(class="info")
|
16
19
|
+PMRender(item)
|
17
20
|
h3
|
@@ -34,7 +34,7 @@ div(class="status")
|
|
34
34
|
if beianN && RC
|
35
35
|
br
|
36
36
|
a(target="_blank" href=`https://beian.mps.gov.cn/#/query/webSearch?code=${RC}`)
|
37
|
-
img(src=theme.statics + theme.assets + '/' + theme.footer.icp.icon style="max-width: 2em;display:inline;" width="20" height="20")
|
37
|
+
img(loading="lazy" decoding="async" data-src=theme.statics + theme.assets + '/' + theme.footer.icp.icon style="max-width: 2em;display:inline;" width="20" height="20")
|
38
38
|
!= beianN
|
39
39
|
!= shokax_inject('status')
|
40
40
|
|
@@ -42,16 +42,11 @@ each dnsLink in dnslinks
|
|
42
42
|
if fontConfig
|
43
43
|
!= _vendor_font()
|
44
44
|
!= _css('app.css')
|
45
|
-
|
46
|
-
if theme.polyfill.enable
|
47
|
-
script(src=`https://polyfill.io/v3/polyfill.min.js?features=${theme.polyfill.features}` defer)
|
48
|
-
|
49
|
-
!= vendor_js()
|
50
|
-
!= _js('siteInit.js')
|
45
|
+
!= preloadjs()
|
51
46
|
|
52
47
|
include pwa.pug
|
53
|
-
|
54
|
-
link(rel="stylesheet" href="https://npm.webcache.cn/@waline/client@
|
48
|
+
if wl
|
49
|
+
link(rel="stylesheet" href="https://npm.webcache.cn/@waline/client@3.0.0-alpha.11/dist/waline.css" media="none" onload="this.media='all'")
|
55
50
|
|
56
51
|
- var qw = theme?.qweather?.enable
|
57
52
|
if qw
|
@@ -10,7 +10,7 @@ nav(id="nav")
|
|
10
10
|
a(href=config.root rel="start")
|
11
11
|
!= alternate || title
|
12
12
|
ul(class="right" id="rightNav")
|
13
|
-
li(class="item theme"
|
13
|
+
li(class="item theme")
|
14
14
|
i(class="ic i-sun")
|
15
15
|
li(class="item search")
|
16
16
|
i(class="ic i-search")
|
@@ -35,18 +35,18 @@ html(lang=page.language?page.language:config.language, style=theme.grayMode ? 'f
|
|
35
35
|
|
36
36
|
!= partial('_partials/header.pug', {}, {cache: true})
|
37
37
|
div(id="imgs" class="pjax")
|
38
|
-
if theme.
|
38
|
+
if theme.homeConfig.gradient || theme.homeConfig.fixedCover
|
39
39
|
//- cover不可用时用Bing随机图片代替
|
40
|
-
- var coverImage = theme.
|
41
|
-
img(src=coverImage)
|
40
|
+
- var coverImage = theme.homeConfig.fixedCover || "https://7ed.net/bing/api"
|
41
|
+
img(src=coverImage loading="eager" decoding="async" fetchpriority="high")
|
42
42
|
else
|
43
43
|
- var covers = _cover_index(page, 6)
|
44
44
|
if covers.length === 6
|
45
45
|
ul
|
46
46
|
each image in covers
|
47
|
-
li(class="item"
|
47
|
+
li(class="item" style=`background-image: url("${image}");`)
|
48
48
|
else
|
49
|
-
img(src=covers)
|
49
|
+
img(src=covers loading="eager" decoding="async" fetchpriority="high")
|
50
50
|
div(id="waves")
|
51
51
|
svg(class="waves" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto")
|
52
52
|
defs
|
@@ -119,10 +119,12 @@ html(lang=page.language?page.language:config.language, style=theme.grayMode ? 'f
|
|
119
119
|
!= partial('_partials/third-party/baidu-analytics.pug', {}, {cache: true})
|
120
120
|
!= partial('_partials/third-party/clarity.pug', {}, {cache: true})
|
121
121
|
!= partial('_partials/third-party/google-analytics.pug', {}, {cache: true})
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
122
|
+
|
123
|
+
!= vendor_js()
|
124
|
+
if theme.polyfill.enable
|
125
|
+
script(src=`https://polyfill.io/v3/polyfill.min.js?features=${theme.polyfill.features}` defer)
|
126
|
+
|
127
|
+
!= _js('siteInit.js')
|
126
128
|
|
127
129
|
!= shokax_inject('bodyEnd')
|
128
130
|
|
@@ -11,7 +11,7 @@ article(itemscope itemtype="http://schema.org/Article" class="post block" lang=t
|
|
11
11
|
if post.photos && post.photos.length
|
12
12
|
div(class="gallery" itemscope itemtype="http://schema.org/ImageGallery")
|
13
13
|
each photo in post.photos
|
14
|
-
img(loading="lazy" data-src=_image_url(photo, post.path) itemprop="contentUrl")
|
14
|
+
img(loading="lazy" decoding="async" data-src=_image_url(photo, post.path) itemprop="contentUrl")
|
15
15
|
if theme.summary.enable && page.layout === 'post'
|
16
16
|
div(class='tabs' id='summary')
|
17
17
|
div(class="show-btn")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
div(class="author" itemprop="author" itemscope itemtype="http://schema.org/Person")
|
2
|
-
img(loading="
|
3
|
-
|
2
|
+
img(loading="eager" decoding="async" class="image" itemprop="image" alt=author
|
3
|
+
src=url_for(theme.statics + theme.assets + '/'+ theme.sidebar.avatar))
|
4
4
|
p(class="name" itemprop="name")
|
5
5
|
!= author
|
6
6
|
div(class="description" itemprop="description")
|
package/layout/index.pug
CHANGED
@@ -12,7 +12,7 @@ block content
|
|
12
12
|
- var sticky = page.sticky.toArray()
|
13
13
|
div(class="segments sticky")
|
14
14
|
each post in sticky
|
15
|
-
+SMRender(post)
|
15
|
+
+SMRender(post, false)
|
16
16
|
if page.catlist.length > 0
|
17
17
|
h2(class="divider")
|
18
18
|
!= __('index.category')
|
@@ -27,7 +27,7 @@ block content
|
|
27
27
|
!= __('index.posts')
|
28
28
|
div(class="segments posts")
|
29
29
|
each post in posts
|
30
|
-
+SMRender(post)
|
30
|
+
+SMRender(post, true)
|
31
31
|
include _partials/pagination.pug
|
32
32
|
|
33
33
|
|
package/package.json
CHANGED
@@ -62,7 +62,7 @@ hexo.extend.generator.register('script', function (locals) {
|
|
62
62
|
twikoo: {
|
63
63
|
envId: theme.twikoo.envId,
|
64
64
|
region: theme.twikoo.region
|
65
|
-
}
|
65
|
+
}
|
66
66
|
};
|
67
67
|
if (config?.algolia) {
|
68
68
|
siteConfig.search = {
|
@@ -100,7 +100,7 @@ hexo.extend.generator.register('script', function (locals) {
|
|
100
100
|
target: ['es2022'],
|
101
101
|
minify: true,
|
102
102
|
legalComments: 'linked',
|
103
|
-
mainFields: ['module', 'main'],
|
103
|
+
mainFields: ['module', 'browser', 'main'],
|
104
104
|
splitting: true,
|
105
105
|
define: {
|
106
106
|
__UNLAZY_LOGGING__: 'false',
|
@@ -151,8 +151,6 @@ hexo.extend.generator.register('script', function (locals) {
|
|
151
151
|
}
|
152
152
|
});
|
153
153
|
}
|
154
|
-
node_fs_1.default.unlinkSync(`./shokaxTemp/${file}`);
|
155
154
|
});
|
156
|
-
node_fs_1.default.rmSync('./shokaxTemp', { force: true, recursive: true });
|
157
155
|
return res;
|
158
156
|
});
|
package/scripts/helpers/asset.js
CHANGED
@@ -53,17 +53,17 @@ hexo.extend.helper.register('_css', function (...urls) {
|
|
53
53
|
return urls.map(url => (0, hexo_util_1.htmlTag)('link', {
|
54
54
|
rel: 'stylesheet',
|
55
55
|
href: hexo_util_1.url_for.call(this, `${statics}${css}/${url}?v=${package_json_1.default.version}`)
|
56
|
-
})).join('');
|
56
|
+
}), '').join('');
|
57
57
|
});
|
58
58
|
hexo.extend.helper.register('_js', function (...urls) {
|
59
59
|
const { statics, js } = hexo.theme.config;
|
60
|
-
return urls.map(url => (0, hexo_util_1.htmlTag)('script', { src: hexo_util_1.url_for.call(this, `${statics}${js}/${url}?v=${package_json_1.default.version}`), type: 'module', fetchpriority: 'high' }, '')).join('');
|
60
|
+
return urls.map(url => (0, hexo_util_1.htmlTag)('script', { src: hexo_util_1.url_for.call(this, `${statics}${js}/${url}?v=${package_json_1.default.version}`), type: 'module', fetchpriority: 'high', defer: true }, '')).join('');
|
61
61
|
});
|
62
62
|
hexo.extend.helper.register('vendor_js', function () {
|
63
63
|
const vendors = hexo.theme.config.vendors;
|
64
64
|
let res = '';
|
65
65
|
for (const jsSync in vendors.js) {
|
66
|
-
res += (0, hexo_util_1.htmlTag)('script', { src: (0, utils_1.getVendorLink)(hexo, vendors.js[jsSync]) }, '');
|
66
|
+
res += (0, hexo_util_1.htmlTag)('script', { src: (0, utils_1.getVendorLink)(hexo, vendors.js[jsSync]), async: true }, '');
|
67
67
|
}
|
68
68
|
// for (const jsAsync in vendors.async_js) {
|
69
69
|
// res += htmlTag('script', { src: getVendorLink(hexo, vendors.async_js[jsAsync]), async: true }, '')
|
@@ -1,7 +1,11 @@
|
|
1
1
|
'use strict';
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
6
|
// @ts-ignore
|
4
7
|
const hexo_util_1 = require("hexo-util");
|
8
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
5
9
|
const randomServer = parseInt(String(Math.random() * 4), 10) + 1;
|
6
10
|
const randomBG = function (count = 1, image_server = null, image_list = []) {
|
7
11
|
let i;
|
@@ -48,6 +52,16 @@ const randomBG = function (count = 1, image_server = null, image_list = []) {
|
|
48
52
|
}
|
49
53
|
return parseImage(image_list[Math.floor(Math.random() * image_list.length)], 'mw690');
|
50
54
|
};
|
55
|
+
hexo.extend.helper.register('preloadjs', function () {
|
56
|
+
const { statics, js } = hexo.theme.config;
|
57
|
+
let res = '';
|
58
|
+
node_fs_1.default.readdirSync('./shokaxTemp').forEach((file) => {
|
59
|
+
if (file.endsWith('.js')) {
|
60
|
+
res += (0, hexo_util_1.htmlTag)('link', { rel: 'modulepreload', href: hexo_util_1.url_for.call(this, `${statics}${js}/${file}`) }, '');
|
61
|
+
}
|
62
|
+
});
|
63
|
+
return res;
|
64
|
+
});
|
51
65
|
// 注册hexo主题中的URL帮助方法
|
52
66
|
hexo.extend.helper.register('_url', function (path, text, options = {}) {
|
53
67
|
// 如果未提供URL路径,则返回
|
@@ -96,7 +110,7 @@ hexo.extend.helper.register('_cover_index', function (item) {
|
|
96
110
|
return this._image_url(item.photos[0], item.path);
|
97
111
|
}
|
98
112
|
else {
|
99
|
-
return randomBG(
|
113
|
+
return randomBG(6, image_server, index_images.length === 0 ? image_list : index_images);
|
100
114
|
}
|
101
115
|
});
|
102
116
|
// 注册hexo主题的永久链接帮助方法
|
package/scripts/plugin/index.js
CHANGED
@@ -37,6 +37,7 @@ const fs = __importStar(require("node:fs"));
|
|
37
37
|
hexo.on('generateBefore', () => {
|
38
38
|
// 加载`theme_injects`过滤器
|
39
39
|
(0, injects_1.default)(hexo);
|
40
|
+
fs.rmSync('./shokaxTemp', { force: true, recursive: true });
|
40
41
|
if (fs.existsSync('request.lock')) {
|
41
42
|
fs.unlinkSync('request.lock');
|
42
43
|
}
|
@@ -44,12 +44,17 @@
|
|
44
44
|
overflow: hidden;
|
45
45
|
|
46
46
|
.inner {
|
47
|
+
margin-top: 2.5rem;
|
47
48
|
overflow-x: hidden;
|
48
49
|
overflow-y: auto;
|
49
50
|
-webkit-overflow-scrolling: touch;
|
50
51
|
width: auto;
|
51
52
|
height: 100%;
|
52
53
|
|
54
|
+
+tablet-mobile() {
|
55
|
+
margin-top: 0;
|
56
|
+
}
|
57
|
+
|
53
58
|
&::-webkit-scrollbar {
|
54
59
|
display: none;
|
55
60
|
}
|
@@ -149,12 +149,12 @@ input, textarea {
|
|
149
149
|
@font-face {
|
150
150
|
font-family: 'ic';
|
151
151
|
font-display: swap;
|
152
|
-
src: url('
|
153
|
-
src: url('
|
154
|
-
url('
|
155
|
-
url('
|
156
|
-
url('
|
157
|
-
url('
|
152
|
+
src: url('https://at.alicdn.com/t/c/font_' + $iconfont + '.eot');
|
153
|
+
src: url('https://at.alicdn.com/t/c/font_' + $iconfont + '.eot?#iefix') format('embedded-opentype'),
|
154
|
+
url('https://at.alicdn.com/t/c/font_' + $iconfont + '.woff2') format('woff2'),
|
155
|
+
url('https://at.alicdn.com/t/c/font_' + $iconfont + '.woff') format('woff'),
|
156
|
+
url('https://at.alicdn.com/t/c/font_' + $iconfont + '.ttf') format('truetype'),
|
157
|
+
url('https://at.alicdn.com/t/c/font_' + $iconfont + '.svg#ic') format('svg');
|
158
158
|
}
|
159
159
|
|
160
160
|
@font-face {
|
@@ -22,7 +22,7 @@ import {
|
|
22
22
|
} from './globalVars'
|
23
23
|
import { changeMetaTheme } from './themeColor'
|
24
24
|
import { Loader } from './thirdparty'
|
25
|
-
import {getHeight, setWidth} from '../library/proto'
|
25
|
+
import { getHeight, setWidth } from '../library/proto'
|
26
26
|
|
27
27
|
export const resizeHandle = () => {
|
28
28
|
// 获取 siteNav 的高度
|
@@ -119,5 +119,5 @@ export const visibilityListener = () => {
|
|
119
119
|
}, 2000))
|
120
120
|
break
|
121
121
|
}
|
122
|
-
})
|
122
|
+
}, { passive: true })
|
123
123
|
}
|
@@ -5,18 +5,8 @@ import { searchBox, configure, stats, hits, pagination } from 'instantsearch.js/
|
|
5
5
|
import type { HitHighlightResult } from 'instantsearch.js/es/types/results'
|
6
6
|
import instantsearch from 'instantsearch.js'
|
7
7
|
import algoliasearch from 'algoliasearch/lite'
|
8
|
-
import {createChild} from "../library/proto";
|
9
8
|
|
10
9
|
export function algoliaSearch (pjax) {
|
11
|
-
if (CONFIG.search === null) { return }
|
12
|
-
|
13
|
-
if (!siteSearch) {
|
14
|
-
setSiteSearch(createChild(BODY, 'div', {
|
15
|
-
id: 'search',
|
16
|
-
innerHTML: '<div class="inner"><div class="header"><span class="icon"><i class="ic i-search"></i></span><div class="search-input-container"></div><span class="close-btn"><i class="ic i-times-circle"></i></span></div><div class="results"><div class="inner"><div id="search-stats"></div><div id="search-hits"></div><div id="search-pagination"></div></div></div></div>'
|
17
|
-
}))
|
18
|
-
}
|
19
|
-
|
20
10
|
const search = instantsearch({
|
21
11
|
indexName: CONFIG.search.indexName,
|
22
12
|
searchClient: algoliasearch(CONFIG.search.appID, CONFIG.search.apiKey),
|
@@ -104,16 +94,6 @@ export function algoliaSearch (pjax) {
|
|
104
94
|
|
105
95
|
search.start()
|
106
96
|
|
107
|
-
// Handle and trigger popup window
|
108
|
-
$dom.each('.search', (element) => {
|
109
|
-
element.addEventListener('click', () => {
|
110
|
-
document.body.style.overflow = 'hidden'
|
111
|
-
transition(siteSearch, 'shrinkIn', () => {
|
112
|
-
$dom('.search-input').focus()
|
113
|
-
}) // transition.shrinkIn
|
114
|
-
})
|
115
|
-
})
|
116
|
-
|
117
97
|
// Monitor main search box
|
118
98
|
const onPopupClose = () => {
|
119
99
|
document.body.style.overflow = ''
|
@@ -16,6 +16,7 @@ import { pagePosition, positionInit } from '../globals/tools'
|
|
16
16
|
import { menuActive, sideBarTab, sidebarTOC } from '../components/sidebar'
|
17
17
|
import { Loader, isOutime } from '../globals/thirdparty'
|
18
18
|
import { tabFormat } from '../page/tab'
|
19
|
+
import { lazyLoad } from 'unlazy'
|
19
20
|
|
20
21
|
export const pjaxReload = () => {
|
21
22
|
pagePosition()
|
@@ -40,6 +41,24 @@ export const siteRefresh = (reload) => {
|
|
40
41
|
vendorJs('copy_tex')
|
41
42
|
vendorCss('mermaid')
|
42
43
|
|
44
|
+
// 懒加载背景图
|
45
|
+
const lazyBg = new IntersectionObserver(function (entries, observer) {
|
46
|
+
entries.forEach(entry => {
|
47
|
+
if (entry.isIntersecting) {
|
48
|
+
const el = entry.target as HTMLElement
|
49
|
+
el.style.backgroundImage = `url("${el.getAttribute('data-background-image')}")`
|
50
|
+
el.removeAttribute('data-background-image')
|
51
|
+
observer.unobserve(el)
|
52
|
+
}
|
53
|
+
})
|
54
|
+
}, {
|
55
|
+
root: null,
|
56
|
+
threshold: 0.2
|
57
|
+
})
|
58
|
+
document.querySelectorAll('[data-background-image]').forEach(el => {
|
59
|
+
lazyBg.observe(el)
|
60
|
+
})
|
61
|
+
|
43
62
|
if (reload !== 1) {
|
44
63
|
$dom.each('script[data-pjax]', pjaxScript)
|
45
64
|
}
|
@@ -53,21 +72,46 @@ export const siteRefresh = (reload) => {
|
|
53
72
|
sideBarTab()
|
54
73
|
sidebarTOC()
|
55
74
|
|
56
|
-
|
57
|
-
|
58
|
-
|
75
|
+
if (LOCAL.ispost) {
|
76
|
+
import('../page/post').then(({ postBeauty }) => {
|
77
|
+
postBeauty()
|
78
|
+
})
|
79
|
+
|
80
|
+
const comment = new IntersectionObserver((entries) => {
|
81
|
+
entries.forEach((entry) => {
|
82
|
+
if (entry.isIntersecting) {
|
83
|
+
if (__shokax_waline__) {
|
84
|
+
import('../components/comments').then(({ walinePageview, walineComment }) => {
|
85
|
+
walinePageview()
|
86
|
+
walineComment()
|
87
|
+
})
|
88
|
+
}
|
89
|
+
if (__shokax_twikoo__) {
|
90
|
+
import('../components/tcomments').then(({ twikooComment }) => {
|
91
|
+
twikooComment()
|
92
|
+
})
|
93
|
+
}
|
94
|
+
comment.disconnect()
|
95
|
+
}
|
96
|
+
})
|
97
|
+
}, {
|
98
|
+
root: null,
|
99
|
+
threshold: 0.2
|
100
|
+
})
|
101
|
+
|
102
|
+
comment.observe($dom('#copyright'))
|
103
|
+
}
|
104
|
+
|
105
|
+
lazyLoad()
|
59
106
|
|
60
|
-
if (__shokax_waline__
|
61
|
-
import('../components/comments').then(async ({
|
62
|
-
walineComment()
|
63
|
-
walinePageview()
|
107
|
+
if (__shokax_waline__) {
|
108
|
+
import('../components/comments').then(async ({ walinePageview, walineRecentComments }) => {
|
64
109
|
await walineRecentComments()
|
65
110
|
})
|
66
111
|
}
|
67
112
|
|
68
|
-
if (__shokax_twikoo__
|
69
|
-
import('../components/tcomments').then(async ({
|
70
|
-
twikooComment()
|
113
|
+
if (__shokax_twikoo__) {
|
114
|
+
import('../components/tcomments').then(async ({ twikooRecentComments }) => {
|
71
115
|
await twikooRecentComments()
|
72
116
|
})
|
73
117
|
}
|
@@ -79,7 +123,7 @@ export const siteRefresh = (reload) => {
|
|
79
123
|
if (__shokax_player__) {
|
80
124
|
toolPlayer.player.load(LOCAL.audio || CONFIG.audio || {})
|
81
125
|
}
|
82
|
-
Loader.hide()
|
126
|
+
Loader.hide(500)
|
83
127
|
|
84
128
|
setTimeout(() => {
|
85
129
|
positionInit()
|
@@ -87,7 +131,7 @@ export const siteRefresh = (reload) => {
|
|
87
131
|
|
88
132
|
cardActive()
|
89
133
|
|
90
|
-
if (__shokax_outime__) {
|
134
|
+
if (__shokax_outime__ && LOCAL.ispost) {
|
91
135
|
isOutime()
|
92
136
|
}
|
93
137
|
}
|
@@ -1,13 +1,15 @@
|
|
1
1
|
import domInit from './domInit'
|
2
2
|
import { pjaxReload, siteRefresh } from './refresh'
|
3
3
|
import { cloudflareInit } from '../library/scriptPjax'
|
4
|
-
import { CONFIG, pjax, setPjax } from '../globals/globalVars'
|
4
|
+
import { BODY, CONFIG, pjax, setPjax, setSiteSearch, siteSearch } from '../globals/globalVars'
|
5
5
|
import { autoDarkmode, themeColorListener } from '../globals/themeColor'
|
6
6
|
import { resizeHandle, scrollHandle, visibilityListener } from '../globals/handles'
|
7
7
|
import { pagePosition } from '../globals/tools'
|
8
8
|
import Pjax from 'theme-shokax-pjax'
|
9
9
|
import { initVue } from '../library/vue'
|
10
|
-
import {
|
10
|
+
import { $dom } from '../library/dom'
|
11
|
+
import { createChild } from '../library/proto'
|
12
|
+
import { transition } from '../library/anime'
|
11
13
|
|
12
14
|
const siteInit = () => {
|
13
15
|
initVue()
|
@@ -36,10 +38,32 @@ const siteInit = () => {
|
|
36
38
|
visibilityListener()
|
37
39
|
}
|
38
40
|
themeColorListener()
|
41
|
+
|
39
42
|
if (__shokax_search__) {
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
$dom('li.item.search > i').addEventListener('click', () => {
|
44
|
+
if (CONFIG.search === null) { return }
|
45
|
+
|
46
|
+
if (!siteSearch) {
|
47
|
+
setSiteSearch(createChild(BODY, 'div', {
|
48
|
+
id: 'search',
|
49
|
+
innerHTML: '<div class="inner"><div class="header"><span class="icon"><i class="ic i-search"></i></span><div class="search-input-container"></div><span class="close-btn"><i class="ic i-times-circle"></i></span></div><div class="results"><div class="inner"><div id="search-stats"></div><div id="search-hits"></div><div id="search-pagination"></div></div></div></div>'
|
50
|
+
}))
|
51
|
+
}
|
52
|
+
|
53
|
+
import('../page/search').then(({ algoliaSearch }) => {
|
54
|
+
algoliaSearch(pjax)
|
55
|
+
})
|
56
|
+
|
57
|
+
// Handle and trigger popup window
|
58
|
+
$dom.each('.search', (element) => {
|
59
|
+
element.addEventListener('click', () => {
|
60
|
+
document.body.style.overflow = 'hidden'
|
61
|
+
transition(siteSearch, 'shrinkIn', () => {
|
62
|
+
$dom('.search-input').focus()
|
63
|
+
}) // transition.shrinkIn
|
64
|
+
})
|
65
|
+
})
|
66
|
+
}, { once: true, capture: true })
|
43
67
|
}
|
44
68
|
|
45
69
|
if (__shokax_fireworks__) {
|
@@ -47,15 +71,22 @@ const siteInit = () => {
|
|
47
71
|
firework.default(CONFIG.fireworks)
|
48
72
|
})
|
49
73
|
}
|
50
|
-
lazyLoad()
|
51
74
|
|
52
|
-
window.addEventListener('scroll', scrollHandle
|
75
|
+
window.addEventListener('scroll', scrollHandle, {
|
76
|
+
passive: true
|
77
|
+
})
|
53
78
|
|
54
|
-
window.addEventListener('resize', resizeHandle
|
79
|
+
window.addEventListener('resize', resizeHandle, {
|
80
|
+
passive: true
|
81
|
+
})
|
55
82
|
|
56
|
-
window.addEventListener('pjax:send', pjaxReload
|
83
|
+
window.addEventListener('pjax:send', pjaxReload, {
|
84
|
+
passive: true
|
85
|
+
})
|
57
86
|
|
58
|
-
window.addEventListener('pjax:success', siteRefresh
|
87
|
+
window.addEventListener('pjax:success', siteRefresh, {
|
88
|
+
passive: true
|
89
|
+
}) // 默认会传入一个event参数
|
59
90
|
|
60
91
|
window.addEventListener('beforeunload', () => {
|
61
92
|
pagePosition()
|