From 203af8ae4a0333d6c89a62869a8ba97302fb8041 Mon Sep 17 00:00:00 2001 From: Jose wan Date: Fri, 1 Dec 2023 14:15:49 +0800 Subject: [PATCH 1/2] Bug Repair MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 补充首页分页跳转按钮方法 --- source/js/main.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/source/js/main.js b/source/js/main.js index f7614c3d..34f60226 100644 --- a/source/js/main.js +++ b/source/js/main.js @@ -881,7 +881,29 @@ let sco = { cookiesWindow.style.display = 'none'; } } - } + }, + /** + * 首页分页跳转 + */ + toPage: function() { + const pageNumbers = document.querySelectorAll(".page-number"); + const maxPageNumber = parseInt(pageNumbers[pageNumbers.length - 1].innerHTML); + const inputElement = document.getElementById("toPageText"); + const inputPageNumber = parseInt(inputElement.value); + + if (!isNaN(inputPageNumber) && inputPageNumber > 0 && inputPageNumber <= maxPageNumber) { + const currentPageUrl = window.location.href.replace(/\/page\/\d+\/$/, "/"); + let targetPageUrl; + + if (inputPageNumber === 1) { + targetPageUrl = currentPageUrl; + } else { + targetPageUrl = currentPageUrl + (currentPageUrl.endsWith("/") ? "" : "/") + "page/" + inputPageNumber + "/"; + } + + document.getElementById("toPageButton").href = targetPageUrl; + } + }, } /* From f8e346b1768a8009e059bfa191bd9737d030dd9b Mon Sep 17 00:00:00 2001 From: Jose wan Date: Fri, 1 Dec 2023 17:23:01 +0800 Subject: [PATCH 2/2] Bug Repair & Update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复分页重复问题 新增waline评论支持 --- _config.yml | 13 ++++ layout/category.pug | 23 +++--- layout/includes/inject/head.pug | 8 +- .../widgets/third-party/comments/comment.pug | 4 +- .../widgets/third-party/comments/waline.pug | 17 +++++ layout/tag.pug | 29 ++++--- package.json | 2 +- source/css/_layout/index.styl | 1 + .../{_comment => _widgets/comment}/index.styl | 0 .../comment}/twikoo.styl | 0 source/css/_widgets/comment/waline.styl | 75 +++++++++++++++++++ source/css/index.styl | 5 +- source/js/main.js | 10 ++- 13 files changed, 148 insertions(+), 39 deletions(-) create mode 100644 layout/includes/widgets/third-party/comments/waline.pug rename source/css/{_comment => _widgets/comment}/index.styl (100%) rename source/css/{_comment => _widgets/comment}/twikoo.styl (100%) create mode 100644 source/css/_widgets/comment/waline.styl diff --git a/_config.yml b/_config.yml index 8b7dd820..b853700b 100644 --- a/_config.yml +++ b/_config.yml @@ -408,11 +408,22 @@ thirdparty: comment: enable: false # 是否开启评论 type: 'twikoo' # valine, twikoo + lazyload: true # 是否开启懒加载 + count: true # 是否显示评论数 # 评论系统 twikoo: envId: # url: https://twikoo.sondy.top/ lang: 'zh-CN' # 语言 accessToken: # accessToken + waline: + envId: https://waline.wzsco.top # url: https://waline.js.org/ + pageview: true # 是否开启页面访问量统计 + option: # waline配置项 + visitor: true # 是否开启访客统计 + highlight: true # 是否开启代码高亮 + emojiCDN: 'https://cdn.jsdelivr.net/npm/emoji-datasource-apple@latest/img/apple/64/' # emoji CDN + admin: # 管理员邮箱 + - # 插入代码到头部 之前 和 底部 之前 # 插入额外代码 如:统计,广告等 @@ -502,6 +513,8 @@ cdn: pacejs: https://cdn.bootcdn.net/ajax/libs/pace/1.2.4/pace.min.js echartsjs: https://cdn.bootcdn.net/ajax/libs/echarts/5.4.2/echarts.min.js lunrjs: https://cdn.bootcdn.net/ajax/libs/lunr.js/2.3.9/lunr.min.js + walinecss: https://cdn.bootcdn.net/ajax/libs/waline/2.15.7/waline.min.css + walinejs: https://cdn.bootcdn.net/ajax/libs/waline/2.15.7/waline.min.js body: viewimagejs: /lib/view-image.min.js waterfalljs: /lib/waterfall.min.js diff --git a/layout/category.pug b/layout/category.pug index aff67e68..787c0ebe 100644 --- a/layout/category.pug +++ b/layout/category.pug @@ -1,16 +1,13 @@ extends includes/layout.pug block content - main.layout#content-inner - div#category - div#category-bar - div.category-bar-items#category-bar-items - include includes/widgets/home/categoryBar - div.recent-posts#recent-posts - - const currentCategory = page.category - each post in site.posts.data - each category in post.categories.data - if category.name === currentCategory - include includes/widgets/home/postList - include includes/mixins/pagination - include includes/widgets/aside/aside \ No newline at end of file + main.layout#content-inner + div#category + div#category-bar + div.category-bar-items#category-bar-items + include includes/widgets/home/categoryBar + div.recent-posts#recent-posts + each post in site.posts.find({ parent: { $exists: false } }).data + include includes/widgets/home/postList + include includes/mixins/pagination + include includes/widgets/aside/aside \ No newline at end of file diff --git a/layout/includes/inject/head.pug b/layout/includes/inject/head.pug index 8f3459c0..797903b8 100644 --- a/layout/includes/inject/head.pug +++ b/layout/includes/inject/head.pug @@ -18,8 +18,12 @@ link(rel="stylesheet", href=cdn.snackbarcss) // comment if theme.comment.enable - if theme.comment.type === 'twikoo' - script(src=cdn.twikoojs) + case theme.comment.type + when 'twikoo' + script(src=cdn.twikoojs) + when 'waline' + script(src=cdn.walinejs) + link(rel="stylesheet", href=cdn.walinecss) // search if theme.thirdparty.search.enable diff --git a/layout/includes/widgets/third-party/comments/comment.pug b/layout/includes/widgets/third-party/comments/comment.pug index 103b96fa..84765640 100644 --- a/layout/includes/widgets/third-party/comments/comment.pug +++ b/layout/includes/widgets/third-party/comments/comment.pug @@ -11,4 +11,6 @@ div#post-comment(view-image) when 'gitalk' include ./gitalk.pug when 'valine' - include ./valine.pug \ No newline at end of file + include ./valine.pug + when 'waline' + include ./waline.pug \ No newline at end of file diff --git a/layout/includes/widgets/third-party/comments/waline.pug b/layout/includes/widgets/third-party/comments/waline.pug new file mode 100644 index 00000000..1457c556 --- /dev/null +++ b/layout/includes/widgets/third-party/comments/waline.pug @@ -0,0 +1,17 @@ +- const { envId, option, pageview } = theme.comment.waline +- const { lazyload, count, type } = theme.comment + +script. + async function initComment() { + (() => { + const waline = Waline.init(Object.assign({ + el: '#comment', + serverURL: '!{envId}', + pageview: !{lazyload ? false : pageview}, + dark: 'html[data-theme="dark"]', + path: window.location.pathname, + search: false, + comment: !{lazyload ? false : count}, + }, !{JSON.stringify(option)})) + })() + } \ No newline at end of file diff --git a/layout/tag.pug b/layout/tag.pug index 6c718053..de381dab 100644 --- a/layout/tag.pug +++ b/layout/tag.pug @@ -1,19 +1,16 @@ extends includes/layout.pug block content - main.layout#content-inner - div#tag - div#tag-page-tags - each tag in site.tags.find({ parent: { $exists: false } }).data - a(id=tag.name class=(tag.name === page.tag ? 'select' : '') href=url_for(tag.path)) - span.tags-punctuation - | #{tag.name} - span.tagsPageCount #{tag.length} - div.recent-posts#recent-posts - - const currentTag = page.tag - each post in site.posts.data - each tag in post.tags.data - if tag.name === currentTag - include includes/widgets/home/postList - include includes/mixins/pagination - include includes/widgets/aside/aside \ No newline at end of file + main.layout#content-inner + div#tag + div#tag-page-tags + each tag in site.tags.find({ parent: { $exists: false } }).data + a(id=tag.name class=(tag.name === page.tag ? 'select' : '') href=url_for(tag.path)) + span.tags-punctuation + | #{tag.name} + span.tagsPageCount #{tag.length} + div.recent-posts#recent-posts + each post in site.posts.find({ parent: { $exists: false } }).data + include includes/widgets/home/postList + include includes/mixins/pagination + include includes/widgets/aside/aside \ No newline at end of file diff --git a/package.json b/package.json index a4a2de55..c83f401a 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hexo-theme-solitude", - "version": "1.2.3", + "version": "1.2.4", "description": "A beautiful, powerful, and efficient Hexo theme developed by the DuoSco team", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" diff --git a/source/css/_layout/index.styl b/source/css/_layout/index.styl index d0173dd5..a7deaf64 100644 --- a/source/css/_layout/index.styl +++ b/source/css/_layout/index.styl @@ -16,6 +16,7 @@ border-radius 12px cursor pointer border var(--style-border) + margin 1rem 0 1rem &:hover box-shadow var(--card-hover-box-shadow) diff --git a/source/css/_comment/index.styl b/source/css/_widgets/comment/index.styl similarity index 100% rename from source/css/_comment/index.styl rename to source/css/_widgets/comment/index.styl diff --git a/source/css/_comment/twikoo.styl b/source/css/_widgets/comment/twikoo.styl similarity index 100% rename from source/css/_comment/twikoo.styl rename to source/css/_widgets/comment/twikoo.styl diff --git a/source/css/_widgets/comment/waline.styl b/source/css/_widgets/comment/waline.styl new file mode 100644 index 00000000..77733208 --- /dev/null +++ b/source/css/_widgets/comment/waline.styl @@ -0,0 +1,75 @@ +#comment + .wl-sort li + color var(--sco-gray) + + &.active + color var(--sco-main) !important + + .wl-comment + .wl-panel + margin 0 !important + + .wl-footer + .wl-info + button + background-color var(--sco-card-bg) + border var(--style-border-always) + color var(--sco-fontcolor) + + button:hover + background-color var(--sco-main) + border-color var(--sco-main) + color var(--sco-card-bg) + + #wl-edit + font-size 13px + line-height 1.5 + margin .75rem .25rem + + .wl-action + transition .3s + + &:hover + color var(--sco-main) + + .wl-meta-head + .wl-count + color var(--sco-gray) + font-size 14px + font-weight normal + + .wl-cards + font-size 16px!important + .wl-comment-actions + button + margin-right 15px + font-size 18px + + &:hover + color var(--sco-main) + .wl-head .wl-nick + font-size 20px !important + color var(--sco-lighttext) + font-weight bolder + + .wl-meta>span + background var(--sco-gray) + border-radius 5px + color var(--sco-card-bg) + margin-right 5px + + .wl-user + img + flex-shrink 0 + height 2.5rem + width 2.5rem + overflow hidden + text-align center + border-radius 2.5rem + border 2px solid var(--sco-white) + +[data-waline] a + color var(--sco-main) !important + +.wl-content pre, .wl-content pre[class*=language-] + padding .5rem!important \ No newline at end of file diff --git a/source/css/index.styl b/source/css/index.styl index 098c0eb1..f4f5dee7 100644 --- a/source/css/index.styl +++ b/source/css/index.styl @@ -15,8 +15,9 @@ if hexo-config('css_prefix') // comment if hexo-config('comment.enable') - @import '_comment/index.styl' - @import '_comment/twikoo.styl' when hexo-config('comment.type') == 'twikoo' + @import '_widgets/comment/index.styl' + @import '_widgets/comment/twikoo.styl' when hexo-config('comment.type') == 'twikoo' + @import '_widgets/comment/waline.styl' when hexo-config('comment.type') == 'waline' // commentBarrage if hexo-config('thirdparty.comment.enable') diff --git a/source/js/main.js b/source/js/main.js index 34f60226..43287806 100644 --- a/source/js/main.js +++ b/source/js/main.js @@ -846,7 +846,7 @@ let sco = { pageText.addEventListener("keydown", (event) => { if (event.keyCode === 13) { - heo.toPage(); + sco.toPage(); pjax.loadUrl(pageButton.href); } }); @@ -885,7 +885,7 @@ let sco = { /** * 首页分页跳转 */ - toPage: function() { + toPage: function () { const pageNumbers = document.querySelectorAll(".page-number"); const maxPageNumber = parseInt(pageNumbers[pageNumbers.length - 1].innerHTML); const inputElement = document.getElementById("toPageText"); @@ -1027,7 +1027,6 @@ window.refreshFn = () => { GLOBAL_CONFIG.lazyload.enable && sco.lazyloadImg() GLOBAL_CONFIG.lightbox && sco.lightbox('') GLOBAL_CONFIG.randomlinks && randomLinksList() - GLOBAL_CONFIG.comment.enable && newestCommentInit() if (PAGE_CONFIG.comment) { initComment() } @@ -1044,7 +1043,10 @@ window.refreshFn = () => { sco.initConsoleState() if (document.getElementById('history-baidu')) sco.card_history() // 那年今日 if (document.getElementById('welcome-info')) sco.card_welcome() // 个性定位 - if (GLOBAL_CONFIG.comment.type === "twikoo" && PAGE_CONFIG.comment) initializeCommentBarrage() // 热评 + if (GLOBAL_CONFIG.comment.type === "twikoo" && PAGE_CONFIG.comment) { + initializeCommentBarrage() // 热评 + GLOBAL_CONFIG.comment.enable && newestCommentInit() + } } sco.initTheme()