diff --git a/_config.yml b/_config.yml index d0ba6de..b3f79af 100644 --- a/_config.yml +++ b/_config.yml @@ -13,6 +13,11 @@ menu: # Link: /link/ || fas fa-link # About: /about/ || fas fa-heart +nav: + logo: # image + display_title: true + fixed: false # fixed navigation bar + # Code Blocks (代碼相關) # -------------------------------------- @@ -185,6 +190,7 @@ toc: number: true expand: false style_simple: false # for post + scroll_percent: true post_copyright: enable: true @@ -396,7 +402,7 @@ tidio: public_key: # daovoice -# http://daovoice.io/ +# http://dashboard.daovoice.io/app daovoice: enable: false app_id: @@ -440,10 +446,6 @@ baidu_analytics: # https://analytics.google.com/analytics/web/ google_analytics: -# CNZZ Analytics -# https://www.umeng.com/ -cnzz_analytics: - # Cloudflare Analytics # https://www.cloudflare.com/zh-tw/web-analytics/ cloudflare_analytics: @@ -632,7 +634,7 @@ subtitle: # source 調用第三方服務 # source: false 關閉調用 # source: 1 調用一言網的一句話(簡體) https://hitokoto.cn/ - # source: 2 調用一句網(簡體) http://yijuzhan.com/ + # source: 2 調用一句網(簡體) https://yijuzhan.com/ # source: 3 調用今日詩詞(簡體) https://www.jinrishici.com/ # subtitle 會先顯示 source , 再顯示 sub 的內容 source: false @@ -753,6 +755,9 @@ darkmode: # autoChangeMode: false autoChangeMode: false +# show scroll percent in scroll-to-top button +rightside_scroll_percent: false + # Don't modify the following settings unless you know how they work (非必要請不要修改 ) # Choose: readmode,translate,darkmode,hideAside,toc,chat,comment # Don't repeat 不要重複 @@ -894,7 +899,7 @@ CDN: # when set it to local, you need to install hexo-butterfly-extjs third_party_provider: jsdelivr - # Add version number to CDN, true or false + # Add version number to CDN, true or false version: false # Custom format @@ -952,4 +957,4 @@ CDN: # prismjs_lineNumber_js: # prismjs_autoloader: # artalk_js: - # artalk_css: \ No newline at end of file + # artalk_css: diff --git a/languages/default.yml b/languages/default.yml index 833fb6c..a491719 100644 --- a/languages/default.yml +++ b/languages/default.yml @@ -117,5 +117,6 @@ Snackbar: night_to_day: Light Mode Activated Manually loading: Loading... +load_more: Load More error404: Page not found diff --git a/languages/en.yml b/languages/en.yml index 9d303e0..49120c2 100644 --- a/languages/en.yml +++ b/languages/en.yml @@ -117,5 +117,6 @@ Snackbar: night_to_day: Light Mode Activated Manually loading: Loading... +load_more: Load More error404: Page not found diff --git a/languages/zh-CN.yml b/languages/zh-CN.yml index 55900d2..9c2919a 100644 --- a/languages/zh-CN.yml +++ b/languages/zh-CN.yml @@ -118,5 +118,6 @@ Snackbar: night_to_day: 你已切换为浅色模式 loading: 加载中... +load_more: 加载更多 error404: 页面没有找到 diff --git a/languages/zh-TW.yml b/languages/zh-TW.yml index 61d667f..86623c0 100644 --- a/languages/zh-TW.yml +++ b/languages/zh-TW.yml @@ -118,5 +118,6 @@ Snackbar: night_to_day: 你已切換為淺色模式 loading: 載入中... +load_more: 載入更多 error404: 頁面沒有找到 diff --git a/layout/includes/additional-js.pug b/layout/includes/additional-js.pug index 3ef0223..4ec9ac1 100644 --- a/layout/includes/additional-js.pug +++ b/layout/includes/additional-js.pug @@ -66,4 +66,4 @@ div != partial("includes/third-party/pjax", {}, { cache: true }) if theme.busuanzi.site_uv || theme.busuanzi.site_pv || theme.busuanzi.page_pv - script(async data-pjax src='//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js') + script(async data-pjax src= theme.asset.busuanzi || '//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js') diff --git a/layout/includes/head.pug b/layout/includes/head.pug index d8ff883..0089ad2 100644 --- a/layout/includes/head.pug +++ b/layout/includes/head.pug @@ -15,7 +15,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, maximum-scale=1.0, user-scalable=no") +meta(name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0") title= tabTitle meta(name="author" content=pageAuthor) meta(name="copyright" content=pageCopyright) @@ -26,7 +26,7 @@ meta(name="theme-color" content=themeColor) include ./head/Open_Graph.pug !=favicon_tag(theme.favicon || config.favicon) -link(rel="canonical" href=urlNoIndex()) +link(rel="canonical" href=urlNoIndex(null,config.pretty_urls.trailing_index,config.pretty_urls.trailing_html)) //- 預解析 !=partial('includes/head/preconnect', {}, {cache: true}) diff --git a/layout/includes/head/Open_Graph.pug b/layout/includes/head/Open_Graph.pug index 1d04b47..8fe04e0 100644 --- a/layout/includes/head/Open_Graph.pug +++ b/layout/includes/head/Open_Graph.pug @@ -1,8 +1,9 @@ if theme.Open_Graph_meta.enable - + const coverVal = page.cover_type === 'img' ? page.cover : theme.avatar.img let ogOption = Object.assign({ type: is_post() ? 'article' : 'website', - image: (page.cover || theme.avatar.img) ? full_url_for(page.cover || theme.avatar.img) : '', + image: coverVal ? full_url_for(coverVal) : '', fb_admins: theme.facebook_comments.user_id || '', fb_app_id: theme.facebook_comments.app_id || '', }, theme.Open_Graph_meta.option) diff --git a/layout/includes/head/analytics.pug b/layout/includes/head/analytics.pug index 6452528..ad4a395 100644 --- a/layout/includes/head/analytics.pug +++ b/layout/includes/head/analytics.pug @@ -16,9 +16,6 @@ if theme.google_analytics gtag('js', new Date()); gtag('config', '!{theme.google_analytics}'); -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}`) - if theme.cloudflare_analytics script(defer data-pjax src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon=`{"token": "${theme.cloudflare_analytics}"}`) diff --git a/layout/includes/head/config.pug b/layout/includes/head/config.pug index 5a8b8f5..ed81219 100644 --- a/layout/includes/head/config.pug +++ b/layout/includes/head/config.pug @@ -120,5 +120,9 @@ script. }, isPhotoFigcaption: !{theme.photofigcaption}, islazyload: !{theme.lazyload.enable}, - isAnchor: !{theme.anchor.auto_update || false} + isAnchor: !{theme.anchor.auto_update || false}, + percent: { + toc: !{theme.toc.scroll_percent}, + rightside: !{theme.rightside_scroll_percent}, + } } diff --git a/layout/includes/head/preconnect.pug b/layout/includes/head/preconnect.pug index d010b05..04d3b48 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.cnzz_analytics - link(rel="preconnect" href="//s4.cnzz.com") - if theme.cloudflare_analytics link(rel="preconnect" href="//static.cloudflareinsights.com") @@ -18,5 +15,5 @@ if theme.microsoft_clarity if theme.blog_title_font && theme.blog_title_font.font_link && theme.blog_title_font.font_link.indexOf('//fonts.googleapis.com') != -1 link(rel="preconnect" href="//fonts.googleapis.com" crossorigin='') -if theme.busuanzi.site_uv || theme.busuanzi.site_pv || theme.busuanzi.page_pv +if !theme.asset.busuanzi && (theme.busuanzi.site_uv || theme.busuanzi.site_pv || theme.busuanzi.page_pv) link(rel="preconnect" href="//busuanzi.ibruce.info") \ No newline at end of file diff --git a/layout/includes/header/index.pug b/layout/includes/header/index.pug index d1aa7c0..df6f3da 100644 --- a/layout/includes/header/index.pug +++ b/layout/includes/header/index.pug @@ -1,6 +1,6 @@ if !theme.disable_top_img && page.top_img !== false if is_post() - - var top_img = page.top_img || page.cover || page.randomcover + - var top_img = page.top_img || page.cover || theme.default_top_img else if is_page() - var top_img = page.top_img || theme.default_top_img else if is_tag() @@ -17,7 +17,7 @@ if !theme.disable_top_img && page.top_img !== false - var top_img = page.top_img || theme.default_top_img if top_img !== false - - var imgSource = top_img && top_img.indexOf('/') !== -1 ? `background-image: url('${url_for(top_img)}')` : `background: ${top_img}` + - var imgSource = top_img && isImgOrUrl(top_img) ? `background-image: url('${url_for(top_img)}')` : `background: ${top_img}` - var bg_img = top_img ? imgSource : '' - var site_title = page.title || page.tag || page.category || config.title - var isHomeClass = is_home() ? 'full_page' : 'not-home-page' diff --git a/layout/includes/header/nav.pug b/layout/includes/header/nav.pug index 7b516e9..a81a2a3 100644 --- a/layout/includes/header/nav.pug +++ b/layout/includes/header/nav.pug @@ -1,17 +1,22 @@ -nav#nav - span#blog_name - a#site-name(href=url_for('/')) #[=config.title] +- const isFixedClass = theme.nav.fixed ? 'fixed' : '' +nav#nav(class=isFixedClass) + span#blog-info + a(href=url_for('/') title=config.title) + if theme.nav.logo + img.site-icon(src=url_for(theme.nav.logo)) + if theme.nav.display_title + span.site-name=config.title #menus if (theme.algolia_search.enable || theme.local_search.enable) #search-button - a.site-page.social-icon.search + a.site-page.social-icon.search(href="javascript:void(0);") i.fas.fa-search.fa-fw span=' '+_p('search.title') !=partial('includes/header/menu_item', {}, {cache: true}) #toggle-menu - a.site-page + a.site-page(href="javascript:void(0);") i.fas.fa-bars.fa-fw diff --git a/layout/includes/layout.pug b/layout/includes/layout.pug index eb1dfe1..dcd2c54 100644 --- a/layout/includes/layout.pug +++ b/layout/includes/layout.pug @@ -33,7 +33,7 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside if (footerBg === true) - var footer_bg = bg_img else - - var footer_bg = theme.footer_bg.indexOf('/') !== -1 ? `background-image: url('${url_for(footerBg)}')` : `background: ${footerBg}` + - var footer_bg = isImgOrUrl(theme.footer_bg) ? `background-image: url('${url_for(footerBg)}')` : `background: ${footerBg}` else - var footer_bg = '' diff --git a/layout/includes/mixins/article-sort.pug b/layout/includes/mixins/article-sort.pug index 01e9ef2..3eaf038 100644 --- a/layout/includes/mixins/article-sort.pug +++ b/layout/includes/mixins/article-sort.pug @@ -11,7 +11,10 @@ mixin articleSort(posts) .article-sort-item(class=no_cover) if article.cover && theme.cover.archives_enable a.article-sort-item-img(href=url_for(article.path) title=title) - img(src=url_for(article.cover) alt=title onerror=`this.onerror=null;this.src='${url_for(theme.error_img.post_page)}'`) + if article.cover_type === 'img' + img(src=url_for(article.cover) alt=title onerror=`this.onerror=null;this.src='${url_for(theme.error_img.post_page)}'`) + else + div(style=`background: ${article.cover}`) .article-sort-item-info .article-sort-item-time i.far.fa-calendar-alt diff --git a/layout/includes/mixins/post-ui.pug b/layout/includes/mixins/post-ui.pug index 3dd364d..4ed053b 100644 --- a/layout/includes/mixins/post-ui.pug +++ b/layout/includes/mixins/post-ui.pug @@ -14,7 +14,10 @@ mixin postUI(posts) if post_cover && theme.cover.index_enable .post_cover(class=leftOrRight) a(href=url_for(link) title=title) - img.post_bg(src=url_for(post_cover) onerror=`this.onerror=null;this.src='`+ url_for(theme.error_img.post_page) + `'` alt=title) + if article.cover_type === 'img' + img.post-bg(src=url_for(post_cover) onerror=`this.onerror=null;this.src='${url_for(theme.error_img.post_page)}'` alt=title) + else + div.post-bg(style=`background: ${post_cover}`) .recent-post-info(class=no_cover) a.article-title(href=url_for(link) title=title)= title .article-meta-wrap diff --git a/layout/includes/page/flink.pug b/layout/includes/page/flink.pug index 8ec4ed6..549b67a 100644 --- a/layout/includes/page/flink.pug +++ b/layout/includes/page/flink.pug @@ -36,6 +36,7 @@ } document.querySelector(".flink").insertAdjacentHTML("afterbegin", result) + window.lazyLoadInstance && window.lazyLoadInstance.update() }) })() diff --git a/layout/includes/pagination.pug b/layout/includes/pagination.pug index c50b81a..2af0e00 100644 --- a/layout/includes/pagination.pug +++ b/layout/includes/pagination.pug @@ -13,19 +13,23 @@ if is_post() if(prev) - var hasPageNext = next ? 'pull-left' : 'pull-full' .prev-post(class=hasPageNext) - - var pagination_cover = prev.cover === false ? prev.randomcover : prev.cover - a(href=url_for(prev.path)) - img.prev-cover(src=url_for(pagination_cover) onerror=`onerror=null;src='${url_for(theme.error_img.post_page)}'` alt='cover of previous post') + a(href=url_for(prev.path) title=prev.title) + if prev.cover_type === 'img' + img.cover(src=url_for(prev.cover) onerror=`onerror=null;src='${url_for(theme.error_img.post_page)}'` alt='cover of previous post') + else + .cover(style=`background: ${prev.cover || 'var(--default-bg-color)'}`) .pagination-info .label=_p('pagination.prev') .prev_info=prev.title if(next) - var hasPagePrev = prev ? 'pull-right' : 'pull-full' - - var pagination_cover = next.cover == false ? next.randomcover : next.cover .next-post(class=hasPagePrev) - a(href=url_for(next.path)) - img.next-cover(src=url_for(pagination_cover) onerror=`onerror=null;src='${url_for(theme.error_img.post_page)}'` alt='cover of next post') + a(href=url_for(next.path) title=next.title) + if next.cover_type === 'img' + img.cover(src=url_for(next.cover) onerror=`onerror=null;src='${url_for(theme.error_img.post_page)}'` alt='cover of next post') + else + .cover(style=`background: ${next.cover || 'var(--default-bg-color)'}`) .pagination-info .label=_p('pagination.next') .next_info=next.title diff --git a/layout/includes/rightside.pug b/layout/includes/rightside.pug index 9696d0b..03c6aaa 100644 --- a/layout/includes/rightside.pug +++ b/layout/includes/rightside.pug @@ -57,4 +57,5 @@ mixin rightsideItem(array) +rightsideItem(showArray) button#go-up(type="button" title=_p("rightside.back_to_top")) + span.scroll-percent i.fas.fa-arrow-up \ 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 c43a18d..e69237f 100644 --- a/layout/includes/third-party/card-post-count/waline.pug +++ b/layout/includes/third-party/card-post-count/waline.pug @@ -10,7 +10,7 @@ script. const waline = Waline.init(initData) } - if (typeof Waline === 'function') initWaline() + if (typeof Waline === 'object') initWaline() else getScript('!{url_for(theme.asset.waline_js)}').then(initWaline) } diff --git a/layout/includes/third-party/comments/artalk.pug b/layout/includes/third-party/comments/artalk.pug index 97a5cd5..2a3bf22 100644 --- a/layout/includes/third-party/comments/artalk.pug +++ b/layout/includes/third-party/comments/artalk.pug @@ -1,13 +1,6 @@ - const { server, site, option } = theme.artalk script. - function addArtalkSource () { - const ele = document.createElement('link') - ele.rel = 'stylesheet' - ele.href= '!{theme.asset.artalk_css}' - document.getElementsByTagName('head')[0].appendChild(ele) - } - function loadArtalk () { function initArtalk () { window.artalkItem = new Artalk(Object.assign({ @@ -22,7 +15,7 @@ script. if (typeof window.artalkItem === 'object') setTimeout(()=>{initArtalk()},200) else { - addArtalkSource() + getCSS('!{theme.asset.artalk_css}') typeof Artalk !== 'function' ? getScript('!{theme.asset.artalk_js}').then(initArtalk) : setTimeout(()=>{initArtalk()},200) } diff --git a/layout/includes/third-party/comments/disqusjs.pug b/layout/includes/third-party/comments/disqusjs.pug index 1e66555..2b4a5f4 100644 --- a/layout/includes/third-party/comments/disqusjs.pug +++ b/layout/includes/third-party/comments/disqusjs.pug @@ -2,13 +2,6 @@ script. function loadDisqusjs () { - function addDisqusjsCSS () { - const ele = document.createElement('link') - ele.rel = 'stylesheet' - ele.href= '!{url_for(theme.asset.disqusjs_css)}' - document.getElementsByTagName('head')[0].appendChild(ele) - } - function initDisqusjs () { window.disqusjs = null disqusjs = new DisqusJS(Object.assign({ @@ -34,7 +27,7 @@ script. if (window.disqusJsLoad) initDisqusjs() else { - addDisqusjsCSS() + getCSS('!{url_for(theme.asset.disqusjs_css)}') getScript('!{url_for(theme.asset.disqusjs)}').then(initDisqusjs) window.disqusJsLoad = true } diff --git a/layout/includes/third-party/comments/gitalk.pug b/layout/includes/third-party/comments/gitalk.pug index fccb64d..e162cce 100644 --- a/layout/includes/third-party/comments/gitalk.pug +++ b/layout/includes/third-party/comments/gitalk.pug @@ -1,11 +1,4 @@ script. - function addGitalkSource () { - const ele = document.createElement('link') - ele.rel = 'stylesheet' - ele.href= '!{url_for(theme.asset.gitalk_css)}' - document.getElementsByTagName('head')[0].appendChild(ele) - } - function loadGitalk () { function initGitalk () { var gitalk = new Gitalk(Object.assign({ @@ -23,7 +16,7 @@ script. if (typeof Gitalk === 'function') initGitalk() else { - addGitalkSource() + getCSS('!{url_for(theme.asset.gitalk_css)}') getScript('!{url_for(theme.asset.gitalk)}').then(initGitalk) } } diff --git a/layout/includes/third-party/comments/waline.pug b/layout/includes/third-party/comments/waline.pug index 06e8078..55c7b45 100644 --- a/layout/includes/third-party/comments/waline.pug +++ b/layout/includes/third-party/comments/waline.pug @@ -3,13 +3,6 @@ script. function loadWaline () { - function insertCSS () { - const link = document.createElement("link") - link.rel = "stylesheet" - link.href = "!{url_for(theme.asset.waline_css)}" - document.head.appendChild(link) - } - function initWaline () { const waline = Waline.init(Object.assign({ el: '#waline-wrap', @@ -21,10 +14,11 @@ script. }, !{JSON.stringify(option)})) } - if (typeof Waline === 'function') initWaline() + if (typeof Waline === 'object') initWaline() else { - insertCSS() - getScript('!{url_for(theme.asset.waline_js)}').then(initWaline) + getCSS('!{url_for(theme.asset.waline_css)}').then(() => { + getScript('!{url_for(theme.asset.waline_js)}').then(initWaline) + }) } } diff --git a/layout/includes/third-party/newest-comments/waline.pug b/layout/includes/third-party/newest-comments/waline.pug index 15ca44c..565f6f4 100644 --- a/layout/includes/third-party/newest-comments/waline.pug +++ b/layout/includes/third-party/newest-comments/waline.pug @@ -64,7 +64,7 @@ script. }) } - if (typeof Waline === 'function') loadWaline() + if (typeof Waline === 'object') loadWaline() else getScript('!{url_for(theme.asset.waline_js)}').then(loadWaline) } diff --git a/layout/includes/third-party/share/share-js.pug b/layout/includes/third-party/share/share-js.pug index 0a566fa..612332c 100644 --- a/layout/includes/third-party/share/share-js.pug +++ b/layout/includes/third-party/share/share-js.pug @@ -1,3 +1,4 @@ -.social-share(data-image=url_for(page.cover|| theme.avatar.img) data-sites= theme.sharejs.sites) +- const coverVal = page.cover_type === 'img' ? page.cover : theme.avatar.img +.social-share(data-image=url_for(coverVal) data-sites= theme.sharejs.sites) link(rel='stylesheet' href=url_for(theme.asset.sharejs_css) media="print" onload="this.media='all'") script(src=url_for(theme.asset.sharejs) defer) \ No newline at end of file diff --git a/layout/includes/widget/card_recent_post.pug b/layout/includes/widget/card_recent_post.pug index 60a0e07..dddf0fc 100644 --- a/layout/includes/widget/card_recent_post.pug +++ b/layout/includes/widget/card_recent_post.pug @@ -14,7 +14,10 @@ if theme.aside.card_recent_post.enable .aside-list-item(class=no_cover) if post_cover && theme.cover.aside_enable a.thumbnail(href=url_for(link) title=title) - img(src=url_for(post_cover) onerror=`this.onerror=null;this.src='${url_for(theme.error_img.post_page)}'` alt=title) + if article.cover_type === 'img' + img(src=url_for(post_cover) onerror=`this.onerror=null;this.src='${url_for(theme.error_img.post_page)}'` alt=title) + else + div(style=`background: ${post_cover}`) .content a.title(href=url_for(link) title=title)= title if theme.aside.card_recent_post.sort === 'updated' diff --git a/package.json b/package.json index 38882af..bbe5b1f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hexo-theme-butterfly", - "version": "4.5.1", + "version": "4.6.0", "description": "A Simple and Card UI Design theme for Hexo", "main": "package.json", "scripts": { diff --git a/plugins.yml b/plugins.yml index 9590b68..c183f69 100644 --- a/plugins.yml +++ b/plugins.yml @@ -1,11 +1,11 @@ algolia_search_v4: name: algoliasearch file: dist/algoliasearch-lite.umd.js - version: 4.14.2 + version: 4.14.3 instantsearch_v4: name: instantsearch.js file: dist/instantsearch.production.min.js - version: 4.49.0 + version: 4.49.4 pjax: name: pjax file: pjax.min.js @@ -37,17 +37,17 @@ disqusjs_css: twikoo: name: twikoo file: dist/twikoo.all.min.js - version: 1.6.7 + version: 1.6.8 waline_js: name: '@waline/client' file: dist/waline.js other_name: waline - version: 2.13.0 + version: 2.14.7 waline_css: name: '@waline/client' file: dist/waline.css other_name: waline - version: 2.13.0 + version: 2.14.7 sharejs: name: butterfly-extsrc file: sharejs/dist/js/social-share.min.js @@ -64,16 +64,16 @@ katex: name: katex file: dist/katex.min.css other_name: KaTeX - version: 0.16.3 + version: 0.16.4 katex_copytex: name: katex file: dist/contrib/copy-tex.min.js other_name: KaTeX - version: 0.16.3 + version: 0.16.4 mermaid: name: mermaid file: dist/mermaid.min.js - version: 9.1.7 + version: 9.3.0 canvas_ribbon: name: butterfly-extsrc file: dist/canvas-ribbon.min.js @@ -131,7 +131,7 @@ fancybox_v4: medium_zoom: name: medium-zoom file: dist/medium-zoom.min.js - version: 1.0.6 + version: 1.0.8 snackbar_css: name: node-snackbar file: dist/snackbar.min.css @@ -144,7 +144,7 @@ fontawesomeV6: name: '@fortawesome/fontawesome-free' file: css/all.min.css other_name: font-awesome - version: 6.2.0 + version: 6.2.1 flickr_justified_gallery_js: name: flickr-justified-gallery file: dist/fjGallery.min.js @@ -183,11 +183,11 @@ prismjs_autoloader: artalk_js: name: artalk file: dist/Artalk.js - version: 2.4.3 + version: 2.4.4 artalk_css: name: artalk file: dist/Artalk.css - version: 2.4.3 + version: 2.4.4 pace_js: name: pace-js other_name: pace diff --git a/scripts/events/cdn.js b/scripts/events/cdn.js index 7d77e63..9c1b2c1 100644 --- a/scripts/events/cdn.js +++ b/scripts/events/cdn.js @@ -12,7 +12,7 @@ hexo.extend.filter.register('before_generate', () => { const themeConfig = hexo.theme.config const { CDN } = themeConfig - const thirdPartySrc = hexo.render.renderSync({ path: path.join(hexo.theme_dir,'/plugins.yml'), engine: 'yaml'}) + const thirdPartySrc = hexo.render.renderSync({ path: path.join(hexo.theme_dir, '/plugins.yml'), engine: 'yaml' }) const internalSrc = { main: { name: 'hexo-theme-butterfly', @@ -46,7 +46,7 @@ hexo.extend.filter.register('before_generate', () => { } const createCDNLink = (data, type, cond = '') => { - Object.keys(data).map(key => { + Object.keys(data).forEach(key => { let { name, version, file, other_name } = data[key] const min_file = minFile(file) @@ -65,6 +65,7 @@ hexo.extend.filter.register('before_generate', () => { min_cdnjs_file, cdnjs_name } + const cdnSource = { local: cond === 'internal' ? cdnjs_file : `/pluginsSrc/${name}/${file}`, jsdelivr: `https://cdn.jsdelivr.net/npm/${name}${verType}/${min_file}`, @@ -72,11 +73,11 @@ hexo.extend.filter.register('before_generate', () => { cdnjs: `https://cdnjs.cloudflare.com/ajax/libs/${cdnjs_name}/${version}/${min_cdnjs_file}`, custom: (CDN.custom_format || '').replace(/\$\{(.+?)\}/g, (match, $1) => value[$1]) } - + data[key] = cdnSource[type] }) - if (cond === 'internal') data['main_css'] = 'css/index.css' + if (cond === 'internal') data.main_css = 'css/index.css' return data } @@ -89,6 +90,6 @@ hexo.extend.filter.register('before_generate', () => { return obj } - themeConfig.asset = Object.assign(createCDNLink(internalSrc,CDN.internal_provider,'internal'), - createCDNLink(thirdPartySrc,CDN.third_party_provider), deleteNullValue(CDN.option)) + themeConfig.asset = Object.assign(createCDNLink(internalSrc, CDN.internal_provider, 'internal'), + createCDNLink(thirdPartySrc, CDN.third_party_provider), deleteNullValue(CDN.option)) }) diff --git a/scripts/events/comment.js b/scripts/events/comment.js index b1ef856..ebbe439 100644 --- a/scripts/events/comment.js +++ b/scripts/events/comment.js @@ -11,4 +11,4 @@ hexo.extend.filter.register('before_generate', () => { } const newArray = use.map(item => item.toLowerCase().replace(/\b[a-z]/g, s => s.toUpperCase())) themeConfig.comments.use = newArray -}) \ No newline at end of file +}) diff --git a/scripts/events/init.js b/scripts/events/init.js index 69c2807..1bd0570 100644 --- a/scripts/events/init.js +++ b/scripts/events/init.js @@ -1,8 +1,7 @@ -const logger = require('hexo-log')() - hexo.extend.filter.register('before_generate', () => { // Get first two digits of the Hexo version number const hexoVer = hexo.version.replace(/(^.*\..*)\..*/, '$1') + const logger = hexo.log if (hexoVer < 5.3) { logger.error('Please update Hexo to V5.3.0 or higher!') @@ -13,7 +12,9 @@ hexo.extend.filter.register('before_generate', () => { if (hexo.locals.get) { const data = hexo.locals.get('data') if (data && data.butterfly) { - logger.error(" 'butterfly.yml' is deprecated. Please use '_config.butterfly.yml' ") + logger.error( + " 'butterfly.yml' is deprecated. Please use '_config.butterfly.yml' " + ) logger.error(" 'butterfly.yml' 已經棄用,請使用 '_config.butterfly.yml' ") process.exit(-1) } diff --git a/scripts/events/welcome.js b/scripts/events/welcome.js index 77eb662..f4c018a 100644 --- a/scripts/events/welcome.js +++ b/scripts/events/welcome.js @@ -1,17 +1,13 @@ -const logger = require('hexo-log')() - hexo.on('ready', () => { const { version } = require('../../package.json') - logger.info(` + hexo.log.info(` =================================================================== - - ##### # # ##### ##### ###### ##### ###### # # # - # # # # # # # # # # # # # - ##### # # # # ##### # # ##### # # - # # # # # # # ##### # # # - # # # # # # # # # # # # - ##### #### # # ###### # # # ###### # - + ##### # # ##### ##### ###### ##### ###### # # # + # # # # # # # # # # # # # + ##### # # # # ##### # # ##### # # + # # # # # # # ##### # # # + # # # # # # # # # # # # + ##### #### # # ###### # # # ###### # ${version} ===================================================================`) }) diff --git a/scripts/filters/random_cover.js b/scripts/filters/random_cover.js index 47ed4fe..ffb61e4 100644 --- a/scripts/filters/random_cover.js +++ b/scripts/filters/random_cover.js @@ -6,40 +6,40 @@ 'use strict' hexo.extend.filter.register('before_post_render', function (data) { - const { config } = this - if (config.post_asset_folder) { - const imgTestReg = /\.(png|jpe?g|gif|svg|webp)(\?.*)?$/ + const imgTestReg = /\.(png|jpe?g|gif|svg|webp)(\?.*)?$/ + let randomCover + let coverVal = data.cover + + // Add path to top_img and cover if post_asset_folder is enabled + if (hexo.config.post_asset_folder) { const topImg = data.top_img - const cover = data.cover if (topImg && topImg.indexOf('/') === -1 && imgTestReg.test(topImg)) data.top_img = data.path + topImg - if (cover && cover.indexOf('/') === -1) data.cover = data.path + cover + if (coverVal && coverVal.indexOf('/') === -1 && imgTestReg.test(coverVal)) data.cover = data.path + coverVal } - if (data.cover === false) { - data.randomcover = randomCover() - return data + const randomCoverFn = () => { + const theme = hexo.theme.config + if (!(theme.cover && theme.cover.default_cover)) return false + if (!Array.isArray(theme.cover.default_cover)) return theme.cover.default_cover + const num = Math.floor(Math.random() * theme.cover.default_cover.length) + return theme.cover.default_cover[num] + } + + if (coverVal === false) return data + + // If cover is not set, use random cover + if (!coverVal) { + randomCover = randomCoverFn() + data.cover = randomCover + coverVal = randomCover // update coverVal + } + + if (coverVal) { + if (coverVal.indexOf('//') !== -1 || imgTestReg.test(coverVal)) { + data.cover_type = 'img' + return data + } } - data.cover = data.cover || randomCover() return data }) - -function randomCover () { - const theme = hexo.theme.config - let cover - let num - - if (theme.cover && theme.cover.default_cover) { - if (!Array.isArray(theme.cover.default_cover)) { - cover = theme.cover.default_cover - return cover - } else { - num = Math.floor(Math.random() * theme.cover.default_cover.length) - cover = theme.cover.default_cover[num] - return cover - } - } else { - cover = theme.default_top_img || 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7' - return cover - } -} diff --git a/scripts/helpers/findArchiveLength.js b/scripts/helpers/findArchiveLength.js index e55dc0f..56e9bcb 100644 --- a/scripts/helpers/findArchiveLength.js +++ b/scripts/helpers/findArchiveLength.js @@ -1,13 +1,13 @@ hexo.extend.helper.register('findArchiveLength', function (func) { - const allPostsLength = this.site.posts.length; - if (hexo.config.archive_generator && hexo.config.archive_generator.enable === false ) return allPostsLength + const allPostsLength = this.site.posts.length + if (hexo.config.archive_generator && hexo.config.archive_generator.enable === false) return allPostsLength const { yearly, monthly, daily } = hexo.config.archive_generator const { year, month, day } = this.page if (yearly === false || !year) return allPostsLength const posts = this.site.posts.sort('date') - const compareFunc = (type,y1,m1,d1,y2,m2,d2) => { + const compareFunc = (type, y1, m1, d1, y2, m2, d2) => { if (type === 'year') { return y1 === y2 } else if (type === 'month') { @@ -18,15 +18,15 @@ hexo.extend.helper.register('findArchiveLength', function (func) { } const generateDateObj = (type) => { - let dateObj = [] + const dateObj = [] let length = 0 posts.forEach(post => { - let date = post.date.clone() + const date = post.date.clone() const year = date.year() const month = date.month() + 1 const day = date.date() - let lastData = dateObj[length - 1] + const lastData = dateObj[length - 1] if (!lastData || !compareFunc(type, lastData.year, lastData.month, lastData.day, year, month, day)) { const name = type === 'year' ? year : type === 'month' ? `${year}-${month}` : `${year}-${month}-${day}` @@ -40,12 +40,12 @@ hexo.extend.helper.register('findArchiveLength', function (func) { } else { lastData.count++ } - }); + }) return dateObj } - const data = func('createArchiveObj', ()=> { + const data = func('createArchiveObj', () => { const yearObj = yearly ? generateDateObj('year') : [] const monthObj = monthly ? generateDateObj('month') : [] const dayObj = daily ? generateDateObj('day') : [] @@ -55,4 +55,4 @@ hexo.extend.helper.register('findArchiveLength', function (func) { const name = month ? day ? `${year}-${month}-${day}` : `${year}-${month}` : year return data.find(item => item.name === name).count -}) \ No newline at end of file +}) diff --git a/scripts/helpers/inject_head_js.js b/scripts/helpers/inject_head_js.js index 9c845d4..88ff5f2 100644 --- a/scripts/helpers/inject_head_js.js +++ b/scripts/helpers/inject_head_js.js @@ -9,8 +9,8 @@ hexo.extend.helper.register('inject_head_js', function () { const { darkmode, aside } = this.theme const { theme_color } = hexo.theme.config - const themeColorLight = theme_color && theme_color.enable && theme_color.meta_theme_color_light || '#ffffff' - const themeColorDark = theme_color && theme_color.enable && theme_color.meta_theme_color_dark || '#0d0d0d' + const themeColorLight = (theme_color && theme_color.enable && theme_color.meta_theme_color_light) || '#ffffff' + const themeColorDark = (theme_color && theme_color.enable && theme_color.meta_theme_color_dark) || '#0d0d0d' const localStore = ` win.saveToLocal = { @@ -60,6 +60,17 @@ hexo.extend.helper.register('inject_head_js', function () { }) ` + const getCSS = ` + win.getCSS = url => new Promise((resolve, reject) => { + const link = document.createElement('link') + link.rel = 'stylesheet' + link.href = url + link.onload = () => resolve() + link.onerror = () => reject() + document.head.appendChild(link) + }) + ` + let darkmodeJs = '' if (darkmode.enable) { darkmodeJs = ` @@ -144,5 +155,5 @@ hexo.extend.helper.register('inject_head_js', function () { detectApple() ` - return `` + return `` }) diff --git a/scripts/helpers/page.js b/scripts/helpers/page.js index aa2b74b..35e05a8 100644 --- a/scripts/helpers/page.js +++ b/scripts/helpers/page.js @@ -54,8 +54,8 @@ hexo.extend.helper.register('cloudTags', function (options = {}) { return result }) -hexo.extend.helper.register('urlNoIndex', function (url = null) { - return prettyUrls(url || this.url, { trailing_index: false, trailing_html: false }) +hexo.extend.helper.register('urlNoIndex', function (url = null, trailingIndex = false, trailingHtml = false) { + return prettyUrls(url || this.url, { trailing_index: trailingIndex, trailing_html: trailingHtml }) }) hexo.extend.helper.register('md5', function (path) { @@ -74,8 +74,8 @@ hexo.extend.helper.register('injectHtml', function (data) { hexo.extend.helper.register('findArchivesTitle', function (page, menu, date) { if (page.year) { const dateStr = page.month ? `${page.year}-${page.month}` : `${page.year}` - const date_format = page.month ? hexo.theme.config.aside.card_archives.format : 'YYYY' - return date(dateStr, date_format) + const dateFormat = page.month ? hexo.theme.config.aside.card_archives.format : 'YYYY' + return date(dateStr, dateFormat) } const defaultTitle = this._p('page.archives') @@ -95,3 +95,11 @@ hexo.extend.helper.register('findArchivesTitle', function (page, menu, date) { return loop(menu) || defaultTitle }) + +hexo.extend.helper.register('isImgOrUrl', function (path) { + const imgTestReg = /\.(png|jpe?g|gif|svg|webp)(\?.*)?$/ + if (path.indexOf('//') !== -1 || imgTestReg.test(path)) { + return true + } + return false +}) diff --git a/scripts/helpers/related_post.js b/scripts/helpers/related_post.js index 6809ac7..9a46f68 100644 --- a/scripts/helpers/related_post.js +++ b/scripts/helpers/related_post.js @@ -15,7 +15,7 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) { title: post.title, path: post.path, cover: post.cover, - randomcover: post.randomcover, + cover_type: post.cover_type, weight: 1, updated: post.updated, created: post.date @@ -50,13 +50,14 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) { result += '