From cb82bfb7b68eb9ee8fb22776347b8c0de3eab371 Mon Sep 17 00:00:00 2001 From: Jerry Date: Tue, 12 Oct 2021 23:27:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=BF=E6=8F=9B=20Justified=20Galler?= =?UTF-8?q?y=20=E7=82=BA=20flickr-justified-gallery=20feat:=20=E5=AE=8C?= =?UTF-8?q?=E5=85=A8=E7=A7=BB=E9=99=A4=20jquery=20feat:=20=E6=B8=85?= =?UTF-8?q?=E9=99=A4=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E7=9A=84CDN,=20?= =?UTF-8?q?=E9=BB=98=E8=AA=8D=20CDN=20=E4=B8=8D=E5=86=8D=E9=A1=AF=E7=A4=BA?= =?UTF-8?q?=E5=9C=A8=20config=20feat:=20=E5=88=87=E6=8F=9B=E5=A4=9C?= =?UTF-8?q?=E9=96=93=E6=A8=A1=E5=BC=8F=E5=BE=8C,=20mermaid=20=E4=B9=9F?= =?UTF-8?q?=E6=9C=83=E5=88=87=E6=8F=9B=E5=A4=9C=E9=96=93=E4=B8=BB=E9=A1=8C?= =?UTF-8?q?=20feat:=20=E7=A7=BB=E9=99=A4=E9=A8=B0=E8=A8=8A=E5=88=86?= =?UTF-8?q?=E6=9E=90=20feat:=20=E7=A7=BB=E9=99=A4=E5=8F=B3=E4=B8=8B?= =?UTF-8?q?=E8=A7=92=E5=AD=97=E9=AB=94=E8=AA=BF=E6=95=B4=E6=8C=89=E9=88=95?= =?UTF-8?q?=20feat:=20=E6=9C=AC=E5=9C=B0=E6=90=9C=E7=B4=A2=E5=8F=AF?= =?UTF-8?q?=E8=99=95=E7=90=86=20json=20feat:=20=E5=8F=B3=E4=B8=8B=E8=A7=92?= =?UTF-8?q?=E6=8C=89=E9=88=95=E8=87=AA=E5=AE=9A=E7=BE=A9=E9=A0=86=E5=BA=8F?= =?UTF-8?q?=20feat:=20=E5=8F=B3=E5=B0=8F=E8=A7=92=E6=8C=89=E9=88=95=20UI?= =?UTF-8?q?=20=E5=BE=AE=E8=AA=BF=20improvement:=20=E6=89=8B=E6=A9=9F?= =?UTF-8?q?=E7=AB=AF=E6=9B=B4=E6=94=B9=E9=96=B2=E8=AE=80=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E9=80=80=E5=87=BA=E6=8C=89=E9=88=95=E5=88=B0=E5=8F=B3=E4=B8=8B?= =?UTF-8?q?=E8=A7=92=20improvement:=20photofigcaption=20=E5=92=8C=20fancyb?= =?UTF-8?q?ox=20=E7=9A=84=20figcaption=20=E5=84=AA=E5=85=88=E9=A1=AF?= =?UTF-8?q?=E7=A4=BA=20=E5=9C=96=E7=89=87=E7=9A=84title=E5=B1=AC=E6=80=A7?= =?UTF-8?q?=EF=BC=8C=E7=84=B6=E5=BE=8C=E6=98=AF=20alt=20=E5=B1=AC=E6=80=A7?= =?UTF-8?q?=20improvement:=20=E9=A6=96=E9=A0=81ui=E5=BE=AE=E8=AA=BF=20impr?= =?UTF-8?q?ovement:=20=E7=A6=81=E6=AD=A2=E4=B8=80=E4=BA=9B=E7=80=8F?= =?UTF-8?q?=E8=A6=BD=E5=99=A8=E6=9C=83=E5=87=BA=E7=8F=BE=E9=BB=9E=E6=93=8A?= =?UTF-8?q?=E5=B7=A6=E4=B8=8B=E8=A7=92=E6=8C=89=E9=88=95=E5=87=BA=E7=8F=BE?= =?UTF-8?q?=E6=94=BE=E5=A4=A7=E7=B6=B2=E9=A0=81=E7=9A=84=E8=A1=8C=E7=82=BA?= =?UTF-8?q?=20improvement:=20js=20=E5=84=AA=E5=8C=96=20fix:=20=E4=BF=AE?= =?UTF-8?q?=E5=BE=A9=E7=AA=97=E5=8F=A3=E5=A4=A7=E5=B0=8F=E6=94=B9=E8=AE=8A?= =?UTF-8?q?=E6=99=82=EF=BC=8C=E5=B0=8E=E8=88=AA=E6=AC=84=E7=9A=84ui=20?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E6=9C=83=E9=8C=AF=E4=BA=82=E7=9A=84=20bug=20?= =?UTF-8?q?fix:=20=E4=BF=AE=E5=BE=A9=20pjax=20=E4=B8=8B,=20twikoo=20?= =?UTF-8?q?=E8=A9=95=E8=AB=96=E7=8D=B2=E5=8F=96=E6=98=AF=E4=B8=8A=E4=B8=80?= =?UTF-8?q?=E7=AF=87=E8=A9=95=E8=AB=96=E7=9A=84=20bug=20fix:=20=E5=A3=93?= =?UTF-8?q?=E7=B8=AE=20html=20=E4=BB=A3=E7=A2=BC=E5=BE=8C,=20mermaid=20?= =?UTF-8?q?=E9=A1=AF=E7=A4=BA=E6=AD=A3=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- README_CN.md | 2 +- _config.yml | 124 +++++------ languages/default.yml | 2 - languages/en.yml | 2 - languages/zh-CN.yml | 2 - languages/zh-TW.yml | 2 - layout/includes/head.pug | 2 +- layout/includes/head/analytics.pug | 12 -- layout/includes/head/config.pug | 5 +- layout/includes/head/preconnect.pug | 3 - layout/includes/mixins/post-ui.pug | 10 +- layout/includes/rightside.pug | 82 +++++--- .../includes/third-party/comments/twikoo.pug | 43 ++-- layout/includes/third-party/math/mermaid.pug | 34 +-- layout/includes/third-party/pjax.pug | 5 - package.json | 2 +- scripts/events/cdn.js | 104 ++++++++++ scripts/helpers/inject_head_js.js | 25 +-- scripts/tag/gallery.js | 2 +- scripts/tag/mermaid.js | 4 +- source/css/_global/function.styl | 2 +- source/css/_layout/aside.styl | 5 +- source/css/_layout/head.styl | 8 +- source/css/_layout/rightside.styl | 18 +- source/css/_layout/third-party.styl | 9 +- source/css/_mode/darkmode.styl | 1 - source/css/_mode/readmode.styl | 5 + source/css/_page/common.styl | 4 +- source/css/_page/homepage.styl | 15 +- source/css/_tags/gallery.styl | 183 ++++++++-------- source/js/main.js | 186 +++++++---------- source/js/search/local-search.js | 195 +++++++++--------- source/js/utils.js | 81 ++++---- 34 files changed, 611 insertions(+), 570 deletions(-) create mode 100644 scripts/events/cdn.js diff --git a/README.md b/README.md index 9001868..9179f3a 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Based on [hexo-theme-melody](https://github.com/Molunerfinn/hexo-theme-melody) t ### GIT -> If you are in Mainland China, you can download in [Gitee](https://gitee.com/iamjerryw/hexo-theme-butterfly) +> If you are in Mainland China, you can download in [Gitee](https://gitee.com/immyw/hexo-theme-butterfly.git) Stable branch [recommend]: diff --git a/README_CN.md b/README_CN.md index 8dc6794..e680844 100644 --- a/README_CN.md +++ b/README_CN.md @@ -24,7 +24,7 @@ ### Git 安裝 -> 本倉庫同時上傳到 [Gitee](https://gitee.com/iamjerryw/hexo-theme-butterfly),如果你訪問 Github 緩慢,可從 Gitee 中下載。 +> 本倉庫同時上傳到 [Gitee](https://gitee.com/immyw/hexo-theme-butterfly.git),如果你訪問 Github 緩慢,可從 Gitee 中下載。 在博客根目錄裡安裝穩定版【推薦】 diff --git a/_config.yml b/_config.yml index 2e19882..2568732 100644 --- a/_config.yml +++ b/_config.yml @@ -401,10 +401,6 @@ baidu_analytics: # https://analytics.google.com/analytics/web/ google_analytics: -# Tencent Analytics ID -# https://mta.qq.com -tencent_analytics: - # CNZZ Analytics # https://www.umeng.com/ cnzz_analytics: @@ -673,9 +669,6 @@ newest_comments: # Bottom right button (右下角按鈕) # -------------------------------------- -# Change font size -change_font_size: false - # Conversion between Traditional and Simplified Chinese (簡繁轉換) translate: enable: false @@ -704,6 +697,14 @@ darkmode: # autoChangeMode: false autoChangeMode: false +# Don't modify the following settings unless you know how they work (非必要請不要修改 ) +# Choose: readmode,translate,darkmode,hideAside,toc,chat,comment +# Don't repeat 不要重複 +rightside_item_order: + enable: false + hide: # readmode,translate,darkmode,hideAside + show: # toc,chat,comment + # Lightbox (圖片大圖查看模式) # -------------------------------------- # You can only choose one, or neither (只能選擇一個 或者 兩個都不選) @@ -724,7 +725,9 @@ fancybox: true mermaid: enable: false # built-in themes: default/forest/dark/neutral - theme: default + theme: + light: default + dark: dark # Note (Bootstrap Callout) note: @@ -817,86 +820,85 @@ inject: # 非必要請不要修改 CDN: # main - main_css: /css/index.css - jquery: https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js - main: /js/main.js - utils: /js/utils.js + main_css: + main: + utils: # pjax - pjax: https://cdn.jsdelivr.net/npm/pjax/pjax.min.js + pjax: # comments - gitalk: https://cdn.jsdelivr.net/npm/gitalk@latest/dist/gitalk.min.js - gitalk_css: https://cdn.jsdelivr.net/npm/gitalk/dist/gitalk.min.css - valine: https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js - disqusjs: https://cdn.jsdelivr.net/npm/disqusjs@1/dist/disqus.js - disqusjs_css: https://cdn.jsdelivr.net/npm/disqusjs@1/dist/disqusjs.css - utterances: https://utteranc.es/client.js - twikoo: https://cdn.jsdelivr.net/npm/twikoo/dist/twikoo.all.min.js - waline: https://cdn.jsdelivr.net/npm/@waline/client/dist/Waline.min.js + gitalk: + gitalk_css: + valine: + disqusjs: + disqusjs_css: + utterances: + twikoo: + waline: # share - addtoany: https://static.addtoany.com/menu/page.js - sharejs: https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js - sharejs_css: https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css + addtoany: + sharejs: + sharejs_css: # search - local_search: /js/search/local-search.js - algolia_js: /js/search/algolia.js - algolia_search: https://cdn.jsdelivr.net/npm/instantsearch.js@2.10.5/dist/instantsearch.min.js - algolia_search_css: https://cdn.jsdelivr.net/npm/instantsearch.js@2.10.5/dist/instantsearch.min.css + local_search: + algolia_js: + algolia_search: + algolia_search_css: # math - mathjax: https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js - katex: https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css - katex_copytex: https://cdn.jsdelivr.net/npm/katex@latest/dist/contrib/copy-tex.min.js - katex_copytex_css: https://cdn.jsdelivr.net/npm/katex@latest/dist/contrib/copy-tex.css - mermaid: https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js + mathjax: + katex: + katex_copytex: + katex_copytex_css: + mermaid: # count - busuanzi: //busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js + busuanzi: # background effect - canvas_ribbon: https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js - canvas_fluttering_ribbon: https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js - canvas_nest: https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-nest.min.js + canvas_ribbon: + canvas_fluttering_ribbon: + canvas_nest: - lazyload: https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js - instantpage: https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js - typed: https://cdn.jsdelivr.net/npm/typed.js/lib/typed.min.js - pangu: https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js + lazyload: + instantpage: + typed: + pangu: # photo - fancybox_css: https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css - fancybox: https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js - medium_zoom: https://cdn.jsdelivr.net/npm/medium-zoom/dist/medium-zoom.min.js + fancybox_css: + fancybox: + medium_zoom: # snackbar - snackbar_css: https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css - snackbar: https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js + snackbar_css: + snackbar: # effect - activate_power_mode: https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js - fireworks: https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js - click_heart: https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js - ClickShowText: https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-show-text.min.js + activate_power_mode: + fireworks: + click_heart: + ClickShowText: # fontawesome - fontawesome: https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css + fontawesome: # Conversion between Traditional and Simplified Chinese - translate: /js/tw_cn.js + translate: - # justifiedGallery - justifiedGallery_js: https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js - justifiedGallery_css: https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css + # flickr-justified-gallery + flickr_justified_gallery_js: + flickr_justified_gallery_css: # aplayer - aplayer_css: https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css - aplayer_js: https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js - meting_js: https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js + aplayer_css: + aplayer_js: + meting_js: # Prism.js - prismjs_js: https://cdn.jsdelivr.net/npm/prismjs/prism.min.js - prismjs_lineNumber_js: https://cdn.jsdelivr.net/npm/prismjs/plugins/line-numbers/prism-line-numbers.min.js - prismjs_autoloader: https://cdn.jsdelivr.net/npm/prismjs/plugins/autoloader/prism-autoloader.min.js \ No newline at end of file + prismjs_js: + prismjs_lineNumber_js: + prismjs_autoloader: \ No newline at end of file diff --git a/languages/default.yml b/languages/default.yml index 09f14c1..2241abc 100644 --- a/languages/default.yml +++ b/languages/default.yml @@ -94,8 +94,6 @@ share: Share rightside: readmode_title: Read Mode - font_plus_title: Increase font size - font_minus_title: Decrease font size translate_title: Toggle Between Traditional Chinese And Simplified Chinese night_mode_title: Toggle Between Light And Dark Mode back_to_top: Back To Top diff --git a/languages/en.yml b/languages/en.yml index 2465afa..22a55db 100644 --- a/languages/en.yml +++ b/languages/en.yml @@ -94,8 +94,6 @@ share: Share rightside: readmode_title: Read Mode - font_plus_title: Increase font size - font_minus_title: Decrease font size translate_title: Switch Between Traditional Chinese And Simplified Chinese night_mode_title: Switch Between Light And Dark Mode back_to_top: Back To Top diff --git a/languages/zh-CN.yml b/languages/zh-CN.yml index 3270a21..a0539a8 100644 --- a/languages/zh-CN.yml +++ b/languages/zh-CN.yml @@ -95,8 +95,6 @@ share: 分享 rightside: readmode_title: 阅读模式 - font_plus_title: 放大字体 - font_minus_title: 缩小字体 translate_title: 简繁转换 night_mode_title: 浅色和深色模式转换 back_to_top: 回到顶部 diff --git a/languages/zh-TW.yml b/languages/zh-TW.yml index 4217284..cf25922 100644 --- a/languages/zh-TW.yml +++ b/languages/zh-TW.yml @@ -95,8 +95,6 @@ share: 分享 rightside: readmode_title: 閱讀模式 - font_plus_title: 放大字型 - font_minus_title: 縮小字型 translate_title: 簡繁轉換 night_mode_title: 淺色和深色模式轉換 back_to_top: 回到頂部 diff --git a/layout/includes/head.pug b/layout/includes/head.pug index 6af325a..37078d8 100644 --- a/layout/includes/head.pug +++ b/layout/includes/head.pug @@ -20,7 +20,7 @@ meta(charset='UTF-8') meta(http-equiv="X-UA-Compatible" content="IE=edge") -meta(name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no") +meta(name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no") title= tabTitle if pageKeywords meta(name="keywords" content=pageKeywords) diff --git a/layout/includes/head/analytics.pug b/layout/includes/head/analytics.pug index 4873ebf..6452528 100644 --- a/layout/includes/head/analytics.pug +++ b/layout/includes/head/analytics.pug @@ -16,18 +16,6 @@ if theme.google_analytics gtag('js', new Date()); gtag('config', '!{theme.google_analytics}'); -if theme.tencent_analytics - script. - var _mtac = {}; - (function() { - var mta = document.createElement("script"); - mta.src = "//pingjs.qq.com/h5/stats.js?v2.0.4"; - mta.setAttribute("name", "MTAH5"); - mta.setAttribute("sid", "!{theme.tencent_analytics}"); - var s = document.getElementsByTagName("script")[0]; - s.parentNode.insertBefore(mta, s); - })(); - if theme.cnzz_analytics script(async data-pjax src=`https://s4.cnzz.com/z_stat.php?id=${theme.cnzz_analytics}&web_id=${theme.cnzz_analytics}`) diff --git a/layout/includes/head/config.pug b/layout/includes/head/config.pug index f669dbe..1f1974c 100644 --- a/layout/includes/head/config.pug +++ b/layout/includes/head/config.pug @@ -112,10 +112,9 @@ script. lightbox: '!{ theme.medium_zoom ? "mediumZoom" : (theme.fancybox ? "fancybox" : "null" )}', Snackbar: !{Snackbar}, source: { - jQuery: '!{url_for(theme.CDN.jquery)}', justifiedGallery: { - js: '!{url_for(theme.CDN.justifiedGallery_js)}', - css: '!{url_for(theme.CDN.justifiedGallery_css)}' + js: '!{url_for(theme.CDN.flickr_justified_gallery_js)}', + css: '!{url_for(theme.CDN.flickr_justified_gallery_css)}' } }, isPhotoFigcaption: !{theme.photofigcaption}, diff --git a/layout/includes/head/preconnect.pug b/layout/includes/head/preconnect.pug index 73231c7..d010b05 100644 --- a/layout/includes/head/preconnect.pug +++ b/layout/includes/head/preconnect.pug @@ -6,9 +6,6 @@ if theme.google_analytics if theme.baidu_analytics link(rel="preconnect" href="//hm.baidu.com") -if theme.tencent_analytics - link(rel="preconnect" href="//pingjs.qq.com") - if theme.cnzz_analytics link(rel="preconnect" href="//s4.cnzz.com") diff --git a/layout/includes/mixins/post-ui.pug b/layout/includes/mixins/post-ui.pug index 4a4a123..c28740d 100644 --- a/layout/includes/mixins/post-ui.pug +++ b/layout/includes/mixins/post-ui.pug @@ -43,25 +43,25 @@ mixin postUI(posts) time(datetime=date_xml(article[date_type]) title=date_title + ' ' + full_date(article[date_type]))=date(article[date_type], config.date_format) if (theme.post_meta.page.categories && article.categories.data.length > 0) span.article-meta - span.article-meta__separator | + span.article-meta-separator | i.fas.fa-inbox each item, index in article.categories.data a(href=url_for(item.path)).article-meta__categories #[=item.name] if (index < article.categories.data.length - 1) - i.fas.fa-angle-right + i.fas.fa-angle-right.article-meta-link if (theme.post_meta.page.tags && article.tags.data.length > 0) span.article-meta.tags - span.article-meta__separator | + span.article-meta-separator | i.fas.fa-tag each item, index in article.tags.data a(href=url_for(item.path)).article-meta__tags #[=item.name] if (index < article.tags.data.length - 1) - span.article-meta__link #[='•'] + span.article-meta-link #[='•'] mixin countBlockInIndex - needLoadCountJs = true span.article-meta - span.article-meta__separator | + span.article-meta-separator | i.fas.fa-comments if block block diff --git a/layout/includes/rightside.pug b/layout/includes/rightside.pug index 0e0bdf5..39a742b 100644 --- a/layout/includes/rightside.pug +++ b/layout/includes/rightside.pug @@ -1,38 +1,60 @@ +- const { readmode, translate, darkmode, aside, chat_btn } = theme +mixin rightsideItem(array) + each item in array + case item + when 'readmode' + if is_post() && readmode + button#readmode(type="button" title=_p('rightside.readmode_title')) + i.fas.fa-book-open + when 'translate' + if translate.enable + button#translateLink(type="button" title=_p('rightside.translate_title'))= translate.default + when 'darkmode' + if darkmode.enable && darkmode.button + button#darkmode(type="button" title=_p('rightside.night_mode_title')) + i.fas.fa-adjust + when 'hideAside' + if aside.enable && aside.button && page.aside !== false + button#hide-aside-btn(type="button" title=_p('rightside.aside')) + i.fas.fa-arrows-alt-h + when 'toc' + if showToc + button#mobile-toc-button.close(type="button" title=_p("rightside.toc")) + i.fas.fa-list-ul + when 'chat' + if chat_btn + button#chat_btn(type="button" title=_p("rightside.chat_btn")) + i.fas.fa-sms + when 'comment' + if commentsJsLoad + a#to_comment(href="#post-comment" title=_p("rightside.scroll_to_comment")) + i.fas.fa-comments + #rightside + - const { enable, hide, show } = theme.rightside_item_order + - const hideArray = enable ? hide && hide.split(',') : ['readmode','translate','darkmode','hideAside'] + - const showArray = enable ? show && show.split(',') : ['toc','chat','comment'] + + #rightside-config-hide - if is_post() && theme.readmode - button#readmode(type="button" title=_p('rightside.readmode_title')) - i.fas.fa-book-open - if theme.change_font_size - button#font-plus(type="button" title=_p('rightside.font_plus_title')) - i.fas.fa-plus - button#font-minus(type="button" title=_p('rightside.font_minus_title')) - i.fas.fa-minus - if theme.translate.enable - button#translateLink(type="button" title=_p('rightside.translate_title'))= theme.translate.default - if theme.darkmode.enable && theme.darkmode.button - button#darkmode(type="button" title=_p('rightside.night_mode_title')) - i.fas.fa-adjust - if theme.aside.enable && theme.aside.button && page.aside !== false - button#hide-aside-btn(type="button" title=_p('rightside.aside')) - i.fas.fa-arrows-alt-h + if hideArray + +rightsideItem(hideArray) #rightside-config-show - if is_post() - if (theme.readmode || theme.translate.enable || (theme.darkmode.enable && theme.darkmode.button) || theme.change_font_size) + if enable + if hide + button#rightside_config(type="button" title=_p("rightside.setting")) + i.fas.fa-cog.fa-spin + else + if is_post() + if (readmode || translate.enable || (darkmode.enable && darkmode.button)) + button#rightside_config(type="button" title=_p("rightside.setting")) + i.fas.fa-cog.fa-spin + else if translate.enable || (darkmode.enable && darkmode.button) button#rightside_config(type="button" title=_p("rightside.setting")) i.fas.fa-cog.fa-spin - else if theme.translate.enable || (theme.darkmode.enable && theme.darkmode.button) || theme.change_font_size - button#rightside_config(type="button" title=_p("rightside.setting")) - i.fas.fa-cog.fa-spin - if showToc - button#mobile-toc-button.close(type="button" title=_p("rightside.toc")) - i.fas.fa-list-ul - if theme.chat_btn - button#chat_btn(type="button" title=_p("rightside.chat_btn")) - i.fas.fa-sms - if commentsJsLoad - a#to_comment(href="#post-comment" title=_p("rightside.scroll_to_comment")) - i.fas.fa-comments + if showArray + +rightsideItem(showArray) + button#go-up(type="button" title=_p("rightside.back_to_top")) i.fas.fa-arrow-up \ No newline at end of file diff --git a/layout/includes/third-party/comments/twikoo.pug b/layout/includes/third-party/comments/twikoo.pug index c191cec..d7a8831 100644 --- a/layout/includes/third-party/comments/twikoo.pug +++ b/layout/includes/third-party/comments/twikoo.pug @@ -1,45 +1,48 @@ +- const { envId, region, option } = theme.twikoo +- const { use, lazyload, count } = theme.comments + script. (()=>{ - const $countDom = document.getElementById('twikoo-count') const init = () => { twikoo.init(Object.assign({ el: '#twikoo-wrap', - envId: '!{theme.twikoo.envId}', - region: '!{theme.twikoo.region}', + envId: '!{envId}', + region: '!{region}', onCommentLoaded: function () { btf.loadLightbox(document.querySelectorAll('#twikoo .tk-content img:not(.vemoji)')) } - }, !{JSON.stringify(theme.twikoo.option)})) + }, !{JSON.stringify(option)})) } const getCount = () => { twikoo.getCommentsCount({ - envId: '!{theme.twikoo.envId}', - region: '!{theme.twikoo.region}', + envId: '!{envId}', + region: '!{region}', urls: [window.location.pathname], includeReply: false }).then(function (res) { - $countDom.innerText = res[0].count + document.getElementById('twikoo-count').innerText = res[0].count }).catch(function (err) { console.error(err); }); } - const loadTwikoo = (bool = false) => { - if (typeof twikoo === 'object') { - init() - bool && $countDom && setTimeout(getCount,0) - } else { - getScript('!{theme.CDN.twikoo}').then(()=> { - init() - bool && $countDom && setTimeout(getCount,0) - }) - } + const runFn = () => { + init() + !{count ? 'GLOBAL_CONFIG_SITE.isPost && getCount()' : ''} } - if ('!{theme.comments.use[0]}' === 'Twikoo' || !!{theme.comments.lazyload}) { - if (!{theme.comments.lazyload}) btf.loadComment(document.getElementById('twikoo-wrap'), loadTwikoo) - else loadTwikoo(true) + const loadTwikoo = () => { + if (typeof twikoo === 'object') { + setTimeout(runFn,0) + return + } + getScript('!{theme.CDN.twikoo}').then(runFn) + } + + if ('!{use[0]}' === 'Twikoo' || !!{lazyload}) { + if (!{lazyload}) btf.loadComment(document.getElementById('twikoo-wrap'), loadTwikoo) + else loadTwikoo() } else { window.loadOtherComment = () => { loadTwikoo() diff --git a/layout/includes/third-party/math/mermaid.pug b/layout/includes/third-party/math/mermaid.pug index 801ce21..5716b30 100644 --- a/layout/includes/third-party/math/mermaid.pug +++ b/layout/includes/third-party/math/mermaid.pug @@ -1,15 +1,25 @@ script. - if (document.getElementsByClassName('mermaid').length) { - if (window.mermaidJsLoad) mermaid.init() - else { - getScript('!{theme.CDN.mermaid}').then(() => { - window.mermaidJsLoad = true - mermaid.initialize({ - theme: '!{theme.mermaid.theme}', + (() => { + const $mermaidWrap = document.querySelectorAll('#article-container .mermaid-wrap') + if ($mermaidWrap.length) { + window.runMermaid = () => { + 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) + }) }) - !{theme.pjax.enable} && mermaid.init() - }) + } + + const loadMermaid = () => { + window.mermaid ? runMermaid() : getScript('!{theme.CDN.mermaid}').then(runMermaid) + } + + window.pjax ? loadMermaid() : document.addEventListener('DOMContentLoaded', loadMermaid) } - } - - + })() \ No newline at end of file diff --git a/layout/includes/third-party/pjax.pug b/layout/includes/third-party/pjax.pug index f3b5812..a1278b9 100644 --- a/layout/includes/third-party/pjax.pug +++ b/layout/includes/third-party/pjax.pug @@ -74,11 +74,6 @@ script. typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting() - // Analytics - if (!{theme.tencent_analytics ? true : false}) { - MtaH5.pgv() - } - // prismjs typeof Prism === 'object' && Prism.highlightAll() diff --git a/package.json b/package.json index 4fb23c4..ee1f528 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hexo-theme-butterfly", - "version": "4.0.0-b7", + "version": "4.0.0-b8", "description": "A Simple and Card UI Design theme for Hexo", "main": "package.json", "scripts": { diff --git a/scripts/events/cdn.js b/scripts/events/cdn.js new file mode 100644 index 0000000..0f038c4 --- /dev/null +++ b/scripts/events/cdn.js @@ -0,0 +1,104 @@ +/** + * Butterfly + * CDN + */ + +'use strict' + +hexo.extend.filter.register('before_generate', () => { + const themeConfig = hexo.theme.config + const defaultCDN = { + main_css: '/css/index.css', + main: '/js/main.js', + utils: '/js/utils.js', + + // pjax + pjax: 'https://cdn.jsdelivr.net/npm/pjax/pjax.min.js', + + // comments + gitalk: 'https://cdn.jsdelivr.net/npm/gitalk@latest/dist/gitalk.min.js', + gitalk_css: 'https://cdn.jsdelivr.net/npm/gitalk/dist/gitalk.min.css', + valine: 'https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js', + disqusjs: 'https://cdn.jsdelivr.net/npm/disqusjs@1/dist/disqus.js', + disqusjs_css: 'https://cdn.jsdelivr.net/npm/disqusjs@1/dist/disqusjs.css', + utterances: 'https://utteranc.es/client.js', + twikoo: 'https://cdn.jsdelivr.net/npm/twikoo/dist/twikoo.all.min.js', + waline: 'https://cdn.jsdelivr.net/npm/@waline/client/dist/Waline.min.js', + + // share + addtoany: 'https://static.addtoany.com/menu/page.js', + sharejs: 'https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js', + sharejs_css: 'https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css', + + // search + local_search: '/js/search/local-search.js', + algolia_js: '/js/search/algolia.js', + algolia_search: 'https://cdn.jsdelivr.net/npm/instantsearch.js@2.10.5/dist/instantsearch.min.js', + algolia_search_css: 'https://cdn.jsdelivr.net/npm/instantsearch.js@2.10.5/dist/instantsearch.min.css', + + // math + mathjax: 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js', + katex: 'https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css', + katex_copytex: 'https://cdn.jsdelivr.net/npm/katex@latest/dist/contrib/copy-tex.min.js', + katex_copytex_css: 'https://cdn.jsdelivr.net/npm/katex@latest/dist/contrib/copy-tex.css', + mermaid: 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js', + + // count + busuanzi: '//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js', + + // background effect + canvas_ribbon: 'https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js', + canvas_fluttering_ribbon: 'https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js', + canvas_nest: 'https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-nest.min.js', + + lazyload: 'https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js', + instantpage: 'https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js', + typed: 'https://cdn.jsdelivr.net/npm/typed.js/lib/typed.min.js', + pangu: 'https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js', + + // photo + fancybox_css: 'https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css', + fancybox: 'https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js', + medium_zoom: 'https://cdn.jsdelivr.net/npm/medium-zoom/dist/medium-zoom.min.js', + + // snackbar + snackbar_css: 'https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css', + snackbar: 'https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js', + + // effect + activate_power_mode: 'https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js', + fireworks: 'https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js', + click_heart: 'https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js', + ClickShowText: 'https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-show-text.min.js', + + // fontawesome + fontawesome: 'https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css', + + // Conversion between Traditional and Simplified Chinese + translate: '/js/tw_cn.js', + + // flickr-justified-gallery + flickr_justified_gallery_js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js', + flickr_justified_gallery_css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css', + + // aplayer + aplayer_css: 'https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css', + aplayer_js: 'https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js', + meting_js: 'https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js', + + // Prism.js + prismjs_js: 'https://cdn.jsdelivr.net/npm/prismjs/prism.min.js', + prismjs_lineNumber_js: 'https://cdn.jsdelivr.net/npm/prismjs/plugins/line-numbers/prism-line-numbers.min.js', + prismjs_autoloader: 'https://cdn.jsdelivr.net/npm/prismjs/plugins/autoloader/prism-autoloader.min.js' + } + + // delete null value + const deleteNullValue = obj => { + for (const i in obj) { + obj[i] === null && delete obj[i] + } + return obj + } + + themeConfig.CDN = Object.assign(defaultCDN, deleteNullValue(themeConfig.CDN)) +}) diff --git a/scripts/helpers/inject_head_js.js b/scripts/helpers/inject_head_js.js index 78e47c0..8da1179 100644 --- a/scripts/helpers/inject_head_js.js +++ b/scripts/helpers/inject_head_js.js @@ -6,7 +6,7 @@ 'use strict' hexo.extend.helper.register('inject_head_js', function () { - const { darkmode, aside, change_font_size, index_img, disable_top_img, pjax} = this.theme + const { darkmode, aside } = this.theme const localStore = ` win.saveToLocal = { @@ -131,31 +131,14 @@ hexo.extend.helper.register('inject_head_js', function () { ` } - let changFontAside = '' - if (change_font_size) { - changFontAside = ` - const fontSizeVal = saveToLocal.get('global-font-size') - if (fontSizeVal !== undefined) { - document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px') - } - ` - } - - let detectApple = '' - if (!disable_top_img || index_img !== false) { - detectApple = ` + const detectApple = ` const detectApple = () => { - if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){ + if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){ document.documentElement.classList.add('apple') } } detectApple() ` - if (pjax.enable) { - detectApple += 'document.addEventListener(\'pjax:complete\', detectApple)' - } - } - - return `` + return `` }) diff --git a/scripts/tag/gallery.js b/scripts/tag/gallery.js index 21ebb55..acccd0b 100644 --- a/scripts/tag/gallery.js +++ b/scripts/tag/gallery.js @@ -8,7 +8,7 @@ const urlFor = require('hexo-util').url_for.bind(hexo) function gallery (args, content) { - return `