Compare commits

...

7 Commits
3.4.0 ... 3.5.1

36 changed files with 531 additions and 261 deletions

View File

@@ -1,9 +1,9 @@
# hexo-theme-butterfly # hexo-theme-butterfly
![version](https://img.shields.io/github/package-json/v/jerryc127/hexo-theme-butterfly) ![master version](https://img.shields.io/github/package-json/v/jerryc127/hexo-theme-butterfly/master?color=%231ab1ad&label=master)
![master version](https://img.shields.io/github/package-json/v/jerryc127/hexo-theme-butterfly/dev?label=dev)
![https://img.shields.io/npm/v/hexo-theme-butterfly?color=%09%23bf00ff](https://img.shields.io/npm/v/hexo-theme-butterfly?color=%09%23bf00ff) ![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.2+-0e83c) ![hexo version](https://img.shields.io/badge/hexo-5.0+-0e83c)
![npm download](https://img.shields.io/npm/dw/hexo-theme-butterfly?color=green)
![license](https://img.shields.io/github/license/jerryc127/hexo-theme-butterfly?color=FF5531) ![license](https://img.shields.io/github/license/jerryc127/hexo-theme-butterfly?color=FF5531)
Demo: 👍 [Butterfly](https://butterfly.js.org/) || 🤞 [JerryC](https://jerryc.me/) Demo: 👍 [Butterfly](https://butterfly.js.org/) || 🤞 [JerryC](https://jerryc.me/)
@@ -71,7 +71,7 @@ npm i hexo-theme-butterfly
- [x] Related articles - [x] Related articles
- [x] Displays outdated notice for a post - [x] Displays outdated notice for a post
- [x] Share (AddThis/Sharejs/Addtoany) - [x] Share (AddThis/Sharejs/Addtoany)
- [X] Comment (Disqus/Disqusjs/Livere/Gitalk/Valine/Utterances/Facebook Comments/Twikoo - [X] Comment (Disqus/Disqusjs/Livere/Gitalk/Valine/Waline/Utterances/Facebook Comments/Twikoo)
- [x] Multiple Comment System Support - [x] Multiple Comment System Support
- [x] Online Chats (Chatra/Tidio/Daovoice/Gitter/Crisp) - [x] Online Chats (Chatra/Tidio/Daovoice/Gitter/Crisp)
- [x] Web analytics (Baidu Analytics/Google Analytics/Tencent Analytics/CNZZ Analytics) - [x] Web analytics (Baidu Analytics/Google Analytics/Tencent Analytics/CNZZ Analytics)

View File

@@ -1,12 +1,11 @@
# hexo-theme-butterfly # hexo-theme-butterfly
![version](https://img.shields.io/github/package-json/v/jerryc127/hexo-theme-butterfly) ![master version](https://img.shields.io/github/package-json/v/jerryc127/hexo-theme-butterfly/master?color=%231ab1ad&label=master)
![master version](https://img.shields.io/github/package-json/v/jerryc127/hexo-theme-butterfly/dev?label=dev)
![https://img.shields.io/npm/v/hexo-theme-butterfly?color=%09%23bf00ff](https://img.shields.io/npm/v/hexo-theme-butterfly?color=%09%23bf00ff) ![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.2+-0e83c) ![hexo version](https://img.shields.io/badge/hexo-5.0+-0e83c)
![npm download](https://img.shields.io/npm/dw/hexo-theme-butterfly?color=green)
![license](https://img.shields.io/github/license/jerryc127/hexo-theme-butterfly?color=FF5531) ![license](https://img.shields.io/github/license/jerryc127/hexo-theme-butterfly?color=FF5531)
預覽: 👍 [Butterfly](https://butterfly.js.org/) || 🤞 [JerryC](https://jerryc.me/) 預覽: 👍 [Butterfly](https://butterfly.js.org/) || 🤞 [JerryC](https://jerryc.me/)
文檔: 📖 [Butterfly Docs](https://butterfly.js.org/posts/21cfbf15/) 文檔: 📖 [Butterfly Docs](https://butterfly.js.org/posts/21cfbf15/)
@@ -71,7 +70,7 @@ theme: butterfly
- [x] 顯示相關文章 - [x] 顯示相關文章
- [x] 過期文章提醒 - [x] 過期文章提醒
- [x] 多種分享系統AddThis/Sharejs/Addtoany - [x] 多種分享系統AddThis/Sharejs/Addtoany
- [X] 多種評論系統Disqus/Disqusjs/Livere/Gitalk/Valine/Utterances/Facebook Comments/Twikoo - [X] 多種評論系統Disqus/Disqusjs/Livere/Gitalk/Valine/Waline/Utterances/Facebook Comments/Twikoo
- [x] 支持雙評論部署 - [x] 支持雙評論部署
- [x] 多種在線聊天Chatra/Tidio/Daovoice/Gitter/Crisp - [x] 多種在線聊天Chatra/Tidio/Daovoice/Gitter/Crisp
- [x] 多種分析系統(百度分析/谷歌分析/騰訊分析/CNZZ分析 - [x] 多種分析系統(百度分析/谷歌分析/騰訊分析/CNZZ分析

View File

@@ -240,7 +240,7 @@ addtoany:
comments: comments:
# Up to two comments system, the first will be shown as default # Up to two comments system, the first will be shown as default
# Choose: Disqus/Disqusjs/Livere/Gitalk/Valine/Utterances/Facebook Comments/Twikoo # Choose: Disqus/Disqusjs/Livere/Gitalk/Valine/Waline/Utterances/Facebook Comments/Twikoo
use: use:
# - Valine # - Valine
# - Disqus # - Disqus
@@ -304,6 +304,15 @@ valine:
requiredFields: nick,mail # required fields (nick/mail) requiredFields: nick,mail # required fields (nick/mail)
option: option:
# waline - A simple comment system with backend support fork from Valine
# https://waline.js.org/
waline:
serverURL: # Waline server address url
avatar: monsterid # gravatar style https://zh-tw.gravatar.com/site/implement/images/#default-image
emojiCDN: # emoji CDN
bg: /image/comment_bg.png # waline background
option:
# utterances # utterances
# https://utteranc.es/ # https://utteranc.es/
utterances: utterances:
@@ -326,6 +335,9 @@ facebook_comments:
# Twikoo # Twikoo
# https://github.com/imaegoo/twikoo # https://github.com/imaegoo/twikoo
twikoo: twikoo:
envId:
region:
option:
# Chat Services # Chat Services
# -------------------------------------- # --------------------------------------
@@ -395,6 +407,14 @@ tencent_analytics:
# https://www.umeng.com/ # https://www.umeng.com/
cnzz_analytics: cnzz_analytics:
# Cloudflare Analytics
# https://www.cloudflare.com/zh-tw/web-analytics/
cloudflare_analytics:
# Microsoft Clarity
# https://clarity.microsoft.com/
microsoft_clarity:
# Advertisement # Advertisement
# -------------------------------------- # --------------------------------------
@@ -609,6 +629,7 @@ aside:
enable: true enable: true
description: description:
button: button:
enable: true
icon: fab fa-github icon: fab fa-github
text: Follow Me text: Follow Me
link: https://github.com/xxxxxx link: https://github.com/xxxxxx
@@ -619,24 +640,29 @@ aside:
enable: true enable: true
limit: 5 # if set 0 will show all limit: 5 # if set 0 will show all
sort: date # date or updated sort: date # date or updated
sort_order: # Don't modify the setting unless you know how it works
card_categories: card_categories:
enable: true enable: true
limit: 8 # if set 0 will show all limit: 8 # if set 0 will show all
expand: none # none/true/false expand: none # none/true/false
sort_order: # Don't modify the setting unless you know how it works
card_tags: card_tags:
enable: true enable: true
limit: 40 # if set 0 will show all limit: 40 # if set 0 will show all
color: false color: false
sort_order: # Don't modify the setting unless you know how it works
card_archives: card_archives:
enable: true enable: true
type: monthly # yearly or monthly type: monthly # yearly or monthly
format: MMMM YYYY # eg: YYYY年MM月 format: MMMM YYYY # eg: YYYY年MM月
order: -1 # Sort of order. 1, asc for ascending; -1, desc for descending order: -1 # Sort of order. 1, asc for ascending; -1, desc for descending
limit: 8 # if set 0 will show all limit: 8 # if set 0 will show all
sort_order: # Don't modify the setting unless you know how it works
card_webinfo: card_webinfo:
enable: true enable: true
post_count: true post_count: true
last_push_date: true last_push_date: true
sort_order: # Don't modify the setting unless you know how it works
# busuanzi count for PV / UV in site # busuanzi count for PV / UV in site
# 訪問人數 # 訪問人數
@@ -654,14 +680,11 @@ runtimeshow:
# Aside widget - Newest Comments # Aside widget - Newest Comments
newest_comments: newest_comments:
enable: false enable: false
sort_order: # Don't modify the setting unless you know how it works
limit: 6 limit: 6
avatar: true avatar: true
leancloud: # You can only choose one, or neither
enable: false valine: 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: github_issues:
enable: false enable: false
repo: repo:
@@ -670,6 +693,7 @@ newest_comments:
forum: forum:
api_key: api_key:
twikoo: false twikoo: false
waline: false
# Bottom right button (右下角按鈕) # Bottom right button (右下角按鈕)
# -------------------------------------- # --------------------------------------
@@ -848,6 +872,7 @@ CDN:
disqusjs_css: https://cdn.jsdelivr.net/npm/disqusjs@1/dist/disqusjs.css disqusjs_css: https://cdn.jsdelivr.net/npm/disqusjs@1/dist/disqusjs.css
utterances: https://utteranc.es/client.js utterances: https://utteranc.es/client.js
twikoo: https://cdn.jsdelivr.net/npm/twikoo/dist/twikoo.all.min.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 # share
addtoany: https://static.addtoany.com/menu/page.js addtoany: https://static.addtoany.com/menu/page.js

View File

@@ -30,3 +30,14 @@ if theme.tencent_analytics
if theme.cnzz_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}`) 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}"}`)
if theme.microsoft_clarity
script.
(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "!{theme.microsoft_clarity}");

View File

@@ -12,6 +12,12 @@ if theme.tencent_analytics
if theme.cnzz_analytics if theme.cnzz_analytics
link(rel="preconnect" href="//s4.cnzz.com") link(rel="preconnect" href="//s4.cnzz.com")
if theme.cloudflare_analytics
link(rel="preconnect" href="//static.cloudflareinsights.com")
if theme.microsoft_clarity
link(rel="preconnect" href="//www.clarity.ms")
if theme.blog_title_font && theme.blog_title_font.font_link && theme.blog_title_font.font_link.indexOf('//fonts.googleapis.com') != -1 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='') link(rel="preconnect" href="//fonts.googleapis.com" crossorigin='')

View File

@@ -65,24 +65,30 @@
span.post-meta-label= _p('post.comments') + ':' span.post-meta-label= _p('post.comments') + ':'
if block if block
block block
if whichCount === 'Disqus' || whichCount === 'Disqusjs' case whichCount
+countBlock when 'Disqus'
span.disqus-comment-count when 'Disqusjs'
a(href=full_url_for(page.path) + '#disqus_thread') +countBlock
else if whichCount === 'Valine' span.disqus-comment-count
+countBlock a(href=full_url_for(page.path) + '#disqus_thread')
a(href=url_for(page.path) + '#post-comment' itemprop="discussionUrl") when 'Valine'
span.valine-comment-count(data-xid=url_for(page.path) itemprop="commentCount") +countBlock
else if whichCount === 'Gitalk' a(href=url_for(page.path) + '#post-comment' itemprop="discussionUrl")
+countBlock span.valine-comment-count(data-xid=url_for(page.path) itemprop="commentCount")
a(href=url_for(page.path) + '#post-comment') when 'Waline'
span.gitalk-#card-toc +countBlock
else if whichCount === 'Twikoo' a(href=url_for(page.path) + '#post-comment')
+countBlock span.waline-comment-count(id=url_for(page.path))
a(href=url_for(page.path) + '#post-comment') when 'Gitalk'
span#twikoo-count +countBlock
else if whichCount === 'Facebook Comments' a(href=url_for(page.path) + '#post-comment')
+countBlock span.gitalk-comment-count
a(href=url_for(page.path) + '#post-comment') when 'Twikoo'
span.fb-comments-count(data-href=urlNoIndex()) +countBlock
a(href=url_for(page.path) + '#post-comment')
span#twikoo-count
when 'Facebook Comments'
+countBlock
a(href=url_for(page.path) + '#post-comment')
span.fb-comments-count(data-href=urlNoIndex())

View File

@@ -1,5 +1,6 @@
- var htmlClassHideAside = theme.aside.enable && theme.aside.hide ? 'hide-aside' : '' - var htmlClassHideAside = theme.aside.enable && theme.aside.hide ? 'hide-aside' : ''
- var hideAside = !theme.aside.enable || page.aside === false ? 'hide-aside' : '' - var hideAside = !theme.aside.enable || page.aside === false ? 'hide-aside' : ''
- var pageType = is_post() ? 'post' : 'page'
doctype html doctype html
html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside) html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside)
@@ -14,7 +15,7 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside
!=partial('includes/sidebar', {}, {cache:theme.fragment_cache}) !=partial('includes/sidebar', {}, {cache:theme.fragment_cache})
#body-wrap #body-wrap(class=pageType)
include ./header/index.pug include ./header/index.pug
main#content-inner.layout(class=hideAside) main#content-inner.layout(class=hideAside)

View File

@@ -13,7 +13,7 @@ script.
if (!{Boolean(option)}) { if (!{Boolean(option)}) {
const otherSetting = !{option} const otherSetting = !{option}
setting = Object.assign({}, setting, otherSetting) setting = Object.assign(setting, otherSetting)
} }
const init = () => { const init = () => {

View File

@@ -31,6 +31,8 @@ hr
#utterances-wrap #utterances-wrap
when 'Twikoo' when 'Twikoo'
#twikoo-wrap #twikoo-wrap
when 'Waline'
#waline-wrap
when 'Facebook Comments' when 'Facebook Comments'
.fb-comments(data-colorscheme = theme.display_mode === 'dark' ? 'dark' : 'light' .fb-comments(data-colorscheme = theme.display_mode === 'dark' ? 'dark' : 'light'
data-numposts= theme.facebook_comments.pageSize || 10 data-numposts= theme.facebook_comments.pageSize || 10

View File

@@ -14,5 +14,7 @@ each name in theme.comments.use
!=partial('includes/third-party/comments/utterances', {}, {cache:theme.fragment_cache}) !=partial('includes/third-party/comments/utterances', {}, {cache:theme.fragment_cache})
when 'Twikoo' when 'Twikoo'
!=partial('includes/third-party/comments/twikoo', {}, {cache:theme.fragment_cache}) !=partial('includes/third-party/comments/twikoo', {}, {cache:theme.fragment_cache})
when 'Waline'
!=partial('includes/third-party/comments/waline', {}, {cache:theme.fragment_cache})
when 'Facebook Comments' when 'Facebook Comments'
!=partial('includes/third-party/comments/facebook_comments', {}, {cache:theme.fragment_cache}) !=partial('includes/third-party/comments/facebook_comments', {}, {cache:theme.fragment_cache})

View File

@@ -1,16 +1,26 @@
- let option = theme.twikoo.option ? JSON.stringify(theme.twikoo.option) : false
script. script.
(()=>{ (()=>{
const $countDom = document.getElementById('twikoo-count') const $countDom = document.getElementById('twikoo-count')
const init = () => { const init = () => {
twikoo.init({ let initData = {
envId: '!{theme.twikoo}', el: '#twikoo-wrap',
el: '#twikoo-wrap' envId: '!{theme.twikoo.envId}',
}) region: '!{theme.twikoo.region}'
}
if (!{Boolean(option)}) {
const otherData = !{option}
initData = Object.assign(initData, otherData)
}
twikoo.init(initData)
} }
const getCount = () => { const getCount = () => {
twikoo.getCommentsCount({ twikoo.getCommentsCount({
envId: '!{theme.twikoo}', envId: '!{theme.twikoo.envId}',
urls: [window.location.pathname], urls: [window.location.pathname],
includeReply: false includeReply: false
}).then(function (res) { }).then(function (res) {
@@ -23,11 +33,11 @@ script.
const loadTwikoo = (bool = false) => { const loadTwikoo = (bool = false) => {
if (typeof twikoo === 'object') { if (typeof twikoo === 'object') {
init() init()
bool && $countDom && setTimeout(()=>{getCount()},0) bool && $countDom && setTimeout(getCount,0)
} else { } else {
getScript('!{theme.CDN.twikoo}').then(()=> { getScript('!{theme.CDN.twikoo}').then(()=> {
init() init()
bool && $countDom && setTimeout(()=>{getCount()},0) bool && $countDom && setTimeout(getCount,0)
}) })
} }
} }

View File

@@ -29,7 +29,7 @@ script.
if (!{Boolean(option)}) { if (!{Boolean(option)}) {
const otherData = !{option} const otherData = !{option}
initData = Object.assign({}, initData, otherData) initData = Object.assign(initData, otherData)
} }
const valine = new Valine(initData) const valine = new Valine(initData)
@@ -40,8 +40,8 @@ script.
} }
if ('!{theme.comments.use[0]}' === 'Valine' || !!{theme.comments.lazyload}) { if ('!{theme.comments.use[0]}' === 'Valine' || !!{theme.comments.lazyload}) {
if (!{theme.comments.lazyload}) btf.loadComment(document.querySelector('#vcomment'),loadValine) if (!{theme.comments.lazyload}) btf.loadComment(document.getElementById('vcomment'),loadValine)
else setTimeout(() => loadValine(), 0) else setTimeout(loadValine, 0)
} else { } else {
function loadOtherComment () { function loadOtherComment () {
loadValine() loadValine()

View File

@@ -0,0 +1,39 @@
- let option = theme.waline.option ? JSON.stringify(theme.waline.option) : false
- let emojiMaps = '""'
if site.data.waline
- emojiMaps = JSON.stringify(site.data.waline)
script.
function loadWaline () {
function initWaline () {
let initData = {
el: '#waline-wrap',
serverURL: '!{theme.waline.serverURL}',
avatar: '#{theme.waline.avatar}',
path: location.pathname,
emojiCDN: '#{theme.waline.emojiCDN}',
emojiMaps: !{emojiMaps},
}
if (!{Boolean(option)}) {
const otherData = !{option}
initData = Object.assign(initData, otherData)
}
const waline = new Waline(initData)
}
if (typeof Waline === 'function') initWaline()
else getScript('!{url_for(theme.CDN.waline)}').then(initWaline)
}
if ('!{theme.comments.use[0]}' === 'Waline' || !!{theme.comments.lazyload}) {
if (!{theme.comments.lazyload}) btf.loadComment(document.getElementById('waline-wrap'),loadWaline)
else setTimeout(loadWaline, 0)
} else {
function loadOtherComment () {
loadWaline()
}
}

View File

@@ -1,8 +1,12 @@
if theme.newest_comments.leancloud.enable - let config = theme.newest_comments
include ./leancloud.pug
else if theme.newest_comments.github_issues.enable if config.valine
include ./valine.pug
else if config.waline
include ./waline.pug
else if config.github_issues.enable
include ./github-issues.pug include ./github-issues.pug
else if theme.newest_comments.disqus.enable else if config.disqus.enable
include ./disqus-comment.pug include ./disqus-comment.pug
else if theme.newest_comments.twikoo else if config.twikoo
include ./twikoo-comment.pug include ./twikoo-comment.pug

View File

@@ -16,7 +16,8 @@ script.
const getComment = () => { const getComment = () => {
const runTwikoo = () => { const runTwikoo = () => {
twikoo.getRecentComments({ twikoo.getRecentComments({
envId: '!{theme.twikoo}', envId: '!{theme.twikoo.envId}',
region: '!{theme.twikoo.region}',
pageSize: !{theme.newest_comments.limit}, pageSize: !{theme.newest_comments.limit},
includeReply: true includeReply: true
}).then(function (res) { }).then(function (res) {

View File

@@ -1,3 +1,5 @@
- let default_avatar = theme.valine.avatar
script(src="https://cdn.jsdelivr.net/npm/blueimp-md5@2.17.0/js/md5.min.js") script(src="https://cdn.jsdelivr.net/npm/blueimp-md5@2.17.0/js/md5.min.js")
script. script.
window.addEventListener('load', () => { window.addEventListener('load', () => {
@@ -17,7 +19,7 @@ script.
const getIcon = (icon, mail) => { const getIcon = (icon, mail) => {
if (icon) return icon if (icon) return icon
let defaultIcon = '!{ theme.newest_comments.leancloud.default_avatar ? `?d=${theme.newest_comments.leancloud.default_avatar}` : ''}' let defaultIcon = '!{ default_avatar ? `?d=${default_avatar}` : ''}'
let iconUrl = `https://gravatar.loli.net/avatar/${md5(mail.toLowerCase()) + defaultIcon}` let iconUrl = `https://gravatar.loli.net/avatar/${md5(mail.toLowerCase()) + defaultIcon}`
return iconUrl return iconUrl
} }
@@ -54,17 +56,17 @@ script.
const getComment = () => { const getComment = () => {
let serverURL = '' let serverURL = ''
if (!{Boolean(theme.newest_comments.leancloud.serverURL)}) { if (!{Boolean(theme.valine.serverURLs)}) {
serverURL = '!{theme.newest_comments.leancloud.serverURL}' serverURL = '!{theme.valine.serverURLs}'
} else { } else {
serverURL = 'https://!{theme.newest_comments.leancloud.appId.substring(0,8)}.api.lncldglobal.com' serverURL = 'https://!{theme.valine.appId.substring(0,8)}.api.lncldglobal.com'
} }
var settings = { var settings = {
"method": "GET", "method": "GET",
"headers": { "headers": {
"X-LC-Id": '!{theme.newest_comments.leancloud.appId}', "X-LC-Id": '!{theme.valine.appId}',
"X-LC-Key": '!{theme.newest_comments.leancloud.appKey}', "X-LC-Key": '!{theme.valine.appKey}',
"Content-Type": "application/json" "Content-Type": "application/json"
}, },
} }
@@ -78,7 +80,7 @@ script.
'content': changeContent(e.comment), 'content': changeContent(e.comment),
'mail': e.mail, 'mail': e.mail,
'nick': e.nick, 'nick': e.nick,
'url': e.url, 'url': e.url + '#' + e.objectId,
'date': e.createdAt, 'date': e.createdAt,
} }
}) })

View File

@@ -0,0 +1,95 @@
- let default_avatar = theme.waline.avatar
script.
window.addEventListener('load', () => {
const changeContent = (content) => {
if (content === '') return content
content = content.replace(/<[^>]+>/g,"") // remove html tag
content = content.replace(/(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|jpeg|gif|png|webp)/g, '') // remove image link
content = content.replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi, '') // remove url
if (content.length > 150) {
content = content.substring(0,150) + '...'
}
return content
}
const getIcon = (mail) => {
let defaultIcon = '!{ default_avatar ? `?d=${default_avatar}` : ''}'
let iconUrl = `https://gravatar.loli.net/avatar/${mail + defaultIcon}`
return iconUrl
}
const generateHtml = array => {
let result = ''
if (array.length) {
for (let i = 0; i < array.length; i++) {
result += '<div class=\'aside-list-item\'>'
if (!{theme.newest_comments.avatar}) {
let name = 'src'
if(!{theme.lazyload.enable}) {
name = 'data-lazy-src'
}
result += `<a href='${array[i].url}' class="thumbnail"><img ${name}='${getIcon(array[i].mail)}' alt='${array[i].nick}'></a>`
}
result += `<div class='content'>
<a class='comment' href='${array[i].url}'>${array[i].content}</a>
<div class='name'><span>${array[i].nick}</span><time> / ${btf.diffDate(array[i].date, true)}</time></div>
</div></div>`
}
} else {
result += '!{_p("aside.card_newest_comments.zero")}'
}
let $dom = document.querySelector('#card-newest-comments .aside-list')
$dom.innerHTML= result
window.lazyLoadInstance && window.lazyLoadInstance.update()
window.pjax && window.pjax.refresh($dom)
}
const getComment = () => {
const loadWaline = () => {
Waline.Widget.RecentComments({
el: '#card-newest-comments .aside-list',
serverURL: '!{theme.waline.serverURL}',
count: !{theme.newest_comments.limit}
}).then(comments => {
const walineArray = comments.map(function (e) {
return {
'content': changeContent(e.comment),
'mail': e.mail,
'nick': e.nick,
'url': e.url + '#' + e.objectId,
'date': e.createdAt,
}
})
saveToLocal.set('waline-newest-comments', JSON.stringify(walineArray), 10/(60*24))
generateHtml(walineArray)
}).catch(e => {
const $dom = document.querySelector('#card-newest-comments .aside-list')
$dom.innerHTML= "!{_p('aside.card_newest_comments.error')}"
})
}
if (typeof Waline === 'function') loadWaline()
else getScript('!{url_for(theme.CDN.waline)}').then(loadWaline)
}
const newestCommentInit = () => {
if (document.querySelector('#card-newest-comments .aside-list')) {
const data = saveToLocal.get('waline-newest-comments')
if (data) {
generateHtml(JSON.parse(data))
} else {
getComment()
}
}
}
newestCommentInit()
document.addEventListener('pjax:complete', newestCommentInit)
})

View File

@@ -1,7 +1,6 @@
if theme.aside.card_announcement.enable if theme.aside.card_announcement.enable
.card-widget.card-announcement .card-widget.card-announcement
.card-content .item-headline
.item-headline i.fas.fa-bullhorn.card-announcement-animation
i.fas.fa-bullhorn.card-announcement-animation span= _p('aside.card_announcement')
span= _p('aside.card_announcement') .announcement_content!= theme.aside.card_announcement.content
.announcement_content!= theme.aside.card_announcement.content

View File

@@ -1,12 +1,11 @@
if theme.aside.card_archives.enable if theme.aside.card_archives.enable
.card-widget.card-archives .card-widget.card-archives
.card-content .item-headline
.item-headline i.fas.fa-archive
i.fas.fa-archive span= _p('aside.card_archives')
span= _p('aside.card_archives')
- let type = theme.aside.card_archives.type || 'monthly'
- let type = theme.aside.card_archives.type || 'monthly' - let format = theme.aside.card_archives.format || 'MMMM YYYY'
- let format = theme.aside.card_archives.format || 'MMMM YYYY' - let order = theme.aside.card_archives.order || -1
- let order = theme.aside.card_archives.order || -1 - let limit = theme.aside.card_archives.limit === 0 ? 0 : theme.aside.card_archives.limit || 8
- let limit = theme.aside.card_archives.limit === 0 ? 0 : theme.aside.card_archives.limit || 8 != aside_archives({ type:type, format: format, order: order, limit: limit })
!= aside_archives({ type:type, format: format, order: order, limit: limit })

View File

@@ -1,37 +1,37 @@
if theme.aside.card_author.enable if theme.aside.card_author.enable
.card-widget.card-info .card-widget.card-info
.card-content .card-info-avatar.is-center
.card-info-avatar.is-center if theme.lazyload.enable
if theme.lazyload.enable img.avatar-img(data-lazy-src=url_for(theme.avatar.img) onerror=`this.onerror=null;this.src='` + url_for(theme.error_img.flink) + `'` alt="avatar")
img.avatar-img(data-lazy-src=url_for(theme.avatar.img) onerror=`this.onerror=null;this.src='` + url_for(theme.error_img.flink) + `'` alt="avatar") else
else img.avatar-img(src=url_for(theme.avatar.img) onerror=`this.onerror=null;this.src='` + url_for(theme.error_img.flink) + `'` alt="avatar")
img.avatar-img(src=url_for(theme.avatar.img) onerror=`this.onerror=null;this.src='` + url_for(theme.error_img.flink) + `'` alt="avatar") .author-info__name= config.author
.author-info__name= config.author .author-info__description!= theme.aside.card_author.description || config.description
.author-info__description!= theme.aside.card_author.description || config.description
.card-info-data .card-info-data
if site.posts.length if site.posts.length
.card-info-data-item.is-center .card-info-data-item.is-center
a(href=url_for(config.archive_dir) + '/') a(href=url_for(config.archive_dir) + '/')
.headline= _p('aside.articles') .headline= _p('aside.articles')
.length-num= site.posts.length .length-num= site.posts.length
if site.tags.length if site.tags.length
.card-info-data-item.is-center .card-info-data-item.is-center
a(href=url_for(config.tag_dir) + '/') a(href=url_for(config.tag_dir) + '/')
.headline= _p('aside.tags') .headline= _p('aside.tags')
.length-num= site.tags.length .length-num= site.tags.length
if site.categories.length if site.categories.length
.card-info-data-item.is-center .card-info-data-item.is-center
a(href=url_for(config.category_dir) + '/') a(href=url_for(config.category_dir) + '/')
.headline= _p('aside.categories') .headline= _p('aside.categories')
.length-num= site.categories.length .length-num= site.categories.length
if theme.aside.card_author.button.enable
a#card-info-btn.button--animated(href=theme.aside.card_author.button.link) a#card-info-btn.button--animated(href=theme.aside.card_author.button.link)
i(class=theme.aside.card_author.button.icon) i(class=theme.aside.card_author.button.icon)
span=theme.aside.card_author.button.text span=theme.aside.card_author.button.text
if(theme.social) if(theme.social)
.card-info-social-icons.is-center .card-info-social-icons.is-center
!=fragment_cache('social', function(){return partial('includes/header/social')}) !=fragment_cache('social', function(){return partial('includes/header/social')})

View File

@@ -1,8 +1,7 @@
if theme.aside.card_categories.enable if theme.aside.card_categories.enable
if site.categories.length if site.categories.length
.card-widget.card-categories .card-widget.card-categories
.card-content .item-headline
.item-headline i.fas.fa-folder-open
i.fas.fa-folder-open span= _p('aside.card_categories')
span= _p('aside.card_categories') !=aside_categories({ limit: theme.aside.card_categories.limit === 0 ? 0 : theme.aside.card_categories.limit || 8 , expand: theme.aside.card_categories.expand })
!=aside_categories({ limit: theme.aside.card_categories.limit === 0 ? 0 : theme.aside.card_categories.limit || 8 , expand: theme.aside.card_categories.expand })

View File

@@ -1,8 +1,7 @@
if theme.newest_comments.enable if theme.newest_comments.enable
.card-widget#card-newest-comments .card-widget#card-newest-comments
.card-content .item-headline
.item-headline i.fas.fa-bolt
i.fas.fa-bolt span= _p('aside.card_newest_comments.headline')
span= _p('aside.card_newest_comments.headline') .aside-list
.aside-list span= _p('aside.card_newest_comments.loading_text')
span= _p('aside.card_newest_comments.loading_text')

View File

@@ -1,13 +1,12 @@
- let tocNumber = page.toc_number !== undefined ? page.toc_number : theme.toc.number - let tocNumber = page.toc_number !== undefined ? page.toc_number : theme.toc.number
#card-toc.card-widget #card-toc.card-widget
.card-content .item-headline
.item-headline i.fas.fa-stream
i.fas.fa-stream span= _p('aside.card_toc')
span= _p('aside.card_toc')
if (page.encrypt == true) if (page.encrypt == true)
.toc-content.toc-div-class(style="display:none")!=toc(page.origin, {list_number: tocNumber}) .toc-content.toc-div-class(style="display:none")!=toc(page.origin, {list_number: tocNumber})
else else
.toc-content!=toc(page.content, {list_number: tocNumber}) .toc-content!=toc(page.content, {list_number: tocNumber})

View File

@@ -1,28 +1,27 @@
if theme.aside.card_recent_post.enable if theme.aside.card_recent_post.enable
.card-widget.card-recent-post .card-widget.card-recent-post
.card-content .item-headline
.item-headline i.fas.fa-history
i.fas.fa-history span= _p('aside.card_recent_post')
span= _p('aside.card_recent_post') .aside-list
.aside-list - let postLimit = theme.aside.card_recent_post.limit === 0 ? site.posts.length : theme.aside.card_recent_post.limit || 5
- let postLimit = theme.aside.card_recent_post.limit === 0 ? site.posts.length : theme.aside.card_recent_post.limit || 5 - let sort = theme.aside.card_recent_post.sort === 'updated' ? 'updated' : 'date'
- let sort = theme.aside.card_recent_post.sort === 'updated' ? 'updated' : 'date' - site.posts.sort(sort, -1).limit(postLimit).each(function(article){
- site.posts.sort(sort, -1).limit(postLimit).each(function(article){ - let link = article.link || article.path
- let link = article.link || article.path - let title = article.title || _p('no_title')
- let title = article.title || _p('no_title') - let no_cover = article.cover === false || !theme.cover.aside_enable ? 'no-cover' : ''
- let no_cover = article.cover === false || !theme.cover.aside_enable ? 'no-cover' : '' - let post_cover = article.cover
- let post_cover = article.cover .aside-list-item(class=no_cover)
.aside-list-item(class=no_cover) if post_cover && theme.cover.aside_enable
if post_cover && theme.cover.aside_enable a.thumbnail(href=url_for(link) title=title)
a.thumbnail(href=url_for(link) title=title) if theme.lazyload.enable
if theme.lazyload.enable img(data-lazy-src=url_for(post_cover) onerror=`this.onerror=null;this.src='${url_for(theme.error_img.post_page)}'` alt=title)
img(data-lazy-src=url_for(post_cover) onerror=`this.onerror=null;this.src='${url_for(theme.error_img.post_page)}'` alt=title)
else
img(src=url_for(post_cover) onerror=`this.onerror=null;this.src='${url_for(theme.error_img.post_page)}'` alt=title)
.content
a.title(href=url_for(link) title=title)= title
if theme.aside.card_recent_post.sort === 'updated'
time(datetime=date_xml(article.updated) title=_p('post.updated') + ' ' + full_date(article.updated)) #[=date(article.updated, config.date_format)]
else else
time(datetime=date_xml(article.date) title=_p('post.created') + ' ' + full_date(article.date)) #[=date(article.date, config.date_format)] img(src=url_for(post_cover) onerror=`this.onerror=null;this.src='${url_for(theme.error_img.post_page)}'` alt=title)
- }) .content
a.title(href=url_for(link) title=title)= title
if theme.aside.card_recent_post.sort === 'updated'
time(datetime=date_xml(article.updated) title=_p('post.updated') + ' ' + full_date(article.updated)) #[=date(article.updated, config.date_format)]
else
time(datetime=date_xml(article.date) title=_p('post.created') + ' ' + full_date(article.date)) #[=date(article.date, config.date_format)]
- })

View File

@@ -0,0 +1,9 @@
if site.data.widget
each item in site.data.widget
.card-widget(class=item.class_name id=item.id_name style=item.order ? `order: ${item.order}` : '')
.item-headline
i(class=item.icon)
span=item.name
.item-content
!=item.html

View File

@@ -1,13 +1,12 @@
if theme.aside.card_tags.enable if theme.aside.card_tags.enable
if site.tags.length if site.tags.length
.card-widget.card-tags .card-widget.card-tags
.card-content .item-headline
.item-headline i.fas.fa-tags
i.fas.fa-tags span= _p('aside.card_tags')
span= _p('aside.card_tags')
- let tagLimit = theme.aside.card_tags.limit === 0 ? 0 : theme.aside.card_tags.limit || 40 - let tagLimit = theme.aside.card_tags.limit === 0 ? 0 : theme.aside.card_tags.limit || 40
if theme.aside.card_tags.color if theme.aside.card_tags.color
.card-tag-cloud!= cloudTags({source: site.tags, minfontsize: 1.1, maxfontsize: 1.5, limit: tagLimit, unit: 'em'}) .card-tag-cloud!= cloudTags({source: site.tags, minfontsize: 1.1, maxfontsize: 1.5, limit: tagLimit, unit: 'em'})
else else
.card-tag-cloud!= tagcloud({min_font: 1.1, max_font: 1.5, amount: tagLimit , color: true, start_color: '#999', end_color: '#99a9bf', unit: 'em'}) .card-tag-cloud!= tagcloud({min_font: 1.1, max_font: 1.5, amount: tagLimit , color: true, start_color: '#999', end_color: '#99a9bf', unit: 'em'})

View File

@@ -1,32 +1,31 @@
if theme.aside.card_webinfo.enable if theme.aside.card_webinfo.enable
.card-widget.card-webinfo .card-widget.card-webinfo
.card-content .item-headline
.item-headline i.fas.fa-chart-line
i.fas.fa-chart-line span= _p('aside.card_webinfo.headline')
span= _p('aside.card_webinfo.headline') .webinfo
.webinfo if theme.aside.card_webinfo.post_count
if theme.aside.card_webinfo.post_count .webinfo-item
.webinfo-item .item-name= _p('aside.card_webinfo.article_name') + " :"
.item-name= _p('aside.card_webinfo.article_name') + " :" .item-count= site.posts.length
.item-count= site.posts.length if theme.runtimeshow.enable
if theme.runtimeshow.enable .webinfo-item
.webinfo-item .item-name= _p('aside.card_webinfo.runtime.name') + " :"
.item-name= _p('aside.card_webinfo.runtime.name') + " :" .item-count#runtimeshow(data-publishDate=date_xml(theme.runtimeshow.publish_date))
.item-count#runtimeshow(data-publishDate=date_xml(theme.runtimeshow.publish_date)) if theme.wordcount.enable && theme.wordcount.total_wordcount
if theme.wordcount.enable && theme.wordcount.total_wordcount .webinfo-item
.webinfo-item .item-name=_p('aside.card_webinfo.site_wordcount') + " :"
.item-name=_p('aside.card_webinfo.site_wordcount') + " :" .item-count=totalcount(site)
.item-count=totalcount(site) if theme.busuanzi.site_uv
if theme.busuanzi.site_uv .webinfo-item
.webinfo-item .item-name= _p('aside.card_webinfo.site_uv_name') + " :"
.item-name= _p('aside.card_webinfo.site_uv_name') + " :" .item-count#busuanzi_value_site_uv
.item-count#busuanzi_value_site_uv if theme.busuanzi.site_pv
if theme.busuanzi.site_pv .webinfo-item
.webinfo-item .item-name= _p('aside.card_webinfo.site_pv_name') + " :"
.item-name= _p('aside.card_webinfo.site_pv_name') + " :" .item-count#busuanzi_value_site_pv
.item-count#busuanzi_value_site_pv if theme.aside.card_webinfo.last_push_date
if theme.aside.card_webinfo.last_push_date .webinfo-item
.webinfo-item .item-name= _p('aside.card_webinfo.last_push_date.name') + " :"
.item-name= _p('aside.card_webinfo.last_push_date.name') + " :" .item-count#last-push-date(data-lastPushDate=date_xml(Date.now()))
.item-count#last-push-date(data-lastPushDate=date_xml(Date.now()))

View File

@@ -1,4 +1,4 @@
#aside_content.aside_content #aside-content.aside-content
//- post //- post
if is_post() if is_post()
if showToc && theme.toc.style_simple if showToc && theme.toc.style_simple
@@ -23,4 +23,5 @@
!=partial('includes/widget/card_categories', {}, {cache:theme.fragment_cache}) !=partial('includes/widget/card_categories', {}, {cache:theme.fragment_cache})
!=partial('includes/widget/card_tags', {}, {cache:theme.fragment_cache}) !=partial('includes/widget/card_tags', {}, {cache:theme.fragment_cache})
!=partial('includes/widget/card_archives', {}, {cache:theme.fragment_cache}) !=partial('includes/widget/card_archives', {}, {cache:theme.fragment_cache})
!=partial('includes/widget/card_webinfo', {}, {cache:theme.fragment_cache}) !=partial('includes/widget/card_webinfo', {}, {cache:theme.fragment_cache})
!=partial('includes/widget/card_self', {}, {cache:theme.fragment_cache})

View File

@@ -1,6 +1,6 @@
{ {
"name": "hexo-theme-butterfly", "name": "hexo-theme-butterfly",
"version": "3.4.0", "version": "3.5.1",
"description": "A Simple and Card UI Design theme for Hexo", "description": "A Simple and Card UI Design theme for Hexo",
"main": "package.json", "main": "package.json",
"scripts": { "scripts": {

View File

@@ -157,8 +157,8 @@ if $site-name-font
#site-title, #site-title,
#site-subtitle, #site-subtitle,
#site-name, #site-name,
#aside_content .author-info__name, #aside-content .author-info__name,
#aside_content .author-info__description #aside-content .author-info__description
font-family: $site-name-font font-family: $site-name-font
.is-center .is-center

View File

@@ -1,4 +1,4 @@
#aside_content #aside-content
width: 25% width: 25%
+minWidth900() +minWidth900()
@@ -20,6 +20,7 @@
position: relative position: relative
overflow: hidden overflow: hidden
margin-top: 1rem margin-top: 1rem
padding: 1rem 1.2rem
border-radius: 8px border-radius: 8px
background: var(--card-bg) background: var(--card-bg)
box-shadow: 0 4px 8px 6px rgba(7, 17, 27, .06) box-shadow: 0 4px 8px 6px rgba(7, 17, 27, .06)
@@ -53,7 +54,7 @@
.card-info-data .card-info-data
display: table display: table
padding: .7rem 0 margin: .7rem 0 .2rem
width: 100% width: 100%
table-layout: fixed table-layout: fixed
@@ -88,6 +89,7 @@
#card-info-btn #card-info-btn
display: block display: block
margin-top: .7rem
background-color: var(--btn-bg) background-color: var(--btn-bg)
color: var(--btn-color) color: var(--btn-color)
text-align: center text-align: center
@@ -96,9 +98,6 @@
span span
padding-left: .5rem padding-left: .5rem
.card-content
padding: 1rem 1.2rem
.item-headline .item-headline
padding-bottom: .3rem padding-bottom: .3rem
font-size: 1.2em font-size: 1.2em
@@ -353,8 +352,37 @@
.layout .layout
justify-content: center justify-content: center
> .aside_content > .aside-content
display: none display: none
> div:first-child > div:first-child
width: 80% width: 80%
.page
.sticky_layout
display: flex
flex-direction: column
if hexo-config('aside.card_recent_post.sort_order')
.card-recent-post
order: hexo-config('aside.card_recent_post.sort_order')
if hexo-config('newest_comments.sort_order')
#card-newest-comments
order: hexo-config('newest_comments.sort_order')
if hexo-config('aside.card_categories.sort_order')
.card-categories
order: hexo-config('aside.card_categories.sort_order')
if hexo-config('aside.card_tags.sort_order')
.card-tags
order: hexo-config('aside.card_tags.sort_order')
if hexo-config('aside.card_archives.sort_order')
.card-archives
order: hexo-config('aside.card-archives.sort_order')
if hexo-config('aside.card_webinfo.sort_order')
.card-webinfo
order: hexo-config('aside.card_webinfo.sort_order')

View File

@@ -1,4 +1,5 @@
#vcomment #vcomment,
#waline
font-size: 1.1em font-size: 1.1em
.vbtn .vbtn
@@ -9,12 +10,9 @@
&:hover &:hover
background: var(--btn-hover-color) background: var(--btn-hover-color)
if hexo-config('valine.bg') textarea
textarea &:focus
background: url(hexo-config('valine.bg')) 100% 100% no-repeat background-image: none
&:focus
background-image: none
.vimg .vimg
transition: all .3s transition: all .3s
@@ -27,6 +25,16 @@
&:after &:after
z-index: 22 z-index: 22
if hexo-config('valine.bg')
#vcomment
textarea
background: url(hexo-config('valine.bg')) 100% 100% no-repeat
if hexo-config('waline.bg')
#waline-wrap
textarea
background: url(hexo-config('waline.bg')) 100% 100% no-repeat
.fireworks .fireworks
position: fixed position: fixed
top: 0 top: 0

View File

@@ -110,7 +110,7 @@ if hexo-config('darkmode.enable') || hexo-config('display_mode') == 'dark'
.ads-wrap .ads-wrap
filter: brightness(.8) filter: brightness(.8)
#aside_content .aside-list > .aside-list-item:not(:last-child) #aside-content .aside-list > .aside-list-item:not(:last-child)
border-bottom: 1px dashed alpha(#FFFFFF, .1) border-bottom: 1px dashed alpha(#FFFFFF, .1)
// //

View File

@@ -7,7 +7,10 @@ if hexo-config('readmode')
--gray: #d6dbdf --gray: #d6dbdf
--hr-border: #d6dbdf --hr-border: #d6dbdf
--hr-before-color: darken(#d6dbdf, 10) --hr-before-color: darken(#d6dbdf, 10)
-highlight-bg: #f7f7f7 --highlight-bg: #f7f7f7
--exit-btn-bg: #C0C0C0
--exit-btn-color: #fff
--exit-btn-hover: darken(#C0C0C0, 20)
[data-theme='dark'] [data-theme='dark']
.read-mode .read-mode
@@ -18,12 +21,32 @@ if hexo-config('readmode')
--gray: rgba(255, 255, 255, .7) --gray: rgba(255, 255, 255, .7)
--hr-border: rgba(255, 255, 255, .5) --hr-border: rgba(255, 255, 255, .5)
--hr-before-color: rgba(255, 255, 255, .7) --hr-before-color: rgba(255, 255, 255, .7)
-highlight-bg: #171717 --highlight-bg: #171717
--exit-btn-bg: #1f1f1f
--exit-btn-color: rgba(255, 255, 255, .9)
--exit-btn-hover: lighten(#1f1f1f, 20)
.read-mode .read-mode
background: var(--readmode-light-color) background: var(--readmode-light-color)
#aside_content .exit-readmode
position: fixed
top: 30px
right: 30px
width: 40px
height: 40px
border-radius: 8px
background: var(--exit-btn-bg)
color: var(--exit-btn-color)
text-align: center
font-size: 16px
cursor: pointer
transition: background .3s
&:hover
background: var(--exit-btn-hover)
#aside-content
display: none display: none
#body-wrap #body-wrap
@@ -54,22 +77,13 @@ if hexo-config('readmode')
.highlight-tools, .highlight-tools,
#footer, #footer,
#post > *:not(#post-info):not(.post-content), #post > *:not(#post-info):not(.post-content),
#to_comment,
#mobile-toc-button,
#nav, #nav,
.post-outdate-notice, .post-outdate-notice,
#web_bg #web_bg,
#rightside,
.no-top-img
display: none !important display: none !important
if !hexo-config('chat_btn')
#chatra,
#tidio-chat-code,
#tidio-chat,
#daodream-container,
.gitter-chat-embed,
.gitter-open-chat-button
display: none !important
#article-container #article-container
a a
color: #99a9bf color: #99a9bf

View File

@@ -247,40 +247,38 @@ document.addEventListener('DOMContentLoaded', function () {
* fancybox和 mediumZoom * fancybox和 mediumZoom
*/ */
const addFancybox = function (ele) { const addFancybox = function (ele) {
if (ele.length) { const runFancybox = (ele) => {
const runFancybox = (ele) => { ele.each(function (i, o) {
ele.each(function (i, o) { const $this = $(o)
const $this = $(o) const lazyloadSrc = $this.attr('data-lazy-src') || $this.attr('src')
const lazyloadSrc = $this.attr('data-lazy-src') || $this.attr('src') const dataCaption = $this.attr('alt') || ''
const dataCaption = $this.attr('alt') || '' $this.wrap(`<a href="${lazyloadSrc}" data-fancybox="group" data-caption="${dataCaption}" class="fancybox"></a>`)
$this.wrap(`<a href="${lazyloadSrc}" data-fancybox="group" data-caption="${dataCaption}" class="fancybox"></a>`) })
})
$().fancybox({ $().fancybox({
selector: '[data-fancybox]', selector: '[data-fancybox]',
loop: true, loop: true,
transitionEffect: 'slide', transitionEffect: 'slide',
protect: true, protect: true,
buttons: ['slideShow', 'fullScreen', 'thumbs', 'close'], buttons: ['slideShow', 'fullScreen', 'thumbs', 'close'],
hash: false hash: false
}) })
} }
if (typeof $.fancybox === 'undefined') { if (typeof $.fancybox === 'undefined') {
$('head').append(`<link rel="stylesheet" type="text/css" href="${GLOBAL_CONFIG.source.fancybox.css}">`) $('head').append(`<link rel="stylesheet" type="text/css" href="${GLOBAL_CONFIG.source.fancybox.css}">`)
$.getScript(`${GLOBAL_CONFIG.source.fancybox.js}`, function () { $.getScript(`${GLOBAL_CONFIG.source.fancybox.js}`, function () {
runFancybox($(ele))
})
} else {
runFancybox($(ele)) runFancybox($(ele))
} })
} else {
runFancybox($(ele))
} }
} }
const addMediumZoom = () => { const addMediumZoom = () => {
const zoom = mediumZoom(document.querySelectorAll('#article-container :not(a)>img')) const zoom = mediumZoom(document.querySelectorAll('#article-container :not(a)>img'))
zoom.on('open', e => { zoom.on('open', e => {
const photoBg = $(document.documentElement).attr('data-theme') === 'dark' ? '#121212' : '#fff' const photoBg = document.documentElement.getAttribute('data-theme') === 'dark' ? '#121212' : '#fff'
zoom.update({ zoom.update({
background: photoBg background: photoBg
}) })
@@ -288,15 +286,17 @@ document.addEventListener('DOMContentLoaded', function () {
} }
const jqLoadAndRun = () => { const jqLoadAndRun = () => {
const isFancybox = GLOBAL_CONFIG.lightbox === 'fancybox' const $fancyboxEle = GLOBAL_CONFIG.lightbox === 'fancybox'
const $fancyboxEle = isFancybox ? document.querySelectorAll('#article-container :not(a):not(.gallery-group) > img, #article-container > img') : null ? document.querySelectorAll('#article-container :not(a):not(.gallery-group) > img, #article-container > img')
: []
const fbLengthNoZero = $fancyboxEle.length > 0
const $jgEle = document.querySelectorAll('#article-container .justified-gallery') const $jgEle = document.querySelectorAll('#article-container .justified-gallery')
const jgEleLength = $jgEle.length const jgLengthNoZero = $jgEle.length > 0
if (jgEleLength || $fancyboxEle !== null) { if (jgLengthNoZero || fbLengthNoZero) {
btf.isJqueryLoad(() => { btf.isJqueryLoad(() => {
jgEleLength && runJustifiedGallery($jgEle) jgLengthNoZero && runJustifiedGallery($jgEle)
isFancybox && addFancybox($fancyboxEle) fbLengthNoZero && addFancybox($fancyboxEle)
}) })
} }
} }
@@ -471,7 +471,7 @@ document.addEventListener('DOMContentLoaded', function () {
const currentActive = $tocLink[currentIndex] const currentActive = $tocLink[currentIndex]
currentActive.classList.add('active') currentActive.classList.add('active')
setTimeout(function () { setTimeout(() => {
autoScrollToc(currentActive) autoScrollToc(currentActive)
}, 0) }, 0)
@@ -488,7 +488,20 @@ document.addEventListener('DOMContentLoaded', function () {
*/ */
const rightSideFn = { const rightSideFn = {
switchReadMode: () => { // read-mode switchReadMode: () => { // read-mode
document.body.classList.toggle('read-mode') const $body = document.body
$body.classList.add('read-mode')
const newEle = document.createElement('button')
newEle.type = 'button'
newEle.className = 'fas fa-sign-out-alt exit-readmode'
$body.appendChild(newEle)
function clickFn () {
$body.classList.remove('read-mode')
newEle.remove()
newEle.removeEventListener('click', clickFn)
}
newEle.addEventListener('click', clickFn)
}, },
switchDarkMode: () => { // Switch Between Light And Dark Mode switchDarkMode: () => { // Switch Between Light And Dark Mode
const nowMode = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'light' const nowMode = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'light'
@@ -626,7 +639,7 @@ document.addEventListener('DOMContentLoaded', function () {
*/ */
const addRuntime = () => { const addRuntime = () => {
const $runtimeCount = document.getElementById('runtimeshow') const $runtimeCount = document.getElementById('runtimeshow')
if ($runtimeCount !== null) { if ($runtimeCount) {
const publishDate = $runtimeCount.getAttribute('data-publishDate') const publishDate = $runtimeCount.getAttribute('data-publishDate')
$runtimeCount.innerText = btf.diffDate(publishDate) + ' ' + GLOBAL_CONFIG.runtime $runtimeCount.innerText = btf.diffDate(publishDate) + ' ' + GLOBAL_CONFIG.runtime
} }
@@ -637,7 +650,7 @@ document.addEventListener('DOMContentLoaded', function () {
*/ */
const addLastPushDate = () => { const addLastPushDate = () => {
const $lastPushDateItem = document.getElementById('last-push-date') const $lastPushDateItem = document.getElementById('last-push-date')
if ($lastPushDateItem !== null) { if ($lastPushDateItem) {
const lastPushDate = $lastPushDateItem.getAttribute('data-lastPushDate') const lastPushDate = $lastPushDateItem.getAttribute('data-lastPushDate')
$lastPushDateItem.innerText = btf.diffDate(lastPushDate, true) $lastPushDateItem.innerText = btf.diffDate(lastPushDate, true)
} }
@@ -685,7 +698,8 @@ document.addEventListener('DOMContentLoaded', function () {
if (!$tabItem.classList.contains('active')) { if (!$tabItem.classList.contains('active')) {
const $tabContent = $tabItem.parentNode.nextElementSibling const $tabContent = $tabItem.parentNode.nextElementSibling
btf.siblings($tabItem, '.active')[0].classList.remove('active') const $siblings = btf.siblings($tabItem, '.active')[0]
$siblings && $siblings.classList.remove('active')
$tabItem.classList.add('active') $tabItem.classList.add('active')
const tabId = $this.getAttribute('data-href').replace('#', '') const tabId = $this.getAttribute('data-href').replace('#', '')
const childList = [...$tabContent.children] const childList = [...$tabContent.children]
@@ -712,7 +726,7 @@ document.addEventListener('DOMContentLoaded', function () {
const toggleCardCategory = function () { const toggleCardCategory = function () {
const $cardCategory = document.querySelectorAll('#aside-cat-list .card-category-list-item.parent i') const $cardCategory = document.querySelectorAll('#aside-cat-list .card-category-list-item.parent i')
if ($cardCategory.length > 0) { if ($cardCategory.length) {
$cardCategory.forEach(function (item) { $cardCategory.forEach(function (item) {
item.addEventListener('click', function (e) { item.addEventListener('click', function (e) {
e.preventDefault() e.preventDefault()

View File

@@ -88,8 +88,9 @@ document.addEventListener('DOMContentLoaded', function () {
translateButtonObject = document.getElementById('translateLink') translateButtonObject = document.getElementById('translateLink')
if (translateButtonObject) { if (translateButtonObject) {
if (currentEncoding !== targetEncoding) { if (currentEncoding !== targetEncoding) {
setTimeout(function () { translateBody() }, translateDelay) setTimeout(translateBody, translateDelay)
if (targetEncoding === 1) { translateButtonObject.innerHTML = msgToSimplifiedChinese } else translateButtonObject.innerHTML = msgToTraditionalChinese if (targetEncoding === 1) translateButtonObject.innerHTML = msgToSimplifiedChinese
else translateButtonObject.innerHTML = msgToTraditionalChinese
} }
translateButtonObject.addEventListener('click', translatePage, false) translateButtonObject.addEventListener('click', translatePage, false)
} }