diff --git a/README.md b/README.md index b19ac7e9..05fa1f85 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ [![gitee](https://img.shields.io/badge/Gitee-red?logo=gitee)](https://gitee.com/nsjjd_w/hexo-theme-solitude) [![gitlab](https://img.shields.io/badge/GitLab-blue?logo=gitlab)](https://gitlab.com/efu/hexo-theme-solitude) -[Preview](https://solitude-demo.efu.me/) 丨 [Documentation](https://solitude-docs.efu.me/) +[Preview](https://efu.me/) 丨 [Documentation](https://solitude-docs.efu.me/) diff --git a/README_zh-cn.md b/README_zh-cn.md index 82b4ed93..c071b0f6 100644 --- a/README_zh-cn.md +++ b/README_zh-cn.md @@ -35,7 +35,7 @@ [![gitee](https://img.shields.io/badge/Gitee-red?logo=gitee)](https://gitee.com/nsjjd_w/hexo-theme-solitude) [![gitlab](https://img.shields.io/badge/GitLab-blue?logo=gitlab)](https://gitlab.com/efu/hexo-theme-solitude) -[预览](https://solitude-demo.efu.me/) 丨 [文档](https://solitude-docs.efu.me/) +[预览](https://efu.me/) 丨 [文档](https://solitude-docs.efu.me/) diff --git a/README_zh-tw.md b/README_zh-tw.md index 1a0efd0a..9a3e393e 100644 --- a/README_zh-tw.md +++ b/README_zh-tw.md @@ -35,7 +35,7 @@ [![gitee](https://img.shields.io/badge/Gitee-red?logo=gitee)](https://gitee.com/nsjjd_w/hexo-theme-solitude) [![gitlab](https://img.shields.io/badge/GitLab-blue?logo=gitlab)](https://gitlab.com/efu/hexo-theme-solitude) -[預覽](https://solitude-demo.efu.me/) 丨 [文档](https://solitude-docs.efu.me/) +[預覽](https://efu.me/) 丨 [文档](https://solitude-docs.efu.me/) diff --git a/SECURITY.md b/SECURITY.md index 70fbe5be..44664b22 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -1,9 +1,9 @@ -# 安全策略 +# Security Policy -## 报告漏洞 +## Report a vulnerability -要报告漏洞,请在正确的 GitHub 存储库上 [通过安全选项卡私下报告](https://github.com/valor-x/hexo-theme-solitude/security/advisories/new)(请参阅 [文档](https://docs.github.com/en/code-security/security-advisories/guidance-on-reporting-and-writing-information-about-vulnerabilities/privately-reporting-a-security-vulnerability#privately-reporting-a-security-vulnerability))。如果无法报告,请随时发送电子邮件至 **o@efu.me**。 +To report a vulnerability, please [report privately via security tab](https://github.com/valor-x/hexo-theme-solitude/security/advisories/new) on the correct GitHub repository (see [Document](https://docs.github.com/en/code-security/security-advisories/guidance-on-reporting-and-writing-information-about-vulnerabilities/privately-reporting-a-security-vulnerability#privately-reporting-a-security-vulnerability)). If you are unable to report, please feel free to email us at o@efu.me. -所有安全漏洞都将得到及时验证和解决。 +All security vulnerabilities will be verified and resolved in a timely manner. -虽然发现新漏洞的情况很少见,但建议始终使用最新版本的主题和其他依赖项,通过维护锁定文件(`yarn.lock`、`package-lock.json`),以保证尽可能安全。 +While it is rare for new vulnerabilities to be discovered, it is recommended to always use the latest version of the theme and other dependencies by maintaining locked files (`yarn.lock`, `package-lock.json`) to ensure that they are as secure as possible. \ No newline at end of file diff --git a/_config.yml b/_config.yml index 0985ad78..abcf0afb 100644 --- a/_config.yml +++ b/_config.yml @@ -295,7 +295,7 @@ aside: # Configure information on the home page index_post_list: direction: column # row / column - content: 3 # 1: post.description / 2: 自动获取description或截取内容(Automatically get descriptions or screenshots) / 3: 只使用截取内容(Use only screenshots) / false: 不显示内容(No content is displayed) + content: false # 1: post.description / 2: 自动获取description或截取内容(Automatically get descriptions or screenshots) / 3: 只使用截取内容(Use only screenshots) / false: 不显示内容(No content is displayed) length: 500 # 截取内容的长度 : The length of the screenshot content cover: both # left: 在左侧 : left / right: 在右侧 : right / both: 两侧 : both @@ -568,6 +568,14 @@ keyboard: # key: L # url: "/links/" +# 复制 +# Copy +copy: + enable: true + copyright: # Turn on Link copyright information after copying.(开启后将在默认增加版权信息) + enable: false + limit: 50 # word count. (字数) + # 懒加载 # lazyload lazyload: @@ -701,17 +709,11 @@ comment: enable: false type: # waline, twikoo commentBarrage: false # 热评开关 / Hot comment switch - newComment: false # 最新评论开关 / Latest comment switch - # 匿名评论前部分随机信息 / Anonymous comment front random information - randomInfoStart: - - "聪敏的" - - "可爱的" - - "美丽的" - # 匿名评论后部分随机信息 / Anonymous comment after random information - randomInfoEnd: - - "白菜" - - "小可爱" - - "小仙女" + lazyload: true # 懒加载 + count: true # 评论数展示 + newest_comment: + enable: false + storage: 421000 # 缓存时间 # twikoo 配置信息 # twikoo settings twikoo: # https://twikoo.js.org/ @@ -722,8 +724,21 @@ comment: # waline settings waline: # https://waline.js.org/ envId: # url: https://waline.wzsco.top - pageview: true # 是否开启页面访问量统计 / Whether to enable page access statistics + pageview: false # 是否开启页面访问量统计 / Whether to enable page access statistics option: # waline配置项 / waline configuration item + # valine 配置信息 + # valine settings + valine: + appId: # leancloud application app id + appKey: # leancloud application app key + serverURLs: # This configuration is suitable for domestic custom domain name users, overseas version will be automatically detected (no need to manually fill in) + avatar: + visitor: false + option: # options list + + +# 中控台扩展 : 最新评论 + 标签 + 文章 +console_plus: false # 站点验证 # Site verification @@ -748,8 +763,8 @@ css_prefix: false font: font-size: 16px code-font-size: 16px - font-family: '"PingFang SC","Hiragino Sans GB","Microsoft YaHei"' - code-font-family: '"monospace", "monospace"' + font-family: 'PingFang SC,Hiragino Sans GB,Microsoft YaHei' + code-font-family: 'monospace, monospace' # 插入代码到头部 之前 和 底部 之前 # Insert code before and before diff --git a/languages/en.yml b/languages/en.yml index 042bb9de..68e1b0ca 100755 --- a/languages/en.yml +++ b/languages/en.yml @@ -1,4 +1,6 @@ more: More +star: Behold, those who found delight in this piece also perused +random: Around theme: dark: dark @@ -130,4 +132,16 @@ link: random: You are about to ⌈ ${name} ⌋ , security unknown. keyboard: - title: Blog shortcuts \ No newline at end of file + title: Blog shortcuts + +newest_comment: + error: Unable to get a comment, please confirm that the relevant configuration is correct. + zero: No comments. + +comment: + title: ' Comment' + +commentBarrage: + title: Hot + +f12: Developer mode is turned on, please follow the GPL. \ No newline at end of file diff --git a/languages/zh-CN.yml b/languages/zh-CN.yml index dcc7bbf6..e8f9a67e 100755 --- a/languages/zh-CN.yml +++ b/languages/zh-CN.yml @@ -1,4 +1,6 @@ more: 更多 +star: 喜欢这篇的人也看了 +random: 随便逛逛 # Language: 简体中文 theme: @@ -9,6 +11,12 @@ copy: success: 复制成功 error: 复制失败 +copy_copyright: + author: 作者 + link: 链接 + source: 来源 + info: 著作权归作者所有。 商业转载请联系作者获得授权,非商业转载请注明出处。 + lately: second: 秒 minute: 分钟 @@ -125,4 +133,16 @@ link: random: 您即将前往 ⌈ ${name} ⌋ , 安全性未知 keyboard: - title: 博客快捷键 \ No newline at end of file + title: 博客快捷键 + +newest_comment: + error: 无法获取评论,请确认相关配置是否正确。 + zero: 没有评论 + +comment: + title: 评论 + +commentBarrage: + title: 热评 + +f12: 开发者模式已打开,请遵循GPL协议。 \ No newline at end of file diff --git a/languages/zh-TW.yml b/languages/zh-TW.yml index eb9d7f7c..a632e9f6 100755 --- a/languages/zh-TW.yml +++ b/languages/zh-TW.yml @@ -1,4 +1,6 @@ more: 更多 +star: 喜歡這篇的人也看了 +random: 随便逛逛 # Language: 繁體中文 (台灣) theme: @@ -9,6 +11,12 @@ copy: success: 複製成功 error: 複製失敗 +copy_copyright: + author: 作者 + link: 連結 + source: 來源 + info: 著作權歸作者所有。 商業轉載請聯繫作者獲得授權,非商業轉載請註明出處。 + lately: second: 秒 minute: 分鐘 @@ -125,4 +133,16 @@ link: random: 您即將前往 ⌈ ${name} ⌋ , 安全性未知 keyboard: - title: 博客快捷鍵 \ No newline at end of file + title: 博客快捷鍵 + +newest_comment: + error: 無法獲取評論,請確認相關配置是否正確。 + zero: 沒有評論 + +comment: + title: 評論 + +commentBarrage: + title: 熱評 + +f12: 開發者模式已打開,請遵循GPL協定。 \ No newline at end of file diff --git a/layout/category.pug b/layout/category.pug index dfd5d14d..db13b97e 100644 --- a/layout/category.pug +++ b/layout/category.pug @@ -6,7 +6,7 @@ block content #category-bar include includes/widgets/home/categoryBar .recent-posts#recent-posts - each post in page.posts.find({ parent: { $exists: false } }).data + each post,index in page.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/console.pug b/layout/includes/console.pug index 2a95997c..314d212c 100644 --- a/layout/includes/console.pug +++ b/layout/includes/console.pug @@ -1,14 +1,15 @@ div#console div.close-btn(onclick="sco.hideConsole()") i.solitude.st-close-fill - if theme.comment.newComment + if theme.console_plus div.console-card-group - div.console-card-group-left - div.console-card#card-newest-comments(onclick="sco.hideConsole()") - div.card-content - div.author-content-item-tips= _p('console.comment_tip') - div.author-content-item-title= _p('console.comment_title') - div.aside-list + if theme.console_plus && theme.comment.newest_comment.enable + div.console-card-group-left + div.console-card#card-newest-comments(onclick="sco.hideConsole()") + div.card-content + div.author-content-item-tips= _p('console.comment_tip') + div.author-content-item-title= _p('console.comment_title') + div.aside-list div.console-card-group-right div.console-card.tags(onclick="sco.hideConsole()") diff --git a/layout/includes/head/config.pug b/layout/includes/head/config.pug index 3da1c373..9411a493 100644 --- a/layout/includes/head/config.pug +++ b/layout/includes/head/config.pug @@ -22,30 +22,69 @@ } } - let translate = 'undefined'; - if (theme.translate && theme.translate.enable) { - translate = JSON.stringify({ - defaultEncoding: theme.translate.defaultEncoding, - translateDelay: theme.translate.translateDelay, - }); + const sayhello2 = theme.aside.card.sayhello2.map(item => `"${item}"`) || []; + + let comment = false + + if (theme.comment.type === 'twikoo') { + comment = JSON.stringify({ + avatar: theme.comment.avatar, + url: theme.comment.twikoo.envId, + commentBarrage: theme.comment.enable, + accessToken: theme.comment.twikoo.accessToken, + owo: { + body: '.OwO-body', + item: '.OwO-items li' + } + }) } - let copyright = 'undefined'; - if (theme.copy.enable && theme.copy.copyright.enable) { - copyright = JSON.stringify({ - limitCount: theme.copy.copyright.limit_count, - languages: { - author: _p("copy_copyright.author") + ': ' + config.author, - link: _p("copy_copyright.link") + ': ', - source: _p("copy_copyright.source") + ': ' + config.title, - info: _p("copy_copyright.info") + if (theme.comment.type === 'waline') { + comment = JSON.stringify({ + avatar: theme.comment.avatar, + url: theme.comment.waline.envId, + commentBarrage: theme.comment.enable, + owo: { + body: '.wl-emoji-popup', + item: '.wl-tab-wrapper button' } }) } - const commentInfoStart = theme.comment.randomInfoStart.map(item => `"${item}"`) || []; - const commentInfoEnd = theme.comment.randomInfoEnd.map(item => `"${item}"`) || []; - const sayhello2 = theme.aside.card.sayhello2.map(item => `"${item}"`) || []; + if (theme.comment.type === 'valine') { + comment = JSON.stringify({ + avatar: theme.comment.avatar, + url: theme.comment.valine.serverURLs, + commentBarrage: theme.comment.enable, + appId: theme.comment.valine.appId, + appKey: theme.comment.valine.appKey, + owo: { + body: '.vwrap', + item: '.vemojis i' + } + }) + } + + let post_ai = false + + if (theme.post_ai.enable) { + post_ai = JSON.stringify({ + key: theme.post_ai.key, + talk: theme.post_ai.talk, + randomPost: theme.post_ai.randomPost, + }) + } + + let copyright = false; + if (theme.copy.enable && theme.copy.copyright.enable) { + copyright = JSON.stringify({ + limit: theme.copy.copyright.limit, + author: _p("copy_copyright.author") + ': ' + config.author, + link: _p("copy_copyright.link") + ': ', + source: _p("copy_copyright.source") + ': ' + config.title, + info: _p("copy_copyright.info") + }) + } script. const GLOBAL_CONFIG = { @@ -57,6 +96,7 @@ script. enable: !{theme.lazyload.enable}, error: '!{theme.lazyload.errorimg}' }, + copyright: !{copyright}, highlight: { enable: !{theme.highlight.enable}, limit: !{theme.highlight.limit}, @@ -64,7 +104,7 @@ script. copy: !{theme.highlight.copy}, syntax: '!{config.syntax_highlighter}' }, - randomlinks: !{theme.footer.randomlink}, + randomlink: !{theme.footer.randomlink}, lang: { theme: { dark: '!{_p('theme.dark')}', @@ -93,7 +133,11 @@ script. chs: { chs_to_cht: '!{_p('chs.chs_tw')}', cht_to_chs: '!{_p('chs.chs_cn')}', - } + }, + barrage: { + title: '!{_p('commentBarrage.title')}', + }, + f12: '!{_p('f12')}', }, aside: { sayhello: { @@ -108,25 +152,7 @@ script. covercolor: { enable: !{theme.post.covercolor.enable} }, - comment: { - enable: !{theme.comment.enable}, - type: '!{theme.comment.type}', - commentBarrage: !{theme.comment.commentBarrage && theme.comment.enable}, - randomInfoStart: [!{commentInfoStart}], - randomInfoEnd: [!{commentInfoEnd}], - twikoo: { - url: '!{theme.comment.twikoo.envId}', - accessToken: '!{theme.comment.twikoo.accessToken}' - }, - waline: { - url: '!{theme.comment.waline.envId}', - } - }, + comment: !{comment}, lightbox: '!{ theme.mediumZoom ? "mediumZoom" : (theme.fancybox ? "fancybox" : "null")}', - ai: { - enable: !{theme.post_ai.enable}, - key: '!{theme.post_ai.key}', - talk: "!{theme.post_ai.talk}", - randomPost: !{theme.post_ai.randomPost}, - } + post_ai: !{post_ai} }; \ No newline at end of file diff --git a/layout/includes/inject/body.pug b/layout/includes/inject/body.pug index d5f85414..d09b6759 100644 --- a/layout/includes/inject/body.pug +++ b/layout/includes/inject/body.pug @@ -14,6 +14,10 @@ div script(src=url_for(theme.cdn.main)) script(src=url_for(theme.cdn.utils)) + if theme.comment.enable && theme.comment.type === 'valine' + // md5 + script(src=url_for(theme.cdn.blueimp_md5)) + // lately script(src=url_for(theme.cdn.lately_js)) @@ -47,7 +51,7 @@ div script(src=url_for(theme.cdn.swiper_js)) if theme.post_ai.enable - script(src=url_for(theme.cdn.sco_ai_js)) + script(src=url_for(theme.cdn.efu_ai)) if theme.capsule.enable || theme.music.enable script(src=url_for(theme.cdn.aplayer_js)) @@ -74,14 +78,14 @@ div case theme.comment.type when 'twikoo' script(src=url_for(theme.cdn.twikoo)) - when 'waline' - script(src=url_for(theme.cdn.waline_js)) if theme.comment.commentBarrage case theme.comment.type when 'twikoo' script(src=url_for(theme.cdn.twikoo_commentBarrage)) when 'waline' script(src=url_for(theme.cdn.waline_commentBarrage)) + when 'valine' + script(src=url_for(theme.cdn.valine_commentBarrage)) if theme.music.enable script(src=url_for(theme.cdn.music_js)) diff --git a/layout/includes/inject/head.pug b/layout/includes/inject/head.pug index dfab01b3..db4ea881 100644 --- a/layout/includes/inject/head.pug +++ b/layout/includes/inject/head.pug @@ -73,11 +73,45 @@ script. document.documentElement.classList.remove('hide-aside') } } + + win.getCSS = (url, id = false) => new Promise((resolve, reject) => { + const link = document.createElement('link') + link.rel = 'stylesheet' + link.href = url + if (id) link.id = id + link.onerror = reject + link.onload = link.onreadystatechange = function () { + const loadState = this.readyState + if (loadState && loadState !== 'loaded' && loadState !== 'complete') return + link.onload = link.onreadystatechange = null + resolve() + } + document.head.appendChild(link) + }) + + win.getScript = (url, attr = {}) => new Promise((resolve, reject) => { + const script = document.createElement('script') + script.src = url + script.async = true + script.onerror = reject + script.onload = script.onreadystatechange = function () { + const loadState = this.readyState + if (loadState && loadState !== 'loaded' && loadState !== 'complete') return + script.onload = script.onreadystatechange = null + resolve() + } + + Object.keys(attr).forEach(key => { + script.setAttribute(key, attr[key]) + }) + + document.head.appendChild(script) + }) } )(window) console.log( - "%c Program: Hexo %c Theme: Solitude %c Version: v1.6.1", + "%c Program: Hexo %c Theme: Solitude %c Version: v1.7.0", "border-radius:5px 0 0 5px;padding: 5px 10px;color:white;background:#ff3842;", "padding: 5px 10px;color:white;background:#3e9f50;", "border-radius:0 5px 5px 0;padding: 5px 10px;background:#0084ff;color:white;" diff --git a/layout/includes/widgets/post/postMeta.pug b/layout/includes/widgets/post/postMeta.pug index 4e1249da..48beeca3 100644 --- a/layout/includes/widgets/post/postMeta.pug +++ b/layout/includes/widgets/post/postMeta.pug @@ -48,6 +48,10 @@ when "waline" span.waline-pageview-count i.solitude.st-loading-line + when "valine" + span.leancloud_visitors(id=url_for(page.path)) + span.leancloud-visitors-count + i.solitude.st-loading-line else if theme.busuanzi span#busuanzi_value_page_pv i.solitude.st-loading-line @@ -62,5 +66,8 @@ when "waline" span.waline-comment-count i.solitude.st-loading-line + when "valine" + span.valine-comment-count(data-xid=url_for(page.path) itemprop="commentCount") + i.solitude.st-loading-line include ./wave \ No newline at end of file diff --git a/layout/includes/widgets/third-party/comments/comment.pug b/layout/includes/widgets/third-party/comments/comment.pug index fb9ae570..01bd0f3c 100644 --- a/layout/includes/widgets/third-party/comments/comment.pug +++ b/layout/includes/widgets/third-party/comments/comment.pug @@ -2,16 +2,14 @@ .comment-head .comment-headline i.solitude.st-chat-fill - span 评论 + span=_p('comment.title') span - .comment-randomInfo - a(onclick="sco.addRandomCommentInfo()", href="javascript:void(0)") 匿名评论 - .comment-tips#comment-tips - span ✅ 你无需删除空行,直接评论以获取最佳展示效果 .comment-wrap #comment case theme.comment.type when 'twikoo' - include ./twikoo.pug + !=partial('includes/widgets/third-party/comments/twikoo',{}, {cache: true}) when 'waline' - include ./waline.pug \ No newline at end of file + !=partial('includes/widgets/third-party/comments/waline',{}, {cache: true}) + when 'valine' + !=partial('includes/widgets/third-party/comments/valine',{}, {cache: true}) \ No newline at end of file diff --git a/layout/includes/widgets/third-party/comments/valine.pug b/layout/includes/widgets/third-party/comments/valine.pug new file mode 100644 index 00000000..10151a2b --- /dev/null +++ b/layout/includes/widgets/third-party/comments/valine.pug @@ -0,0 +1,44 @@ +- const { lazyload, count } = theme.comment +- const { appId, appKey, avatar, serverURLs, visitor, option } = theme.comment.valine +- let emojiMaps = '""' + +if site.data.valine + - emojiMaps = JSON.stringify(site.data.valine) + +script. + async function initComment() { + const initValine = () => { + const valine = new Valine(Object.assign({ + el: '#comment', + appId: '#{appId}', + appKey: '#{appKey}', + avatar: '#{avatar}', + serverURLs: '#{serverURLs}', + emojiMaps: !{emojiMaps}, + path: window.location.pathname, + visitor: #{visitor}, + ...!{JSON.stringify(option)} + })) + + if (GLOBAL_CONFIG.lightbox) { + utils.lightbox(document.querySelectorAll('#comment .vcontent img:not(.vemoji)')); + } + + sco.owoBig(); + } + + const loadValine = async () => { + if (typeof Valine === 'function') initValine() + else { + await getScript('!{url_for(theme.cdn.valine)}') + initValine() + } + } + + if (!!{lazyload}) { + if (!{lazyload}) utils.loadComment(document.getElementById('comment'), loadValine) + else setTimeout(loadValine, 0) + } else { + await loadValine() + } + } \ 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 index 24d8bd28..c1dc4313 100644 --- a/layout/includes/widgets/third-party/comments/waline.pug +++ b/layout/includes/widgets/third-party/comments/waline.pug @@ -1,17 +1,45 @@ -- const { envId, option } = theme.comment.waline +- const { envId, option ,pageview } = theme.comment.waline +- const { lazyload, count } = theme.comment script. async function initComment() { - Waline.init(Object.assign({ - el: '#comment', - serverURL: '!{envId}', - pageview: !{theme.post.meta.pv}, - dark: 'html[data-theme="dark"]', - path: window.location.pathname, - search: false, - comment: #{theme.post.meta.comment && is_post()}, - }, !{JSON.stringify(option)})) + const isLazyLoad = !!{lazyload}; + let walineInitFunction = window.walineFn || null; - GLOBAL_CONFIG.lightbox && utils.lightbox(document.querySelectorAll('#comment .wl-content img:not(.wl-emoji)')) - sco.owoBig() + async function initWaline(Fn) { + const walineOptions = { + el: '#comment', + serverURL: '!{envId}', + pageview: !isLazyLoad, + dark: 'html[data-theme="dark"]', + path: window.location.pathname, + comment: !isLazyLoad, + ...!{JSON.stringify(option)} + }; + const walineInstance = Fn(walineOptions); + + utils.addGlobalFn('pjax', () => walineInstance.destroy(), 'destroyWaline'); + } + + async function loadWalineCSSAndJS() { + if (!walineInitFunction) { + await getCSS('!{url_for(theme.cdn.waline_css)}'); + const {init} = await import('!{url_for(theme.cdn.waline_js)}'); + walineInitFunction = init || Waline.init; + window.walineFn = walineInitFunction; + } + initWaline(walineInitFunction); + } + + if (isLazyLoad) { + utils.loadComment(document.getElementById('comment'),loadWalineCSSAndJS); + } else { + await loadWalineCSSAndJS(); + } + + if (GLOBAL_CONFIG.lightbox) { + utils.lightbox(document.querySelectorAll('#comment .wl-content img:not(.wl-emoji)')); + } + + sco.owoBig(); } \ No newline at end of file diff --git a/layout/includes/widgets/third-party/news-comment/newest-comment.pug b/layout/includes/widgets/third-party/news-comment/newest-comment.pug index 0e405d9d..caaa858b 100644 --- a/layout/includes/widgets/third-party/news-comment/newest-comment.pug +++ b/layout/includes/widgets/third-party/news-comment/newest-comment.pug @@ -1,6 +1,8 @@ -if theme.comment.enable && theme.comment.newComment +if theme.comment.enable && theme.console_plus && theme.comment.newest_comment.enable case theme.comment.type when 'twikoo' - include twikoo + !=partial('includes/widgets/third-party/news-comment/twikoo',{}, {cache: true}) when 'waline' - include waline \ No newline at end of file + !=partial('includes/widgets/third-party/news-comment/waline',{}, {cache: true}) + when 'valine' + !=partial('includes/widgets/third-party/news-comment/valine',{}, {cache: true}) \ No newline at end of file diff --git a/layout/includes/widgets/third-party/news-comment/twikoo.pug b/layout/includes/widgets/third-party/news-comment/twikoo.pug index d4b22d4b..c08f2891 100644 --- a/layout/includes/widgets/third-party/news-comment/twikoo.pug +++ b/layout/includes/widgets/third-party/news-comment/twikoo.pug @@ -15,12 +15,12 @@ script. return content.length > 150 ? content.substring(0, 150) + '...' : content; } - const getComment = () => { - const $dom = document.querySelector('#card-newest-comments .aside-list') + const $asideList = document.querySelector('#card-newest-comments .aside-list') + const getComment = () => { const runTwikoo = () => { twikoo.getRecentComments({ - envId: GLOBAL_CONFIG.comment.twikoo.url, + envId: GLOBAL_CONFIG.comment.url, region: '', pageSize: 6, includeReply: true @@ -32,18 +32,18 @@ script. 'url': `${e.url}#${e.id}`, 'date': new Date(e.created).toISOString() })) + saveToLocal.set('twikoo-newest-comment', JSON.stringify(twikooArray), !{theme.comment.newest_comment.storage}/(60*24)) generateHtml(twikooArray) }).catch(function (err) { console.error(err) - $dom.innerHTML = "无法获取评论,请确认相关配置是否正确" + $asideList.textContent = "!{_p('newest_comment.error')}" }) } runTwikoo() } const generateHtml = array => { - const $dom = document.querySelector('#card-newest-comments .aside-list') - $dom.innerHTML = array.length ? array.map(item => ` + $asideList.innerHTML = array.length ? array.map(item => `
${item.nick} @@ -54,15 +54,17 @@ script.
- `).join('') : '没有评论' + `).join('') : "!{_p('newest_comment.zero')}" window.lazyLoadInstance && window.lazyLoadInstance.update() - window.pjax && window.pjax.refresh($dom) + window.pjax && window.pjax.refresh() utils && utils.changeTimeFormat() } const newestCommentInit = () => { - const $asideList = document.querySelector('#card-newest-comments .aside-list') - if ($asideList) { + const data = saveToLocal.get('twikoo-newest-comment') + if (data) { + generateHtml(JSON.parse(data)) + } else { getComment() } } diff --git a/layout/includes/widgets/third-party/news-comment/valine.pug b/layout/includes/widgets/third-party/news-comment/valine.pug new file mode 100644 index 00000000..a0a60e87 --- /dev/null +++ b/layout/includes/widgets/third-party/news-comment/valine.pug @@ -0,0 +1,79 @@ +script. + window.addEventListener('load', () => { + const changeContent = (content) => { + if (content === '') return content; + + const replacements = [ + {regex: /]+>/ig, replacement: '[Image]'}, + {regex: /]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi, replacement: '[URL]'}, + {regex: /```[\s\S]*?```/g, replacement: '[Code]'}, + {regex: /<[^>]+>/g, replacement: ""} + ]; + + content = replacements.reduce((str, {regex, replacement}) => str.replace(regex, replacement), content); + + return content.length > 150 ? content.substring(0, 150) + '...' : content; + } + + const $asideList = document.querySelector('#card-newest-comments .aside-list') + const newestCommentInit = () => { + const data = saveToLocal.get('valine-newest-comment') + if (data) { + generateHtml(JSON.parse(data)) + } else { + getComment() + } + } + + const getComment = async () => { + try { + const settings = { + "method": "GET", + "headers": { + "X-LC-Id": '!{theme.comment.valine.appId}', + "X-LC-Key": '!{theme.comment.valine.appKey}', + "Content-Type": "application/json" + }, + } + + const res = await fetch('!{theme.comment.valine.serverURLs}/1.1/classes/Comment?limit=8&order=-createdAt', settings) + const result = await res.json() + window.res = result + const valineArray = result.results.map(e => { + return { + 'content': changeContent(e.comment), + 'avatar': '!{theme.comment.avatar}' + '/avatar/' + md5(e.mail.toLowerCase()), + 'nick': e.nick, + 'url': e.url + '#' + e.objectId, + 'date': e.updatedAt || e.createdAt + } + }) + saveToLocal.set('valine-newest-comment', JSON.stringify(valineArray), !{theme.comment.newest_comment.storage} / (60 * 24)) + generateHtml(valineArray) + } catch (err) { + console.error(err) + $asideList.textContent = "!{_p('newest_comment.error')}" + } + } + + const generateHtml = array => { + const $dom = document.querySelector('#card-newest-comments .aside-list') + $dom.innerHTML = array.length ? array.map(item => ` +
+ + ${item.nick} +
${item.nick}
+
+
+ ${item.content} + +
+
+ `).join('') : "!{_p('newest_comment.zero')}" + window.lazyLoadInstance && window.lazyLoadInstance.update() + window.pjax && window.pjax.refresh() + utils && utils.changeTimeFormat() + } + + newestCommentInit() + }) \ No newline at end of file diff --git a/layout/includes/widgets/third-party/news-comment/waline.pug b/layout/includes/widgets/third-party/news-comment/waline.pug index fbbedf13..b9a5eb94 100644 --- a/layout/includes/widgets/third-party/news-comment/waline.pug +++ b/layout/includes/widgets/third-party/news-comment/waline.pug @@ -17,28 +17,33 @@ script. const $asideList = document.querySelector('#card-newest-comments .aside-list') const newestCommentInit = () => { - if ($asideList) { + const data = saveToLocal.get('waline-newest-comment') + if (data) { + generateHtml(JSON.parse(data)) + } else { getComment() } } - const getComment = () => { - Waline.RecentComments( - options = { - serverURL: GLOBAL_CONFIG.comment.waline.url, - count: 6, - } - ).then(function (res) { - const walineArray = res.comments.map(item => ({ - 'content': changeContent(item.comment), - 'avatar': item.avatar, - 'nick': item.nick, - 'url': `${item.url}#${item.objectId}`, - 'date': new Date(item.insertedAt).toISOString() - })) + + const getComment = async () => { + try { + const res = await fetch('!{theme.comment.waline.envId}/api/comment?type=recent&count=8', {method: 'GET'}) + const result = await res.json() + const walineArray = result.data.map(e => { + return { + 'content': changeContent(e.comment), + 'avatar': e.avatar, + 'nick': e.nick, + 'url': e.url + '#' + e.objectId, + 'date': e.time || e.insertedAt + } + }) + saveToLocal.set('waline-newest-comment', JSON.stringify(walineArray), !{theme.comment.newest_comment.storage} / (60 * 24)) generateHtml(walineArray) - }).catch( - $asideList.innerHTML = "无法获取评论,请确认相关配置是否正确" - ) + } catch (err) { + console.error(err) + $asideList.textContent = "!{_p('newest_comment.error')}" + } } const generateHtml = array => { @@ -54,9 +59,9 @@ script. - `).join('') : '没有评论' + `).join('') : "!{_p('newest_comment.zero')}" window.lazyLoadInstance && window.lazyLoadInstance.update() - window.pjax && window.pjax.refresh($dom) + window.pjax && window.pjax.refresh() utils && utils.changeTimeFormat() } diff --git a/layout/page.pug b/layout/page.pug index fd06fc83..e00482a3 100644 --- a/layout/page.pug +++ b/layout/page.pug @@ -25,6 +25,9 @@ block content != page.content when 'music' include includes/page/music + when 'banner' + include includes/widgets/page/banner + include includes/page/default default include includes/page/default if page.comment diff --git a/layout/tag.pug b/layout/tag.pug index faebfbc6..7ae23b6f 100644 --- a/layout/tag.pug +++ b/layout/tag.pug @@ -10,7 +10,7 @@ block content | #{tag.name} span.tagsPageCount #{tag.length} .recent-posts#recent-posts - each post in page.posts.find({ parent: { $exists: false } }).data + each post,index in page.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 c9bd9913..1b3401a6 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hexo-theme-solitude", - "version": "1.6.1", + "version": "1.7.0", "description": "A beautiful, powerful, and efficient Hexo theme developed by the wleelw", "main": "package.json", "scripts": { diff --git a/plugins.yml b/plugins.yml index be117548..e7b12a84 100644 --- a/plugins.yml +++ b/plugins.yml @@ -15,10 +15,18 @@ twikoo: file: dist/twikoo.all.min.js version: 1.6.31 waline_js: - name: '@waline/client' + name: 'waline' file: dist/waline.js other_name: waline - version: 2.15.8 + version: 3.1.3 +waline_css: + name: 'waline' + file: dist/waline.css + version: 3.1.3 +valine: + name: valine + file: dist/Valine.min.js + version: 1.5.1 sharejs: name: butterfly-extsrc file: sharejs/dist/js/social-share.min.js @@ -97,4 +105,8 @@ fancyapps_css: mermaid_js: name: mermaid file: dist/mermaid.min.js - version: 10.8.0 \ No newline at end of file + version: 10.8.0 +blueimp_md5: + name: blueimp-md5 + file: js/md5.min.js + version: 2.19.0 \ No newline at end of file diff --git a/scripts/event/cdn.js b/scripts/event/cdn.js index b46950a1..734893e3 100644 --- a/scripts/event/cdn.js +++ b/scripts/event/cdn.js @@ -54,9 +54,9 @@ hexo.extend.filter.register('before_generate', () => { file: 'js/tw_cn.js', version }, - sco_ai_js: { + efu_ai: { name: 'hexo-theme-solitude', - file: 'js/third_party/sco-ai.min.js', + file: 'js/third_party/efu_ai.min.js', version }, twikoo_commentBarrage: { @@ -69,6 +69,11 @@ hexo.extend.filter.register('before_generate', () => { file: 'js/commentBarrage/waline.js', version }, + valine_commentBarrage: { + name: 'hexo-theme-solitude', + file: 'js/commentBarrage/valine.js', + version + }, waterfall: { name: 'hexo-theme-solitude', file: 'js/third_party/waterfall.min.js', diff --git a/scripts/event/init.js b/scripts/event/init.js index 8d62119c..ef3f4010 100644 --- a/scripts/event/init.js +++ b/scripts/event/init.js @@ -5,13 +5,15 @@ hexo.extend.filter.register('before_generate', () => { const logger = hexo.log; const config = hexo.config; - if (hexoVer < 6.3) { - logger.error('请把 Hexo 升级到 V6.3.0 或更高的版本!'); + if (hexoVer < 7.0) { + logger.error('请把 Hexo 升级到 V7.0.0 或更高的版本!'); + logger.error('Please upgrade your Hexo to V7.0.0 or higher!'); process.exit(-1); } if (Number(majorVer) < 14) { logger.error('请将 Node.js 升级到 v14.0.0 或更高的版本!'); + logger.error('Please upgrade Node.js to v14.0.0 or later!'); process.exit(-1); } }); \ No newline at end of file diff --git a/scripts/event/merge_config.js b/scripts/event/merge_config.js index 35083cd3..e50ecc98 100644 --- a/scripts/event/merge_config.js +++ b/scripts/event/merge_config.js @@ -129,7 +129,8 @@ hexo.extend.filter.register('before_generate', () => { randompostjs: 'https://cdn.cbd.int/st-source/js/moment/random_post.min.js' }, keyboard: { enable: false, list: [] - }, lazyload: { + } + ,lazyload: { enable: false, field: 'site', placeholder: '/img/loading.gif', errorimg: '/img/error_load.png' }, loading: { fullpage: false, pace: true, @@ -150,7 +151,7 @@ hexo.extend.filter.register('before_generate', () => { enable: true, copyright: { enable: false, - limit_count: 50 + limit: 50 } } , post_ai: { @@ -164,7 +165,7 @@ hexo.extend.filter.register('before_generate', () => { enable: false, per_page: false, copytex: false, }, comment: { enable: false, - type: 'twikoo', + type: '', commentBarrage: false, newComment: false, randomInfoStart: [`baby's`, `little`, `my`,], @@ -180,8 +181,8 @@ hexo.extend.filter.register('before_generate', () => { font: { 'font-size': '16px', 'code-font-size': '16px', - 'font-family': '"PingFang SC","Hiragino Sans GB","Microsoft YaHei"', - 'code-font-family': '"monospace", "monospace"', + 'font-family': 'PingFang SC, Hiragino Sans GB,Microsoft YaHei', + 'code-font-family': 'monospace, monospace', }, extends: { head: [], body: [], diff --git a/scripts/helper/related_post.js b/scripts/helper/related_post.js index c52db6af..fc98a43a 100644 --- a/scripts/helper/related_post.js +++ b/scripts/helper/related_post.js @@ -5,7 +5,7 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) { const config = hexo.theme.config const limitNum = config.related_post.limit || 6 const dateType = config.related_post.date_type || 'created' - const headlineLang = this._p('喜欢这篇的人也看了') + const headlineLang = this._p('star') currentPost.tags.forEach(function (tag) { allPosts.forEach(function (post) { @@ -36,7 +36,7 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) { relatedPosts.sort(compare('weight', dateType)) let result = '