diff --git a/README.md b/README.md index 284ff4120..e0189ba35 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@
# hexo-theme-butterfly @@ -14,7 +12,7 @@  -Demo: 👍 [Butterfly](https://butterfly.js.org/) || 🤞 [CrazyWong](https://crazywong.com/) +Demo: 👍 [Butterfly](https://butterfly.js.org/) || 🤞 [CrazyWong](https://blog.crazywong.com/) Docs: 📖 [Butterfly Docs](https://butterfly.js.org/posts/21cfbf15/) @@ -62,17 +60,17 @@ npm i hexo-theme-butterfly - [x] Card UI Design - [X] Support sub-menu -- [x] Two Column designs +- [x] Two-column layout - [x] Responsive Web Design - [x] Dark Mode - [x] Pjax - [x] Read Mode - [x] Conversion between Traditional and Simplified Chinese - [X] TOC catalog is available for both computers and mobile phones -- [X] Color themes (darker/pale night/light/ocean/mac/mac light), support custom colors +- [X] Built-in Syntax Highlighting Themes (darker/pale night/light/ocean/mac/mac light), also support customization - [X] Code Blocks (Display code language/close or expand Code Blocks/Copy Button/word wrap) - [X] Disable copy/Add a Copyright Notice to the Copied Text -- [X] Search (Algolia SearchZ/Local Search) +- [X] Search (Algolia Search/Local Search) - [x] Mathjax and Katex - [x] Built-in 404 page - [x] WordCount diff --git a/README_CN.md b/README_CN.md index f67c2e387..441cd793f 100644 --- a/README_CN.md +++ b/README_CN.md @@ -1,7 +1,5 @@ # hexo-theme-butterfly @@ -14,7 +12,7 @@  -預覽: 👍 [Butterfly](https://butterfly.js.org/) || 🤞 [CrazyWong](https://crazywong.com/) +預覽: 👍 [Butterfly](https://butterfly.js.org/) || 🤞 [CrazyWong](https://blog.crazywong.com/) 文檔: 📖 [Butterfly Docs](https://butterfly.js.org/posts/21cfbf15/) @@ -72,7 +70,7 @@ theme: butterfly - [X] 內置多種代碼配色(darker/pale night/light/ocean/mac/mac light),可自定義代碼配色 - [X] 代碼塊顯示代碼語言/關閉或展開代碼塊/代碼複製/代碼自動換行 - [X] 可關閉文字複製/可開啟內容複製增加版權信息) -- [X] 兩種搜索(Algolia搜索和本地搜索) +- [X] 兩種搜索( Algolia 搜索和本地搜索) - [x] Mathjax 和 Katex - [x] 內置404頁面 - [x] 顯示字數統計 diff --git a/_config.yml b/_config.yml index aad06ef72..5c1b8d128 100644 --- a/_config.yml +++ b/_config.yml @@ -645,6 +645,11 @@ background: # Footer Background footer_bg: false +# Add mask to header or footer (为 header 或 footer 添加黑色半透遮罩) +mask: + header: true + footer: true + # the position of bottom right button/default unit: px (右下角按鈕距離底部的距離/默認單位為px) rightside-bottom: diff --git a/layout/includes/header/index.pug b/layout/includes/header/index.pug index 8089f1967..33e01dbc6 100644 --- a/layout/includes/header/index.pug +++ b/layout/includes/header/index.pug @@ -44,7 +44,7 @@ header#page-header(class=`${isHomeClass+isFixedClass}` style=bg_img) span#subtitle if(theme.social) #site_social_icons - !=fragment_cache('social', function(){return partial('includes/header/social')}) + !=partial('includes/header/social', {}, {cache: true}) #scroll-down i.fas.fa-angle-down.scroll-down-effects else diff --git a/layout/includes/loading/fullpage-loading.pug b/layout/includes/loading/fullpage-loading.pug index 5ca3d0dbe..4a2c8bf51 100644 --- a/layout/includes/loading/fullpage-loading.pug +++ b/layout/includes/loading/fullpage-loading.pug @@ -9,21 +9,25 @@ .loading-word= _p('loading') script. - const preloader = { - endLoading: () => { - document.body.style.overflow = ''; - document.getElementById('loading-box').classList.add("loaded") - }, - initLoading: () => { - document.body.style.overflow = 'hidden'; - document.getElementById('loading-box').classList.remove("loaded") + (()=>{ + const $loadingBox = document.getElementById('loading-box') + const $body = document.body + const preloader = { + endLoading: () => { + $body.style.overflow = '' + $loadingBox.classList.add('loaded') + }, + initLoading: () => { + $body.style.overflow = 'hidden' + $loadingBox.classList.remove('loaded') + } } - } - preloader.initLoading() - window.addEventListener('load',()=> { preloader.endLoading() }) + preloader.initLoading() + window.addEventListener('load',() => { preloader.endLoading() }) - if (!{theme.pjax && theme.pjax.enable}) { - document.addEventListener('pjax:send', () => { preloader.initLoading() }) - document.addEventListener('pjax:complete', () => { preloader.endLoading() }) - } \ No newline at end of file + if (!{theme.pjax && theme.pjax.enable}) { + document.addEventListener('pjax:send', () => { preloader.initLoading() }) + document.addEventListener('pjax:complete', () => { preloader.endLoading() }) + } + })() \ No newline at end of file diff --git a/layout/includes/mixins/post-ui.pug b/layout/includes/mixins/post-ui.pug index 4ed053b49..970b5fc12 100644 --- a/layout/includes/mixins/post-ui.pug +++ b/layout/includes/mixins/post-ui.pug @@ -70,7 +70,7 @@ mixin postUI(posts) block span.article-meta-label= ' ' + _p('card_post_count') - if theme.comments.card_post_count + if theme.comments.card_post_count && theme.comments.use case theme.comments.use[0] when 'Disqus' +countBlockInIndex @@ -89,7 +89,7 @@ mixin postUI(posts) when 'Waline' +countBlockInIndex a(href=url_for(link) + '#post-comment') - span.waline-comment-count(id=url_for(link)) + span.waline-comment-count(data-path=url_for(link)) i.fa-solid.fa-spinner.fa-spin when 'Twikoo' +countBlockInIndex diff --git a/layout/includes/rightside.pug b/layout/includes/rightside.pug index 03c6aaab4..57d8fba89 100644 --- a/layout/includes/rightside.pug +++ b/layout/includes/rightside.pug @@ -23,7 +23,7 @@ mixin rightsideItem(array) i.fas.fa-list-ul when 'chat' if chat_btn - button#chat_btn(type="button" title=_p("rightside.chat")) + button#chat-btn(type="button" title=_p("rightside.chat")) i.fas.fa-sms when 'comment' if commentsJsLoad diff --git a/layout/includes/sidebar.pug b/layout/includes/sidebar.pug index 11bddf8cc..66c67a9df 100644 --- a/layout/includes/sidebar.pug +++ b/layout/includes/sidebar.pug @@ -14,5 +14,5 @@ .headline= _p('aside.categories') .length-num= site.categories.length - hr + hr.custom-hr !=partial('includes/header/menu_item', {}, {cache: true}) diff --git a/layout/includes/third-party/card-post-count/artalk.pug b/layout/includes/third-party/card-post-count/artalk.pug index ef4993e2d..9e9aaed42 100644 --- a/layout/includes/third-party/card-post-count/artalk.pug +++ b/layout/includes/third-party/card-post-count/artalk.pug @@ -2,19 +2,34 @@ script. (() => { - const getArtalkCount = () => { - const runWidget = () => { - Artalk.loadCountWidget({ - server: '!{server}', - site: '!{site}', - countEl: '.artalk-count' + const getArtalkCount = async() => { + try { + const eleGroup = document.querySelectorAll('#recent-posts .artalk-count') + const keyArray = Array.from(eleGroup).map(i => i.getAttribute('data-page-key')) + + const headerList = { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Origin': window.location.origin + }, + body: new URLSearchParams({ + 'site_name': '!{site}', + 'type':'page_comment', + 'page_keys': keyArray + }) + } + + const res = await fetch('!{server}/api/stat', headerList) + const result = await res.json() + + keyArray.forEach((key, index) => { + eleGroup[index].textContent = result.data[key] || 0 }) + } catch (err) { + console.error(err) } - - if (typeof Artalk === 'function') runWidget() - else getScript('!{theme.asset.artalk_js}').then(runWidget) } - window.pjax ? getArtalkCount() : window.addEventListener('load', getArtalkCount) })() \ No newline at end of file diff --git a/layout/includes/third-party/card-post-count/waline.pug b/layout/includes/third-party/card-post-count/waline.pug index e69237fa7..c80da5789 100644 --- a/layout/includes/third-party/card-post-count/waline.pug +++ b/layout/includes/third-party/card-post-count/waline.pug @@ -1,17 +1,19 @@ script. (() => { - function loadWaline () { - function initWaline () { - let initData = { - el: null, - serverURL: '!{theme.waline.serverURL}', - comment: true - } - const waline = Waline.init(initData) - } + async function loadWaline () { + try { + const eleGroup = document.querySelectorAll('#recent-posts .waline-comment-count') + const keyArray = Array.from(eleGroup).map(i => i.getAttribute('data-path')) - if (typeof Waline === 'object') initWaline() - else getScript('!{url_for(theme.asset.waline_js)}').then(initWaline) + const res = await fetch(`!{theme.waline.serverURL}/api/comment?type=count&url=${keyArray}`, { method: 'GET' }) + const result = await res.json() + + result.data.forEach((count, index) => { + eleGroup[index].textContent = count + }) + } catch (err) { + console.error(err) + } } window.pjax ? loadWaline() : window.addEventListener('load', loadWaline) diff --git a/layout/includes/third-party/chat/chatra.pug b/layout/includes/third-party/chat/chatra.pug index b6c120146..5cc7b5a99 100644 --- a/layout/includes/third-party/chat/chatra.pug +++ b/layout/includes/third-party/chat/chatra.pug @@ -1,33 +1,50 @@ //- https://chatra.io/help/api/ script. - (function(d, w, c) { - w.ChatraID = '#{theme.chatra.id}'; - var s = d.createElement('script'); - w[c] = w[c] || function() { - (w[c].q = w[c].q || []).push(arguments); - }; - s.async = true; - s.src = 'https://call.chatra.io/chatra.js'; - if (d.head) d.head.appendChild(s); - })(document, window, 'Chatra'); + (() => { + const isChatBtn = !{theme.chat_btn} + const isChatHideShow = !{theme.chat_hide_show} - if (!{theme.chat_btn}) { - var chatBtnFn = () => { - var chatBtn = document.getElementById("chat_btn") - chatBtn.addEventListener("click", function(){ - Chatra('openChat') - }); - } - chatBtnFn() - } else { - if (!{theme.chat_hide_show}) { - function chatBtnHide () { + if (isChatBtn) { + const close = () => { + Chatra('minimizeWidget') Chatra('hide') } - function chatBtnShow () { + + const open = () => { + Chatra('openChat', true) Chatra('show') } + + window.ChatraSetup = { + startHidden: true + } + + window.chatBtnFn = () => { + const isShow = document.getElementById('chatra').classList.contains('chatra--expanded') + isShow ? close() : open() + } + } else if (isChatHideShow) { + window.chatBtn = { + hide: () => { + Chatra('hide') + }, + show: () => { + Chatra('show') + } + } } - } + + (function(d, w, c) { + w.ChatraID = '#{theme.chatra.id}' + var s = d.createElement('script') + w[c] = w[c] || function() { + (w[c].q = w[c].q || []).push(arguments) + } + s.async = true + s.src = 'https://call.chatra.io/chatra.js' + if (d.head) d.head.appendChild(s) + })(document, window, 'Chatra') + + })() diff --git a/layout/includes/third-party/chat/crisp.pug b/layout/includes/third-party/chat/crisp.pug index cc57e8dd2..6c8b6bf43 100644 --- a/layout/includes/third-party/chat/crisp.pug +++ b/layout/includes/third-party/chat/crisp.pug @@ -1,36 +1,45 @@ script. - window.$crisp = []; - window.CRISP_WEBSITE_ID = "!{theme.crisp.website_id}"; - (function () { - d = document; - s = d.createElement("script"); - s.src = "https://client.crisp.chat/l.js"; - s.async = 1; - d.getElementsByTagName("head")[0].appendChild(s); - })(); - $crisp.push(["safe", true]) + (() => { + window.$crisp = []; + window.CRISP_WEBSITE_ID = "!{theme.crisp.website_id}"; + (function () { + d = document; + s = d.createElement("script"); + s.src = "https://client.crisp.chat/l.js"; + s.async = 1; + d.getElementsByTagName("head")[0].appendChild(s); + })(); + $crisp.push(["safe", true]) - if (!{theme.chat_btn}) { - $crisp.push(["do", "chat:hide"]) - $crisp.push(["on", "chat:closed", function() { - $crisp.push(["do", "chat:hide"]) - }]) - var chatBtnFn = () => { - var chatBtn = document.getElementById("chat_btn") - chatBtn.addEventListener("click", function(){ + const isChatBtn = !{theme.chat_btn} + const isChatHideShow = !{theme.chat_hide_show} + + if (isChatBtn) { + const open = () => { $crisp.push(["do", "chat:show"]) $crisp.push(["do", "chat:open"]) + } - }); - } - chatBtnFn() - } else { - if (!{theme.chat_hide_show}) { - function chatBtnHide () { + const close = () => { $crisp.push(["do", "chat:hide"]) } - function chatBtnShow () { - $crisp.push(["do", "chat:show"]) + + close() + $crisp.push(["on", "chat:closed", function() { + close() + }]) + + window.chatBtnFn = () => { + $crisp.is("chat:visible") ? close() : open() + } + } else if (isChatHideShow) { + window.chatBtn = { + hide: () => { + $crisp.push(["do", "chat:hide"]) + }, + show: () => { + $crisp.push(["do", "chat:show"]) + } } } - } \ No newline at end of file + })() \ No newline at end of file diff --git a/layout/includes/third-party/chat/daovoice.pug b/layout/includes/third-party/chat/daovoice.pug index 3c6b06493..5a7c33dc9 100644 --- a/layout/includes/third-party/chat/daovoice.pug +++ b/layout/includes/third-party/chat/daovoice.pug @@ -1,40 +1,40 @@ //- https://guide.daocloud.io/daovoice/javascript-api-5869833.html script. - (function(i,s,o,g,r,a,m){i["DaoVoiceObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;a.charset="utf-8";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/!{theme.daovoice.app_id}.js","daovoice") + (() => { + (function(i,s,o,g,r,a,m){i["DaoVoiceObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;a.charset="utf-8";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/!{theme.daovoice.app_id}.js","daovoice") -script. - var isChatBtn = !{theme.chat_btn} - daovoice('init', { - app_id: '!{theme.daovoice.app_id}',},{ - launcher: { - disableLauncherIcon: isChatBtn // 悬浮 ICON 是否显示 - }, - }); - daovoice('update'); + const isChatBtn = !{theme.chat_btn} + const isChatHideShow = !{theme.chat_hide_show} - if (isChatBtn) { - var chatBtnFn = () => { - var chatBtn = document.getElementById("chat_btn") - chatBtn.addEventListener("click", function(){ - daovoice('show') - }); - } - chatBtnFn() - } else { - if (!{theme.chat_hide_show}) { - function chatBtnHide () { - daovoice('update', {},{ - launcher: { - disableLauncherIcon: true // 悬浮 ICON 是否显示 - }, - }); + daovoice('init', { + app_id: '!{theme.daovoice.app_id}',},{ + launcher: { + disableLauncherIcon: isChatBtn + }, + }); + daovoice('update'); + + if (isChatBtn) { + window.chatBtnFn = () => { + const isShow = document.getElementById('daodream-messenger').classList.contains('daodream-messenger-active') + isShow ? daovoice('hide') : daovoice('show') } - function chatBtnShow () { - daovoice('update', {},{ - launcher: { - disableLauncherIcon: false // 悬浮 ICON 是否显示 - }, - }); + } else if (isChatHideShow) { + window.chatBtn = { + hide: () => { + daovoice('update', {},{ + launcher: { + disableLauncherIcon: true + } + }) + }, + show: () => { + daovoice('update', {}, { + launcher: { + disableLauncherIcon: false + } + }) + } } } - } \ No newline at end of file + })() \ No newline at end of file diff --git a/layout/includes/third-party/chat/messenger.pug b/layout/includes/third-party/chat/messenger.pug index e5c9d885d..3d244fc04 100644 --- a/layout/includes/third-party/chat/messenger.pug +++ b/layout/includes/third-party/chat/messenger.pug @@ -4,39 +4,41 @@ #fb-customer-chat.fb-customerchat(page_id=pageID attribution='biz_inbox') script. - document.getElementById('fb-root') ? '' : document.body.insertAdjacentHTML('afterend', '') + (() => { + document.getElementById('fb-root') ? '' : document.body.insertAdjacentHTML('afterend', '') - window.fbAsyncInit = function() { - FB.init({ - xfbml: true, - version: 'v16.0' - }); - }; + window.fbAsyncInit = function() { + FB.init({ + xfbml: true, + version: 'v16.0' + }); + }; - (function(d, s, id) { - var js, fjs = d.getElementsByTagName(s)[0]; - if (d.getElementById(id)) return; - js = d.createElement(s); js.id = id; - js.src = 'https://connect.facebook.net/!{lang}/sdk/xfbml.customerchat.js'; - fjs.parentNode.insertBefore(js, fjs); - }(document, 'script', 'facebook-jssdk')); + (function(d, s, id) { + var js, fjs = d.getElementsByTagName(s)[0]; + if (d.getElementById(id)) return; + js = d.createElement(s); js.id = id; + js.src = 'https://connect.facebook.net/!{lang}/sdk/xfbml.customerchat.js'; + fjs.parentNode.insertBefore(js, fjs); + }(document, 'script', 'facebook-jssdk')); - if (!{theme.chat_btn}) { - var chatBtnFn = () => { - var chatBtn = document.getElementById("chat_btn") - chatBtn.addEventListener("click", function(){ - FB.CustomerChat.show(); - }); - } - chatBtnFn() - } else { - if (!{theme.chat_hide_show}) { - function chatBtnHide () { - FB.CustomerChat.hide() + const isChatBtn = !{theme.chat_btn} + const isChatHideShow = !{theme.chat_hide_show} + + if (isChatBtn) { + window.chatBtnFn = () => { + const isShow = document.querySelector('.fb_customer_chat_bounce_in_v2') + isShow ? FB.CustomerChat.hide() : FB.CustomerChat.show() } - function chatBtnShow () { - FB.CustomerChat.show(false) + } else if (isChatHideShow) { + window.chatBtn = { + hide: () => { + FB.CustomerChat.hide() + }, + show: () => { + FB.CustomerChat.show(false) + } } } - } + })() diff --git a/layout/includes/third-party/chat/tidio.pug b/layout/includes/third-party/chat/tidio.pug index 6b0097fb6..20104f53f 100644 --- a/layout/includes/third-party/chat/tidio.pug +++ b/layout/includes/third-party/chat/tidio.pug @@ -1,41 +1,45 @@ script(src=`//code.tidio.co/${theme.tidio.public_key}.js` async) +script. + (() => { + const isChatBtn = !{theme.chat_btn} + const isChatHideShow = !{theme.chat_hide_show} -if theme.chat_btn - script. - function onTidioChatApiReady() { - window.tidioChatApi.hide(); - window.tidioChatApi.on("close", function() { - window.tidioChatApi.hide(); - }); - } - if (window.tidioChatApi) { - window.tidioChatApi.on("ready", onTidioChatApiReady); - } else { - document.addEventListener("tidioChat-ready", onTidioChatApiReady); - } - - var chatBtnFn = () => { - document.getElementById("chat_btn").addEventListener("click", function(){ - window.tidioChatApi.show(); - window.tidioChatApi.open(); - }); - } - chatBtnFn() + if (isChatBtn) { + let isShow = false + const close = () => { + window.tidioChatApi.hide() + isShow = false + } + + const open = () => { + window.tidioChatApi.open() + window.tidioChatApi.show() + isShow = true + } -else if theme.chat_hide_show - script. - function chatBtnHide () { + const onTidioChatApiReady = () => { + window.tidioChatApi.hide() + window.tidioChatApi.on("close", close) + } if (window.tidioChatApi) { - //- window.tidioChatApi.hide(); - document.getElementById('tidio-chat').style.display= 'none' + window.tidioChatApi.on("ready", onTidioChatApiReady) + } else { + document.addEventListener("tidioChat-ready", onTidioChatApiReady) } - } - function chatBtnShow () { - if (window.tidioChatApi) { - //- window.tidioChatApi.show(); - document.getElementById('tidio-chat').style.display= 'block' - } + window.chatBtnFn = () => { + if (!window.tidioChatApi) return + isShow ? close() : open() + } + } else if (isChatHideShow) { + window.chatBtn = { + hide: () => { + window.tidioChatApi && window.tidioChatApi.hide() + }, + show: () => { + window.tidioChatApi && window.tidioChatApi.show() + } + } } - + })() diff --git a/layout/includes/third-party/comments/artalk.pug b/layout/includes/third-party/comments/artalk.pug index 0f7631e09..c5844ed07 100644 --- a/layout/includes/third-party/comments/artalk.pug +++ b/layout/includes/third-party/comments/artalk.pug @@ -23,11 +23,10 @@ script. }) } - if (typeof window.artalkItem === 'object') setTimeout(()=>{initArtalk()},200) + if (typeof window.artalkItem === 'object') initArtalk() else { getCSS('!{theme.asset.artalk_css}').then(()=>{ - typeof Artalk !== 'function' ? getScript('!{theme.asset.artalk_js}').then(initArtalk) - : setTimeout(()=>{initArtalk()},200) + getScript('!{theme.asset.artalk_js}').then(initArtalk) }) } } diff --git a/layout/includes/third-party/comments/index.pug b/layout/includes/third-party/comments/index.pug index 0821ae582..c797395b8 100644 --- a/layout/includes/third-party/comments/index.pug +++ b/layout/includes/third-party/comments/index.pug @@ -1,5 +1,5 @@ - let defaultComment = theme.comments.use[0] -hr +hr.custom-hr #post-comment .comment-head .comment-headline diff --git a/layout/includes/third-party/comments/waline.pug b/layout/includes/third-party/comments/waline.pug index 3d43fe254..55c7b45a4 100644 --- a/layout/includes/third-party/comments/waline.pug +++ b/layout/includes/third-party/comments/waline.pug @@ -14,13 +14,9 @@ script. }, !{JSON.stringify(option)})) } - const walineCSSLoad = document.getElementById('waline-css') - - if (typeof Waline === 'object') { - walineCSSLoad ? initWaline() : getCSS('!{url_for(theme.asset.waline_css)}','waline-css').then(initWaline) - } + if (typeof Waline === 'object') initWaline() else { - getCSS('!{url_for(theme.asset.waline_css)}','waline-css').then(() => { + getCSS('!{url_for(theme.asset.waline_css)}').then(() => { getScript('!{url_for(theme.asset.waline_js)}').then(initWaline) }) } diff --git a/layout/includes/third-party/math/mathjax.pug b/layout/includes/third-party/math/mathjax.pug index e1734b7b7..470aa451f 100644 --- a/layout/includes/third-party/math/mathjax.pug +++ b/layout/includes/third-party/math/mathjax.pug @@ -3,7 +3,7 @@ script. if (!window.MathJax) { window.MathJax = { tex: { - inlineMath: [ ['$','$'], ["\\(","\\)"]], + inlineMath: [['$', '$'], ['\\(', '\\)']], tags: 'ams' }, chtml: { @@ -21,16 +21,7 @@ script. math.end = {node: text, delim: '', n: 0} doc.math.push(math) } - }, ''], - insertScript: [200, () => { - document.querySelectorAll('mjx-container').forEach(node => { - if (node.hasAttribute('display')) { - btf.wrap(node, 'div', { class: 'mathjax-overflow' }) - } else { - btf.wrap(node, 'span', { class: 'mathjax-overflow' }) - } - }); - }, '', false] + }, ''] } } } diff --git a/layout/includes/third-party/math/mermaid.pug b/layout/includes/third-party/math/mermaid.pug index 3222a4a4a..119a5dd57 100644 --- a/layout/includes/third-party/math/mermaid.pug +++ b/layout/includes/third-party/math/mermaid.pug @@ -1,30 +1,38 @@ script. (() => { - const $mermaidWrap = document.querySelectorAll('#article-container .mermaid-wrap') - if ($mermaidWrap.length) { - window.runMermaid = () => { - window.loadMermaid = true - const theme = document.documentElement.getAttribute('data-theme') === 'dark' ? '!{theme.mermaid.theme.dark}' : '!{theme.mermaid.theme.light}' - - Array.from($mermaidWrap).forEach((item, index) => { - const mermaidSrc = item.firstElementChild - const mermaidThemeConfig = '%%{init:{ \'theme\':\'' + theme + '\'}}%%\n' - const mermaidID = 'mermaid-' + index - const mermaidDefinition = mermaidThemeConfig + mermaidSrc.textContent - mermaid.mermaidAPI.render(mermaidID, mermaidDefinition, (svgCode) => { - mermaidSrc.insertAdjacentHTML('afterend', svgCode) + const $mermaid = document.querySelectorAll('#article-container .mermaid-wrap') + if ($mermaid.length === 0) return + const runMermaid = () => { + window.loadMermaid = true + const theme = document.documentElement.getAttribute('data-theme') === 'dark' ? '!{theme.mermaid.theme.dark}' : '!{theme.mermaid.theme.light}' + + Array.from($mermaid).forEach((item, index) => { + const mermaidSrc = item.firstElementChild + const mermaidThemeConfig = '%%{init:{ \'theme\':\'' + theme + '\'}}%%\n' + const mermaidID = 'mermaid-' + index + const mermaidDefinition = mermaidThemeConfig + mermaidSrc.textContent + + const renderFn = mermaid.render(mermaidID, mermaidDefinition) + + const renderV10 = () => { + renderFn.then(({svg}) => { + mermaidSrc.insertAdjacentHTML('afterend', svg) }) - }) - } + } - const loadMermaid = () => { - window.loadMermaid ? runMermaid() : getScript('!{url_for(theme.asset.mermaid)}').then(runMermaid) - } + const renderV9 = svg => { + mermaidSrc.insertAdjacentHTML('afterend', svg) + } - btf.addModeChange('mermaid', () => { - window.runMermaid() + typeof renderFn === 'string' ? renderV9(renderFn) : renderV10() }) + } - window.pjax ? loadMermaid() : document.addEventListener('DOMContentLoaded', loadMermaid) + const loadMermaid = () => { + window.loadMermaid ? runMermaid() : getScript('!{url_for(theme.asset.mermaid)}').then(runMermaid) } + + btf.addModeChange('mermaid', runMermaid) + + window.pjax ? loadMermaid() : document.addEventListener('DOMContentLoaded', loadMermaid) })() \ No newline at end of file diff --git a/layout/includes/third-party/newest-comments/artalk.pug b/layout/includes/third-party/newest-comments/artalk.pug index ccbc94669..e2e83bac6 100644 --- a/layout/includes/third-party/newest-comments/artalk.pug +++ b/layout/includes/third-party/newest-comments/artalk.pug @@ -1,6 +1,6 @@ - const { server, site, option } = theme.artalk - const avatarCdn = option !== null && option.gravatar && option.gravatar.mirror -- const avatarDefault = option !== null && option.gravatar && option.gravatar.default +- const avatarDefault = option !== null && option.gravatar && (option.gravatar.params || option.gravatar.default) script. window.addEventListener('load', () => { @@ -72,11 +72,13 @@ script. const res = await fetch('!{server}/api/stat', headerList) const result = await res.json() const avatarStr = await getSetting() - const avatarCdn = !{avatarCdn} || avatarStr.data.frontend_conf.gravatar.mirror - const avatarDefault = !{avatarDefault} || avatarStr.data.frontend_conf.gravatar.default + const { mirror, params, default:defaults } = avatarStr.data.frontend_conf.gravatar + const avatarCdn = !{avatarCdn} || mirror + let avatarDefault = !{avatarDefault} || params || defaults + avatarDefault = avatarDefault.startsWith('d=') ? avatarDefault : `d=${avatarDefault}` const artalk = result.data.map(function (e) { return { - 'avatar': `${avatarCdn}${e.email_encrypted}?d=${avatarDefault}`, + 'avatar': `${avatarCdn}${e.email_encrypted}?${avatarDefault}`, 'content': changeContent(e.content_marked), 'nick': e.nick, 'url': e.page_url, diff --git a/layout/includes/third-party/newest-comments/waline.pug b/layout/includes/third-party/newest-comments/waline.pug index 95d17bb3c..00a72d5f3 100644 --- a/layout/includes/third-party/newest-comments/waline.pug +++ b/layout/includes/third-party/newest-comments/waline.pug @@ -1,6 +1,6 @@ script. window.addEventListener('load', () => { - const changeContent = (content) => { + const changeContent = content => { if (content === '') return content content = content.replace(/