From 22d8b8ead99403f2268eb8074cd29e32da1781ce Mon Sep 17 00:00:00 2001 From: XPoet Date: Thu, 28 Dec 2023 23:01:22 +0800 Subject: [PATCH 1/4] ui: optimize theme mode settings (#295) --- source/js/toggle-theme.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/js/toggle-theme.js b/source/js/toggle-theme.js index 46452409..603eba55 100644 --- a/source/js/toggle-theme.js +++ b/source/js/toggle-theme.js @@ -6,16 +6,16 @@ KEEP.initModeToggle = () => { iconDom: document.querySelector('.tool-toggle-theme-mode i'), enableLightMode() { - document.body.classList.remove('dark-mode') - document.body.classList.add('light-mode') + document.documentElement.classList.remove('dark-mode') + document.documentElement.classList.add('light-mode') this.iconDom.className = 'fas fa-moon' KEEP.themeInfo.styleStatus.isDark = false KEEP.setStyleStatus() }, enableDarkMode() { - document.body.classList.add('dark-mode') - document.body.classList.remove('light-mode') + document.documentElement.classList.add('dark-mode') + document.documentElement.classList.remove('light-mode') this.iconDom.className = 'fas fa-sun' KEEP.themeInfo.styleStatus.isDark = true KEEP.setStyleStatus() @@ -37,7 +37,7 @@ KEEP.initModeToggle = () => { initModeToggleButton() { this.themeModeToggleBtn.addEventListener('click', () => { - const isDark = document.body.classList.contains('dark-mode') + const isDark = document.documentElement.classList.contains('dark-mode') isDark ? this.enableLightMode() : this.enableDarkMode() }) }, From ad55c9f28a2c9245f818b41b6b3b4155319b9045 Mon Sep 17 00:00:00 2001 From: XPoet Date: Fri, 29 Dec 2023 11:02:34 +0800 Subject: [PATCH 2/4] perf: optimize post meta info --- layout/_partial/post/post-meta-info.ejs | 7 +++---- source/css/layout/_partial/post-meta-info.styl | 18 ------------------ source/js/post/post-helper.js | 2 +- 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/layout/_partial/post/post-meta-info.ejs b/layout/_partial/post/post-meta-info.ejs index 1ec26e9e..a750d9f1 100644 --- a/layout/_partial/post/post-meta-info.ejs +++ b/layout/_partial/post/post-meta-info.ejs @@ -13,14 +13,13 @@ const home_tag_limit_number = 5 <% if (page_type === 'post') { %> -   - <%= date(post.date, theme.post?.datetime_format || 'YYYY-MM-DD HH:mm:ss') %> - <%= date(post.date, 'YYYY-MM-DD HH:mm') %> +   + <%= date(post.date, theme.post?.datetime_format || 'YYYY-MM-DD HH:mm:ss') %>   - <%= date(post.updated, theme.post?.datetime_format || 'YYYY-MM-DD HH:mm:ss') %> + <%= date(post.updated, theme.post?.datetime_format || 'YYYY-MM-DD HH:mm:ss') %> <% } %> diff --git a/source/css/layout/_partial/post-meta-info.styl b/source/css/layout/_partial/post-meta-info.styl index a716f8f7..1ee51359 100644 --- a/source/css/layout/_partial/post-meta-info.styl +++ b/source/css/layout/_partial/post-meta-info.styl @@ -65,29 +65,11 @@ $meta-icon-interspace = 0.4rem .post-create-date { display var(--post-create-datetime) - - .mobile { - display none - } - - +keep-tablet() { - .pc { - display none - } - - .mobile { - display inline-block - } - } } .post-update-date { display var(--post-update-datetime) - - +keep-tablet() { - display none - } } diff --git a/source/js/post/post-helper.js b/source/js/post/post-helper.js index 93623382..18c92fb0 100644 --- a/source/js/post/post-helper.js +++ b/source/js/post/post-helper.js @@ -194,7 +194,7 @@ function initPostHelper() { resetPostUpdateDate() { const updateDateDom = document.querySelector( - '.post-meta-info-container .post-update-date .pc' + '.post-meta-info-container .post-update-date .datetime' ) const updated = new Date(updateDateDom.dataset.updated).getTime() const format = KEEP.theme_config.post?.datetime_format || 'YYYY-MM-DD HH:mm:ss' From f21ee564fd22abdbba45e4087df8071885006bf1 Mon Sep 17 00:00:00 2001 From: XPoet Date: Tue, 2 Jan 2024 10:58:35 +0800 Subject: [PATCH 3/4] perf: cdn configuration adds cdnjs settings item --- _config.yml | 2 +- scripts/helpers/helper.js | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/_config.yml b/_config.yml index e29aa661..a1470b85 100644 --- a/_config.yml +++ b/_config.yml @@ -289,7 +289,7 @@ lazyload: # --------------------------------------------------------------------------------------- cdn: enable: false # Option values: true | false - provider: jsdelivr # Option values: jsdelivr | unpkg + provider: cdnjs # Option values: cdnjs | jsdelivr | unpkg # --------------------------------------------------------------------------------------- diff --git a/scripts/helpers/helper.js b/scripts/helpers/helper.js index 958e0539..4f0441fc 100644 --- a/scripts/helpers/helper.js +++ b/scripts/helpers/helper.js @@ -37,25 +37,44 @@ hexo.extend.helper.register('getAuthorBadge', function (postCount, authorLabelCo const getSourceCdnUrl = (tyle, themeConfig, path) => { const version = require('../../package.json').version let { provider } = themeConfig?.cdn || {} + const providerEnum = { + jsdelivr: 'jsdelivr', + unpkg: 'unpkg', + cdnjs: 'cdnjs' + } + if (!provider) { - provider = 'jsdelivr' + provider = providerEnum.cdnjs } + let urlPrefix = '' + switch (provider?.toLocaleLowerCase()) { - case 'jsdelivr': + case providerEnum.jsdelivr: urlPrefix = '//cdn.jsdelivr.net/npm/hexo-theme-keep' if (tyle === 'js') { return `` } else { return `` } - case 'unpkg': + + case providerEnum.unpkg: urlPrefix = '//unpkg.com/hexo-theme-keep' if (tyle === 'js') { return `` } else { return `` } + + case providerEnum.cdnjs: + urlPrefix = 'https://cdnjs.cloudflare.com/ajax/libs/hexo-theme-keep' + if (tyle === 'js') { + path = path.includes('.min.js') ? path : path.replace('.js', '.min.js') + return `` + } else { + path = path.includes('.min.css') ? path : path.replace('.css', '.min.css') + return `` + } } } From 812dfbf216337469827f3ca99b4957558343da3c Mon Sep 17 00:00:00 2001 From: XPoet Date: Tue, 2 Jan 2024 11:34:41 +0800 Subject: [PATCH 4/4] ui: modify code block shrink line icon --- source/css/common/code-block/code-block.styl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/css/common/code-block/code-block.styl b/source/css/common/code-block/code-block.styl index a7b4e1ce..dc0b67b3 100644 --- a/source/css/common/code-block/code-block.styl +++ b/source/css/common/code-block/code-block.styl @@ -156,7 +156,7 @@ figure.highlight { font-weight 600 font-size 1rem font-family 'Font Awesome 6 Free' - content '\f078' + content '\f103' } &:hover {