diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 00656fe..f8c2d62 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -7,14 +7,16 @@ assignees: '' --- + + diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/custom.md index 48d5f81..4842758 100644 --- a/.github/ISSUE_TEMPLATE/custom.md +++ b/.github/ISSUE_TEMPLATE/custom.md @@ -4,7 +4,6 @@ about: Describe this issue template's purpose here. title: '' labels: '' assignees: '' - --- diff --git a/.github/stale.yml b/.github/stale.yml index 355bbee..2d74a9c 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -8,7 +8,6 @@ exemptLabels: - security - bug - enhancement - - Solved - documentation # Label to use when marking an issue as stale staleLabel: wontfix diff --git a/README.md b/README.md index af0c3b1..fac6714 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,8 @@ ![version](https://img.shields.io/github/package-json/v/jerryc127/hexo-theme-butterfly) ![https://img.shields.io/npm/v/hexo-theme-butterfly?color=%09%23bf00ff](https://img.shields.io/npm/v/hexo-theme-butterfly?color=%09%23bf00ff) -![hexo version](https://img.shields.io/badge/hexo-4.0+-0e83c) +![hexo version](https://img.shields.io/badge/hexo-4.2+-0e83c) ![npm download](https://img.shields.io/npm/dw/hexo-theme-butterfly?color=green) -![nodejs version](https://img.shields.io/badge/node.js-8.0+-yellow) ![license](https://img.shields.io/github/license/jerryc127/hexo-theme-butterfly?color=FF5531) Demo: 👍 [Butterfly](https://demo.jerryc.me/) || 🤞 [JerryC](https://jerryc.me/) @@ -49,10 +48,49 @@ npm i hexo-theme-butterfly > npm install hexo-renderer-pug hexo-renderer-stylus +## Features + +- [x] Card UI Design +- [X] Support sub-menu +- [x] Two Column designs +- [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] 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] Mathjax and Katex +- [x] Built-in 404 page +- [x] WordCount +- [x] Related articles +- [x] Displays outdated notice for a post +- [x] Share (AddThis/Sharejs/Addtoany) +- [X] Comment (Disqus/Disqusjs/Livere/Gitalk/Valine/Utterances/Facebook Comments) +- [x] Multiple Comment System Support +- [x] Online Chats (Chatra/Tidio/Daovoice/Gitter/Crisp) +- [x] Web analytics (Baidu Analytics/Google Analytics/Tencent Analytics/CNZZ Analytics) +- [x] Google AdSense +- [x] Webmaster Verification (google/Bing/Baidu/360/Yandex) +- [x] Change website colour scheme +- [x] Typewriter Effect: activate_power_mode +- [x] Background effects (Canvas ribbon/canvas_ribbon_piao/canvas_nest) +- [x] Mouse click effects (Fireworks/Heart/Text) +- [x] Preloader/Loading Animation +- [x] Busuanzi visitor counter +- [x] Medium Zoom/Fancybox +- [x] Mermaid +- [x] Justified Gallery +- [x] Lazyload images +- [x] Instantpage/Pangu/Snackbar notification toast/PWA...... + ## Screenshots -![image](https://user-images.githubusercontent.com/16351105/58887365-1272f780-8718-11e9-9329-3292c6ba20d4.png) +![](https://cdn.jsdelivr.net/gh/jerryc127/CDN/img/theme-butterfly-readme-homepage-1.png) -![](https://user-images.githubusercontent.com/16351105/58887457-3cc4b500-8718-11e9-9417-2bdea603c92e.png) +![](https://cdn.jsdelivr.net/gh/jerryc127/CDN/img/theme-butterfly-readme-homepage-2.png) -![](https://user-images.githubusercontent.com/16351105/69338594-7d03f980-0c9e-11ea-8b64-7f165e6508e2.png) \ No newline at end of file +![](https://cdn.jsdelivr.net/gh/jerryc127/CDN/img/theme-butterfly-readme-post.png) diff --git a/README_CN.md b/README_CN.md index 6d4750a..b8b7890 100644 --- a/README_CN.md +++ b/README_CN.md @@ -2,9 +2,8 @@ ![version](https://img.shields.io/github/package-json/v/jerryc127/hexo-theme-butterfly) ![https://img.shields.io/npm/v/hexo-theme-butterfly?color=%09%23bf00ff](https://img.shields.io/npm/v/hexo-theme-butterfly?color=%09%23bf00ff) -![hexo version](https://img.shields.io/badge/hexo-4.0+-0e83c) +![hexo version](https://img.shields.io/badge/hexo-4.2+-0e83c) ![npm download](https://img.shields.io/npm/dw/hexo-theme-butterfly?color=green) -![nodejs version](https://img.shields.io/badge/node.js-8.0+-yellow) ![license](https://img.shields.io/github/license/jerryc127/hexo-theme-butterfly?color=FF5531) @@ -49,9 +48,49 @@ theme: butterfly >如果你沒有pug以及stylus的渲染器,請下載安裝: npm install hexo-renderer-pug hexo-renderer-stylus --save +## 特色 + +- [x] 卡片化設計 +- [X] 支持二級目錄 +- [x] 雙欄設計 +- [x] 響應式主題 +- [x] 夜間模式 +- [x] Pjax +- [x] 文章閲讀模式 +- [x] 簡體和繁體轉換 +- [X] 電腦和手機都可查看TOC目錄 +- [X] 內置多種代碼配色(darker/pale night/light/ocean/mac/mac light),可自定義代碼配色 +- [X] 代碼塊顯示代碼語言/關閉或展開代碼塊/代碼複製/代碼自動換行 +- [X] 可關閉文字複製/可開啟內容複製增加版權信息) +- [X] 兩種搜索(Algolia搜索和本地搜索) +- [x] Mathjax 和 Katex +- [x] 內置404頁面 +- [x] 顯示字數統計 +- [x] 顯示相關文章 +- [x] 過期文章提醒 +- [x] 多種分享系統(AddThis/Sharejs/Addtoany) +- [X] 多種評論系統(Disqus/Disqusjs/Livere/Gitalk/Valine/Utterances/Facebook Comments) +- [x] 支持雙評論部署 +- [x] 多種在線聊天(Chatra/Tidio/Daovoice/Gitter/Crisp) +- [x] 多種分析系統(百度分析/谷歌分析/騰訊分析/CNZZ分析) +- [x] 谷歌廣告/手動廣告位置 +- [x] 各種站長驗證(Google/Bing/Baidu/360/Yandex) +- [x] 修改網站配色 +- [x] 打字特效 activate_power_mode +- [x] 多種背景特效(靜止彩帶/動態彩帶/Canvas Nest) +- [x] 多種鼠標點擊特效(煙花/文字/愛心) +- [x] 內置一種 Preloader 加載動畫 +- [x] 不蒜子訪問統計 +- [x] 兩種大圖模式(Medium Zoom/Fancybox) +- [x] Mermaid 圖表顯示 +- [x] 照片牆 +- [x] 圖片懶加載 +- [x] Instantpage/Pangu/Snackbar彈窗/PWA...... + ## 截圖 -![image](https://user-images.githubusercontent.com/16351105/58887365-1272f780-8718-11e9-9329-3292c6ba20d4.png) -![image](https://user-images.githubusercontent.com/16351105/58887457-3cc4b500-8718-11e9-9417-2bdea603c92e.png) +![](https://cdn.jsdelivr.net/gh/jerryc127/CDN/img/theme-butterfly-readme-homepage-1.png) -![](https://user-images.githubusercontent.com/16351105/69338594-7d03f980-0c9e-11ea-8b64-7f165e6508e2.png) \ No newline at end of file +![](https://cdn.jsdelivr.net/gh/jerryc127/CDN/img/theme-butterfly-readme-homepage-2.png) + +![](https://cdn.jsdelivr.net/gh/jerryc127/CDN/img/theme-butterfly-readme-post.png) diff --git a/_config.yml b/_config.yml index a91983a..338d7ec 100644 --- a/_config.yml +++ b/_config.yml @@ -17,10 +17,13 @@ menu: # Link: /link/ || fas fa-link # About: /about/ || fas fa-heart +# Hide the child menu items in mobile sidebar +hide_sidebar_menu_child: false + # Code Blocks (代碼相關) # -------------------------------------- -highlight_theme: light # default / darker / pale night / light / ocean / mac / mac light / false +highlight_theme: light # darker / pale night / light / ocean / mac / mac light / false highlight_copy: true # copy button highlight_lang: true # show the code language highlight_shrink: false # true: shrink the code blocks / false: expand the code blocks | none: expand code blocks and hide the button @@ -88,14 +91,14 @@ favicon: /img/favicon.png # Avatar (頭像) avatar: - img: /img/avatar.png + img: effect: false # the banner image of home page index_img: # if the banner of page not setting, it will show the top_img -default_top_img: https://i.loli.net/2020/05/01/IuWi8QbHvzjlOPw.jpg +default_top_img: # the banner image of archive page archive_img: @@ -125,7 +128,7 @@ cover: position: both # When cover is not set, the default cover is displayed (當沒有設置cover時,默認的封面顯示) default_cover: - - https://i.loli.net/2020/05/01/gkihqEjXxJ5UZ1C.jpg + # - https://i.loli.net/2020/05/01/gkihqEjXxJ5UZ1C.jpg # Replace Broken Images (替換無法顯示的圖片) error_img: @@ -232,14 +235,7 @@ sharejs: # https://www.addtoany.com/ addtoany: enable: false - item: - - facebook - - twitter - - wechat - - sina_weibo - - facebook_messenger - - email - - copy_link + item: facebook,twitter,wechat,sina_weibo,facebook_messenger,email,copy_link # Comments System # -------------------------------------- @@ -374,7 +370,7 @@ footer: owner: enable: true since: 2020 - custom_text: + custom_text: copyright: true # Copyright of theme and framework ICP: # Chinese ICP License enable: false @@ -386,14 +382,21 @@ footer: # -------------------------------------- # Baidu Analytics +# https://tongji.baidu.com/web/welcome/login baidu_analytics: # Google 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: + # Advertisement # -------------------------------------- @@ -528,9 +531,9 @@ click_heart: false ClickShowText: enable: false text: - - I - - LOVE - - YOU + # - I + # - LOVE + # - YOU fontSize: 15px # Default display mode (網站默認的顯示模式) @@ -547,14 +550,16 @@ beautify: # Global font settings # Don't modify the following settings unless you know how they work (非必要不要修改) font: + global-font-size: + code-font-size: font-family: - code-font: + code-font-family: # Font settings for the site title and site subtitle # 左上角網站名字 主頁居中網站名字 -blog_title_font: - font_link: https://fonts.googleapis.com/css?family=Titillium+Web&display=swap - font-family: Titillium Web, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif +# blog_title_font: + # font_link: https://fonts.googleapis.com/css?family=Titillium+Web&display=swap + # font-family: Titillium Web, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif # The setting of divider icon (水平分隔線圖標設置) hr_icon: @@ -621,7 +626,10 @@ aside: format: MMMM YYYY # eg: YYYY年MM月 order: -1 # Sort of order. 1, asc for ascending; -1, desc for descending limit: 8 # if set 0 will show all - card_webinfo: true + card_webinfo: + enable: true + post_count: true + last_push_date: true # busuanzi count for PV / UV in site # 訪問人數 @@ -636,6 +644,25 @@ runtimeshow: enable: false publish_date: +# Aside widget - Newest Comments +newest_comments: + enable: false + limit: 6 + avatar: true + leancloud: + enable: false + appId: # leancloud application app id + appKey: # leancloud application app key + serverURL: # This configuration is suitable for domestic custom domain name users, overseas version will be automatically detected (no need to manually fill in) + default_avatar: # mp/identicon/monsterid/wavatar/retro/robohash/blank + github_issues: + enable: false + repo: + disqus: + enable: false + forum: + api_key: + # Bottom right button (右下角按鈕) # -------------------------------------- @@ -709,7 +736,11 @@ note: # Pjax [Beta] # It may contain bugs and unstable, give feedback when you find the bugs. # https://github.com/MoOx/pjax -pjax: false +pjax: + enable: false + exclude: + # - xxxx + # - xxxx # Inject the css and script (aplayer/meting) aplayerInject: @@ -731,7 +762,7 @@ baidu_push: false # https://instant.page/ # prefetch (預加載) -instantpage: true +instantpage: false # https://github.com/vinta/pangu.js # Insert a space between Chinese character and English character (中英文之間添加空格) @@ -742,7 +773,7 @@ pangu: # Lazyload (圖片懶加載) # https://github.com/verlok/lazyload lazyload: - enable: true + enable: false post: /img/loading.gif # PWA @@ -751,7 +782,6 @@ lazyload: # pwa: # enable: false # manifest: /image/pwa/manifest.json -# theme_color: "#fff" # apple_touch_icon: /image/pwa/apple-touch-icon.png # favicon_32_32: /image/pwa/32.png # favicon_16_16: /image/pwa/16.png @@ -858,3 +888,8 @@ CDN: 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 diff --git a/languages/default.yml b/languages/default.yml index e3a5524..53d40e7 100644 --- a/languages/default.yml +++ b/languages/default.yml @@ -65,11 +65,25 @@ aside: card_webinfo: headline: Info article_name: Article - runtime_name: Run time + runtime: + name: Run time + unit: days + last_push_date: + name: Last Push site_wordcount: Total Count site_uv_name: UV site_pv_name: PV more_button: More + card_newest_comments: + heading: Newest Comments + loading_text: loading... + zero_day: Today + day: days ago + +date_suffix: + one_hour: Just + hours: hours ago + day: days ago donate: Donate share: Share @@ -87,8 +101,6 @@ rightside: scroll_to_comment: Scroll To Comments setting: Setting -runtime_unit: days - copy_copyright: author: Author link: Link diff --git a/languages/en.yml b/languages/en.yml index e3a5524..53d40e7 100644 --- a/languages/en.yml +++ b/languages/en.yml @@ -65,11 +65,25 @@ aside: card_webinfo: headline: Info article_name: Article - runtime_name: Run time + runtime: + name: Run time + unit: days + last_push_date: + name: Last Push site_wordcount: Total Count site_uv_name: UV site_pv_name: PV more_button: More + card_newest_comments: + heading: Newest Comments + loading_text: loading... + zero_day: Today + day: days ago + +date_suffix: + one_hour: Just + hours: hours ago + day: days ago donate: Donate share: Share @@ -87,8 +101,6 @@ rightside: scroll_to_comment: Scroll To Comments setting: Setting -runtime_unit: days - copy_copyright: author: Author link: Link diff --git a/languages/zh-CN.yml b/languages/zh-CN.yml index ae6b207..0b10cbc 100644 --- a/languages/zh-CN.yml +++ b/languages/zh-CN.yml @@ -67,11 +67,25 @@ aside: card_webinfo: headline: 网站资讯 article_name: 文章数目 - runtime_name: 已运行时间 + runtime: + name: 已运行时间 + unit: 天 + last_push_date: + name: 最后更新时间 site_wordcount: 本站总字数 site_uv_name: 本站访客数 site_pv_name: 本站总访问量 more_button: 查看更多 + card_newest_comments: + heading: 最新评论 + loading_text: 正在加载中... + zero_day: 今天 + day: 天前 + +date_suffix: + one_hour: 刚刚 + hours: 小时前 + day: 天前 donate: 打赏 share: 分享 @@ -89,8 +103,6 @@ rightside: scroll_to_comment: 直达评论 setting: 设置 -runtime_unit: 天 - copy_copyright: author: 作者 link: 链接 @@ -106,7 +118,6 @@ Snackbar: day_to_night: 你已切换为深色模式 night_to_day: 你已切换为浅色模式 -error_title: 页面没有找到 loading: 加载中... error404: diff --git a/languages/zh-TW.yml b/languages/zh-TW.yml index 74902a2..47f6d86 100644 --- a/languages/zh-TW.yml +++ b/languages/zh-TW.yml @@ -67,11 +67,25 @@ aside: card_webinfo: headline: 網站資訊 article_name: 文章數目 - runtime_name: 已執行時間 + runtime: + name: 已運行時間 + unit: 天 + last_push_date: + name: 最後更新時間 site_wordcount: 本站總字數 site_uv_name: 本站訪客數 site_pv_name: 本站總訪問量 more_button: 檢視更多 + card_newest_comments: + heading: 最新評論 + loading_text: 正在加載中... + zero_day: 今天 + day: 天前 + +date_suffix: + one_hour: 剛剛 + hours: 小時前 + day: 天前 donate: 打賞 share: 分享 @@ -89,8 +103,6 @@ rightside: scroll_to_comment: 直達評論 setting: 設定 -runtime_unit: 天 - copy_copyright: author: 作者 link: 連結 diff --git a/layout/includes/additional-js.pug b/layout/includes/additional-js.pug index 2e00ca6..0979f90 100644 --- a/layout/includes/additional-js.pug +++ b/layout/includes/additional-js.pug @@ -15,7 +15,7 @@ div script(src=url_for(theme.CDN.instantpage) type="module" defer) if theme.lazyload.enable - script(src=url_for(theme.CDN.lazyload) async) + script(src=url_for(theme.CDN.lazyload)) if (theme.snackbar && theme.snackbar.enable) script(src=url_for(theme.CDN.snackbar)) @@ -44,6 +44,14 @@ div if theme.busuanzi.site_uv || theme.busuanzi.site_pv || theme.busuanzi.page_pv script(async src=url_for(theme.CDN.busuanzi)) + !=partial('includes/third-party/prismjs', {}, {cache:theme.fragment_cache}) + + if theme.aside.enable && theme.newest_comments.enable + if theme.pjax.enable + !=partial('includes/third-party/newest-comments/index', {}, {cache:theme.fragment_cache}) + else if (!is_post() && page.aside !== false) + !=partial('includes/third-party/newest-comments/index', {}, {cache:theme.fragment_cache}) + !=fragment_cache('injectBottom', function(){return injectHtml(theme.inject.bottom)}) !=partial('includes/third-party/effect', {}, {cache:theme.fragment_cache}) @@ -51,11 +59,10 @@ div !=partial('includes/third-party/chat/index', {}, {cache:theme.fragment_cache}) if theme.aplayerInject && theme.aplayerInject.enable - if theme.pjax || theme.aplayerInject.per_page + if theme.pjax.enable || theme.aplayerInject.per_page include ./head/aplayer.pug else if page.aplayer include ./head/aplayer.pug - if theme.pjax - !=partial('includes/third-party/pjax', {}, {cache:theme.fragment_cache}) - + if theme.pjax.enable + !=partial('includes/third-party/pjax', {}, {cache:theme.fragment_cache}) \ No newline at end of file diff --git a/layout/includes/head.pug b/layout/includes/head.pug index ea3808f..84374ab 100644 --- a/layout/includes/head.pug +++ b/layout/includes/head.pug @@ -17,6 +17,7 @@ - else pageKeywords = Array.isArray(config.keywords) ? (config.keywords).join(','): ([]).join(',') || config.keywords - var pageAuthor = config.email ? config.author + ',' + config.email : config.author - var pageCopyright = config.copyright || config.author +- var themeColor = theme.display_mode === 'dark' ? '#0d0d0d' : '#ffffff' meta(charset='UTF-8') meta(http-equiv="X-UA-Compatible" content="IE=edge") @@ -28,13 +29,15 @@ if pageKeywords meta(name="author" content=pageAuthor) meta(name="copyright" content=pageCopyright) meta(name ="format-detection" content="telephone=no") -!=favicon_tag(theme.favicon || config.favicon) -link(rel="canonical" href=urlNoIndex()) +meta(name="theme-color" content=themeColor) if theme.disable_baidu_transformation meta(http-equiv="Cache-Control" content="no-transform") meta(http-equiv="Cache-Control" content="no-siteapp") +!=favicon_tag(theme.favicon || config.favicon) +link(rel="canonical" href=urlNoIndex()) + //- 預解析 !=partial('includes/head/preconnect', {}, {cache:theme.fragment_cache}) @@ -53,9 +56,6 @@ if theme.facebook_comments.user_id if (theme.pwa && theme.pwa.enable) !=partial('includes/head/pwa', {}, {cache:theme.fragment_cache}) -if theme.darkmode.enable - !=partial('includes/head/darkmode', {}, {cache:theme.fragment_cache}) - //- main css link(rel='stylesheet', href=url_for(theme.CDN.main_css)) link(rel='stylesheet', href=url_for(theme.CDN.fontawesome)) @@ -77,7 +77,7 @@ if theme.algolia_search.enable !=partial('includes/head/analytics', {}, {cache:theme.fragment_cache}) //- font -if theme.blog_title_font.font_link +if theme.blog_title_font && theme.blog_title_font.font_link link(rel='stylesheet' href=url_for(theme.blog_title_font.font_link)) //- global config @@ -86,5 +86,7 @@ if theme.blog_title_font.font_link include ./head/config_site.pug include ./head/noscript.pug +!=partial('includes/head/darkmode', {}, {cache:theme.fragment_cache}) + !=fragment_cache('injectHead', function(){return injectHtml(theme.inject.head)}) diff --git a/layout/includes/head/analytics.pug b/layout/includes/head/analytics.pug index 01b0469..f4379b5 100644 --- a/layout/includes/head/analytics.pug +++ b/layout/includes/head/analytics.pug @@ -17,4 +17,16 @@ if theme.google_analytics gtag('config', '!{theme.google_analytics}'); if theme.tencent_analytics - script(src=`https://tajs.qq.com/stats?sId=${theme.tencent_analytics}` charset="UTF-8" data-pjax) + 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 61c26ea..1e4e492 100644 --- a/layout/includes/head/config.pug +++ b/layout/includes/head/config.pug @@ -1,6 +1,6 @@ - - var algolia = 'undefined'; - var env = process.env; + let algolia = 'undefined'; + let env = process.env; if (theme.algolia_search.enable) { algolia = JSON.stringify({ appId: env.ALGOLIA_APP_ID || config.algolia.appId || config.algolia.applicationID, @@ -16,7 +16,7 @@ }) } - var localSearch = 'undefined'; + let localSearch = 'undefined'; if (theme.local_search && theme.local_search.enable) { localSearch = JSON.stringify({ path: config.search.path, @@ -26,7 +26,8 @@ } }) } - var translate = 'undefined'; + + let translate = 'undefined'; if (theme.translate && theme.translate.enable){ translate = JSON.stringify({ defaultEncoding: theme.translate.defaultEncoding, @@ -36,7 +37,7 @@ }) } - var copyright = 'undefined'; + let copyright = 'undefined'; if (theme.copy.enable && theme.copy.copyright.enable){ copyright = JSON.stringify({ limitCount: theme.copy.copyright.limit_count, @@ -49,7 +50,7 @@ }) } - var ClickShowText = 'undefined'; + let ClickShowText = 'undefined'; if (theme.ClickShowText && theme.ClickShowText.enable) { ClickShowText = JSON.stringify({ text: theme.ClickShowText.text.join(","), @@ -58,24 +59,24 @@ } - var Snackbar = 'undefined'; + let Snackbar = 'undefined'; if (theme.snackbar && theme.snackbar.enable) { - Snackbar = JSON.stringify({ - bookmark: { - message_prev: _p("Snackbar.bookmark.message_prev"), - message_next: _p("Snackbar.bookmark.message_next") - }, - chs_to_cht: _p("Snackbar.chs_to_cht"), - cht_to_chs: _p("Snackbar.cht_to_chs"), - day_to_night: _p("Snackbar.day_to_night"), - night_to_day: _p("Snackbar.night_to_day"), - bgLight: theme.snackbar.bg_light, - bgDark: theme.snackbar.bg_dark, - position: theme.snackbar.position, + Snackbar = JSON.stringify({ + bookmark: { + message_prev: _p("Snackbar.bookmark.message_prev"), + message_next: _p("Snackbar.bookmark.message_next") + }, + chs_to_cht: _p("Snackbar.chs_to_cht"), + cht_to_chs: _p("Snackbar.cht_to_chs"), + day_to_night: _p("Snackbar.day_to_night"), + night_to_day: _p("Snackbar.night_to_day"), + bgLight: theme.snackbar.bg_light, + bgDark: theme.snackbar.bg_dark, + position: theme.snackbar.position, }) } - var noticeOutdate = 'undefined'; + let noticeOutdate = 'undefined'; if (theme.noticeOutdate && theme.noticeOutdate.enable) { noticeOutdate = JSON.stringify({ limitDay: theme.noticeOutdate.limit_day, @@ -85,6 +86,25 @@ }) } + let highlight = 'undefined'; + if ((config.highlight && config.highlight.enable) || (config.prismjs && config.prismjs.enable)) { + highlight = JSON.stringify({ + plugin: config.highlight.enable ? 'highlighjs' : 'prismjs', + highlightCopy: theme.highlight_copy, + highlightLang: theme.highlight_lang + }) + } + + let date_suffix = 'undefined'; + if (theme.aside.card_webinfo.last_push_date) { + date_suffix = JSON.stringify({ + one_hour: _p("date_suffix.one_hour"), + hours: _p("date_suffix.hours"), + day: _p('date_suffix.day') + + }) + } + script. var GLOBAL_CONFIG = { root: '!{config.root}', @@ -93,6 +113,7 @@ script. localSearch: !{localSearch}, translate: !{translate}, noticeOutdate: !{noticeOutdate}, + highlight: !{highlight}, copy: { success: '!{_p("copy.success")}', error: '!{_p("copy.error")}', @@ -102,8 +123,8 @@ script. message_prev: '!{_p("Snackbar.bookmark.message_prev")}', message_next: '!{_p("Snackbar.bookmark.message_next")}' }, - runtime_unit: '!{_p("runtime_unit")}', - runtime: !{theme.runtimeshow.enable}, + runtime: '!{theme.runtimeshow.enable ? _p("aside.card_webinfo.runtime.unit") : ""}', + date_suffix: !{date_suffix}, copyright: !{copyright}, ClickShowText: !{ClickShowText}, medium_zoom: !{theme.medium_zoom}, @@ -114,10 +135,38 @@ script. css: '!{theme.CDN.justifiedGallery_css}' }, baiduPush: !{theme.baidu_push}, - highlightCopy: !{theme.highlight_copy}, - highlightLang: !{theme.highlight_lang}, isPhotoFigcaption: !{theme.photofigcaption}, islazyload: !{theme.lazyload.enable}, - isanchor: !{theme.anchor} + isanchor: !{theme.anchor} + }; + + var saveToLocal = { + set: function setWithExpiry(key, value, ttl) { + const now = new Date() + const expiryDay = ttl * 86400000 + const item = { + value: value, + expiry: now.getTime() + expiryDay, + } + localStorage.setItem(key, JSON.stringify(item)) + }, + + get: function getWithExpiry(key) { + const itemStr = localStorage.getItem(key) + + if (!itemStr) { + return undefined + } + const item = JSON.parse(itemStr) + const now = new Date() + + if (now.getTime() > item.expiry) { + localStorage.removeItem(key) + return undefined + } + return item.value + } } + + diff --git a/layout/includes/head/darkmode.pug b/layout/includes/head/darkmode.pug index cc1a27b..c3e775d 100644 --- a/layout/includes/head/darkmode.pug +++ b/layout/includes/head/darkmode.pug @@ -1,56 +1,50 @@ -script. - var activateDarkMode = function () { - document.documentElement.setAttribute('data-theme', 'dark') - if (document.querySelector('meta[name="theme-color"]') !== null) { - document.querySelector('meta[name="theme-color"]').setAttribute('content', '#000') - } - } - var activateLightMode = function () { - document.documentElement.setAttribute('data-theme', 'light') - if (document.querySelector('meta[name="theme-color"]') !== null) { - document.querySelector('meta[name="theme-color"]').setAttribute('content', '#fff') - } - } - - var getCookies = function (name) { - const value = `; ${document.cookie}` - const parts = value.split(`; ${name}=`) - if (parts.length === 2) return parts.pop().split(';').shift() - } - - var autoChangeMode = '#{theme.darkmode.autoChangeMode}' - var t = getCookies('theme') - if (autoChangeMode === '1') { - var isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches - var isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches - var isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches - var hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified - - if (t === undefined) { - if (isLightMode) activateLightMode() - else if (isDarkMode) activateDarkMode() - else if (isNotSpecified || hasNoSupport) { - console.log('You specified no preference for a color scheme or your browser does not support it. I Schedule dark mode during night time.') - var now = new Date() - var hour = now.getHours() - var isNight = hour <= 6 || hour >= 18 - isNight ? activateDarkMode() : activateLightMode() +if theme.darkmode.enable + script. + var activateDarkMode = function () { + document.documentElement.setAttribute('data-theme', 'dark') + if (document.querySelector('meta[name="theme-color"]') !== null) { + document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d') } - window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) { - if (Cookies.get('theme') === undefined) { - e.matches ? activateDarkMode() : activateLightMode() + } + var activateLightMode = function () { + document.documentElement.setAttribute('data-theme', 'light') + if (document.querySelector('meta[name="theme-color"]') !== null) { + document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff') + } + } + + var autoChangeMode = '#{theme.darkmode.autoChangeMode}' + var t = saveToLocal.get('theme') + if (autoChangeMode === '1') { + var isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches + var isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches + var isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches + var hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified + + if (t === undefined) { + if (isLightMode) activateLightMode() + else if (isDarkMode) activateDarkMode() + else if (isNotSpecified || hasNoSupport) { + var now = new Date() + var hour = now.getHours() + var isNight = hour <= 6 || hour >= 18 + isNight ? activateDarkMode() : activateLightMode() } - }) - } else if (t === 'light') activateLightMode() - else activateDarkMode() - } else if (autoChangeMode === '2') { - now = new Date() - hour = now.getHours() - isNight = hour <= 6 || hour >= 18 - if (t === undefined) isNight ? activateDarkMode() : activateLightMode() - else if (t === 'light') activateLightMode() - else activateDarkMode() - } else { - if (t === 'dark') activateDarkMode() - else if (t === 'light') activateLightMode() - } + window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) { + if (saveToLocal.get('theme') === undefined) { + e.matches ? activateDarkMode() : activateLightMode() + } + }) + } else if (t === 'light') activateLightMode() + else activateDarkMode() + } else if (autoChangeMode === '2') { + now = new Date() + hour = now.getHours() + isNight = hour <= 6 || hour >= 18 + if (t === undefined) isNight ? activateDarkMode() : activateLightMode() + else if (t === 'light') activateLightMode() + else activateDarkMode() + } else { + if (t === 'dark') activateDarkMode() + else if (t === 'light') activateLightMode() + } diff --git a/layout/includes/head/noscript.pug b/layout/includes/head/noscript.pug index bf995d7..b0f6e1d 100644 --- a/layout/includes/head/noscript.pug +++ b/layout/includes/head/noscript.pug @@ -1,5 +1,5 @@ noscript. -