Compare commits

...

16 Commits
4.5.1 ... 4.6.1

57 changed files with 557 additions and 379 deletions

View File

@@ -13,6 +13,11 @@ menu:
# Link: /link/ || fas fa-link # Link: /link/ || fas fa-link
# About: /about/ || fas fa-heart # About: /about/ || fas fa-heart
nav:
logo: # image
display_title: true
fixed: false # fixed navigation bar
# Code Blocks (代碼相關) # Code Blocks (代碼相關)
# -------------------------------------- # --------------------------------------
@@ -185,6 +190,7 @@ toc:
number: true number: true
expand: false expand: false
style_simple: false # for post style_simple: false # for post
scroll_percent: true
post_copyright: post_copyright:
enable: true enable: true
@@ -396,7 +402,7 @@ tidio:
public_key: public_key:
# daovoice # daovoice
# http://daovoice.io/ # http://dashboard.daovoice.io/app
daovoice: daovoice:
enable: false enable: false
app_id: app_id:
@@ -440,10 +446,6 @@ baidu_analytics:
# https://analytics.google.com/analytics/web/ # https://analytics.google.com/analytics/web/
google_analytics: google_analytics:
# CNZZ Analytics
# https://www.umeng.com/
cnzz_analytics:
# Cloudflare Analytics # Cloudflare Analytics
# https://www.cloudflare.com/zh-tw/web-analytics/ # https://www.cloudflare.com/zh-tw/web-analytics/
cloudflare_analytics: cloudflare_analytics:
@@ -623,16 +625,13 @@ subtitle:
enable: false enable: false
# Typewriter Effect (打字效果) # Typewriter Effect (打字效果)
effect: true effect: true
# Effect Speed Options (打字效果速度參數) # Customize typed.js (配置typed.js)
startDelay: 300 # time before typing starts in milliseconds # https://github.com/mattboldt/typed.js/#customization
typeSpeed: 150 # type speed in milliseconds typed_option:
backSpeed: 50 # backspacing speed in milliseconds
# loop (循環打字)
loop: true
# source 調用第三方服務 # source 調用第三方服務
# source: false 關閉調用 # source: false 關閉調用
# source: 1 調用一言網的一句話(簡體) https://hitokoto.cn/ # source: 1 調用一言網的一句話(簡體) https://hitokoto.cn/
# source: 2 調用一句網(簡體) http://yijuzhan.com/ # source: 2 調用一句網(簡體) https://yijuzhan.com/
# source: 3 調用今日詩詞(簡體) https://www.jinrishici.com/ # source: 3 調用今日詩詞(簡體) https://www.jinrishici.com/
# subtitle 會先顯示 source , 再顯示 sub 的內容 # subtitle 會先顯示 source , 再顯示 sub 的內容
source: false source: false
@@ -753,6 +752,9 @@ darkmode:
# autoChangeMode: false # autoChangeMode: false
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 (非必要請不要修改 ) # Don't modify the following settings unless you know how they work (非必要請不要修改 )
# Choose: readmode,translate,darkmode,hideAside,toc,chat,comment # Choose: readmode,translate,darkmode,hideAside,toc,chat,comment
# Don't repeat 不要重複 # Don't repeat 不要重複
@@ -894,7 +896,7 @@ CDN:
# when set it to local, you need to install hexo-butterfly-extjs # when set it to local, you need to install hexo-butterfly-extjs
third_party_provider: jsdelivr third_party_provider: jsdelivr
# Add version number to CDN, true or false # Add version number to CDN, true or false
version: false version: false
# Custom format # Custom format
@@ -952,4 +954,5 @@ CDN:
# prismjs_lineNumber_js: # prismjs_lineNumber_js:
# prismjs_autoloader: # prismjs_autoloader:
# artalk_js: # artalk_js:
# artalk_css: # artalk_css:
# busuanzi:

View File

@@ -117,5 +117,6 @@ Snackbar:
night_to_day: Light Mode Activated Manually night_to_day: Light Mode Activated Manually
loading: Loading... loading: Loading...
load_more: Load More
error404: Page not found error404: Page not found

View File

@@ -117,5 +117,6 @@ Snackbar:
night_to_day: Light Mode Activated Manually night_to_day: Light Mode Activated Manually
loading: Loading... loading: Loading...
load_more: Load More
error404: Page not found error404: Page not found

View File

@@ -118,5 +118,6 @@ Snackbar:
night_to_day: 你已切换为浅色模式 night_to_day: 你已切换为浅色模式
loading: 加载中... loading: 加载中...
load_more: 加载更多
error404: 页面没有找到 error404: 页面没有找到

View File

@@ -118,5 +118,6 @@ Snackbar:
night_to_day: 你已切換為淺色模式 night_to_day: 你已切換為淺色模式
loading: 載入中... loading: 載入中...
load_more: 載入更多
error404: 頁面沒有找到 error404: 頁面沒有找到

View File

@@ -66,4 +66,4 @@ div
!= partial("includes/third-party/pjax", {}, { cache: true }) != partial("includes/third-party/pjax", {}, { cache: true })
if theme.busuanzi.site_uv || theme.busuanzi.site_pv || theme.busuanzi.page_pv 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')

View File

@@ -15,7 +15,7 @@
meta(charset='UTF-8') meta(charset='UTF-8')
meta(http-equiv="X-UA-Compatible" content="IE=edge") 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 title= tabTitle
meta(name="author" content=pageAuthor) meta(name="author" content=pageAuthor)
meta(name="copyright" content=pageCopyright) meta(name="copyright" content=pageCopyright)
@@ -26,7 +26,7 @@ meta(name="theme-color" content=themeColor)
include ./head/Open_Graph.pug include ./head/Open_Graph.pug
!=favicon_tag(theme.favicon || config.favicon) !=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}) !=partial('includes/head/preconnect', {}, {cache: true})

View File

@@ -1,8 +1,9 @@
if theme.Open_Graph_meta.enable if theme.Open_Graph_meta.enable
- -
const coverVal = page.cover_type === 'img' ? page.cover : theme.avatar.img
let ogOption = Object.assign({ let ogOption = Object.assign({
type: is_post() ? 'article' : 'website', 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_admins: theme.facebook_comments.user_id || '',
fb_app_id: theme.facebook_comments.app_id || '', fb_app_id: theme.facebook_comments.app_id || '',
}, theme.Open_Graph_meta.option) }, theme.Open_Graph_meta.option)

View File

@@ -16,9 +16,6 @@ if theme.google_analytics
gtag('js', new Date()); gtag('js', new Date());
gtag('config', '!{theme.google_analytics}'); 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 if theme.cloudflare_analytics
script(defer data-pjax src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon=`{"token": "${theme.cloudflare_analytics}"}`) script(defer data-pjax src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon=`{"token": "${theme.cloudflare_analytics}"}`)

View File

@@ -120,5 +120,9 @@ script.
}, },
isPhotoFigcaption: !{theme.photofigcaption}, isPhotoFigcaption: !{theme.photofigcaption},
islazyload: !{theme.lazyload.enable}, 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},
}
} }

View File

@@ -6,9 +6,6 @@ if theme.google_analytics
if theme.baidu_analytics if theme.baidu_analytics
link(rel="preconnect" href="//hm.baidu.com") link(rel="preconnect" href="//hm.baidu.com")
if theme.cnzz_analytics
link(rel="preconnect" href="//s4.cnzz.com")
if theme.cloudflare_analytics if theme.cloudflare_analytics
link(rel="preconnect" href="//static.cloudflareinsights.com") 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 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='')
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") link(rel="preconnect" href="//busuanzi.ibruce.info")

View File

@@ -1,6 +1,6 @@
if !theme.disable_top_img && page.top_img !== false if !theme.disable_top_img && page.top_img !== false
if is_post() 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() else if is_page()
- var top_img = page.top_img || theme.default_top_img - var top_img = page.top_img || theme.default_top_img
else if is_tag() 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 - var top_img = page.top_img || theme.default_top_img
if top_img !== false 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 bg_img = top_img ? imgSource : ''
- var site_title = page.title || page.tag || page.category || config.title - var site_title = page.title || page.tag || page.category || config.title
- var isHomeClass = is_home() ? 'full_page' : 'not-home-page' - var isHomeClass = is_home() ? 'full_page' : 'not-home-page'
@@ -28,7 +28,9 @@ else
- var top_img = false - var top_img = false
- var isHomeClass = 'not-top-img' - var isHomeClass = 'not-top-img'
header#page-header(class=isHomeClass style=bg_img) - const isFixedClass = theme.nav.fixed ? ' fixed' : ''
header#page-header(class=`${isHomeClass+isFixedClass}` style=bg_img)
!=partial('includes/header/nav', {}, {cache: true}) !=partial('includes/header/nav', {}, {cache: true})
if top_img !== false if top_img !== false
if is_post() if is_post()

View File

@@ -1,17 +1,21 @@
nav#nav nav#nav
span#blog_name span#blog-info
a#site-name(href=url_for('/')) #[=config.title] 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 #menus
if (theme.algolia_search.enable || theme.local_search.enable) if (theme.algolia_search.enable || theme.local_search.enable)
#search-button #search-button
a.site-page.social-icon.search a.site-page.social-icon.search(href="javascript:void(0);")
i.fas.fa-search.fa-fw i.fas.fa-search.fa-fw
span=' '+_p('search.title') span=' '+_p('search.title')
!=partial('includes/header/menu_item', {}, {cache: true}) !=partial('includes/header/menu_item', {}, {cache: true})
#toggle-menu #toggle-menu
a.site-page a.site-page(href="javascript:void(0);")
i.fas.fa-bars.fa-fw i.fas.fa-bars.fa-fw

View File

@@ -33,7 +33,7 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside
if (footerBg === true) if (footerBg === true)
- var footer_bg = bg_img - var footer_bg = bg_img
else 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 else
- var footer_bg = '' - var footer_bg = ''

View File

@@ -11,7 +11,10 @@ mixin articleSort(posts)
.article-sort-item(class=no_cover) .article-sort-item(class=no_cover)
if article.cover && theme.cover.archives_enable if article.cover && theme.cover.archives_enable
a.article-sort-item-img(href=url_for(article.path) title=title) 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-info
.article-sort-item-time .article-sort-item-time
i.far.fa-calendar-alt i.far.fa-calendar-alt

View File

@@ -14,7 +14,10 @@ mixin postUI(posts)
if post_cover && theme.cover.index_enable if post_cover && theme.cover.index_enable
.post_cover(class=leftOrRight) .post_cover(class=leftOrRight)
a(href=url_for(link) title=title) 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) .recent-post-info(class=no_cover)
a.article-title(href=url_for(link) title=title)= title a.article-title(href=url_for(link) title=title)= title
.article-meta-wrap .article-meta-wrap

View File

@@ -36,6 +36,7 @@
} }
document.querySelector(".flink").insertAdjacentHTML("afterbegin", result) document.querySelector(".flink").insertAdjacentHTML("afterbegin", result)
window.lazyLoadInstance && window.lazyLoadInstance.update()
}) })
})() })()

View File

@@ -13,19 +13,23 @@ if is_post()
if(prev) if(prev)
- var hasPageNext = next ? 'pull-left' : 'pull-full' - var hasPageNext = next ? 'pull-left' : 'pull-full'
.prev-post(class=hasPageNext) .prev-post(class=hasPageNext)
- var pagination_cover = prev.cover === false ? prev.randomcover : prev.cover a(href=url_for(prev.path) title=prev.title)
a(href=url_for(prev.path)) if prev.cover_type === 'img'
img.prev-cover(src=url_for(pagination_cover) onerror=`onerror=null;src='${url_for(theme.error_img.post_page)}'` alt='cover of previous post') 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 .pagination-info
.label=_p('pagination.prev') .label=_p('pagination.prev')
.prev_info=prev.title .prev_info=prev.title
if(next) if(next)
- var hasPagePrev = prev ? 'pull-right' : 'pull-full' - var hasPagePrev = prev ? 'pull-right' : 'pull-full'
- var pagination_cover = next.cover == false ? next.randomcover : next.cover
.next-post(class=hasPagePrev) .next-post(class=hasPagePrev)
a(href=url_for(next.path)) a(href=url_for(next.path) title=next.title)
img.next-cover(src=url_for(pagination_cover) onerror=`onerror=null;src='${url_for(theme.error_img.post_page)}'` alt='cover of next post') 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 .pagination-info
.label=_p('pagination.next') .label=_p('pagination.next')
.next_info=next.title .next_info=next.title

View File

@@ -57,4 +57,5 @@ mixin rightsideItem(array)
+rightsideItem(showArray) +rightsideItem(showArray)
button#go-up(type="button" title=_p("rightside.back_to_top")) button#go-up(type="button" title=_p("rightside.back_to_top"))
span.scroll-percent
i.fas.fa-arrow-up i.fas.fa-arrow-up

View File

@@ -10,7 +10,7 @@ script.
const waline = Waline.init(initData) 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) else getScript('!{url_for(theme.asset.waline_js)}').then(initWaline)
} }

View File

@@ -1,13 +1,6 @@
- const { server, site, option } = theme.artalk - const { server, site, option } = theme.artalk
script. 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 loadArtalk () {
function initArtalk () { function initArtalk () {
window.artalkItem = new Artalk(Object.assign({ window.artalkItem = new Artalk(Object.assign({
@@ -22,7 +15,7 @@ script.
if (typeof window.artalkItem === 'object') setTimeout(()=>{initArtalk()},200) if (typeof window.artalkItem === 'object') setTimeout(()=>{initArtalk()},200)
else { else {
addArtalkSource() getCSS('!{theme.asset.artalk_css}')
typeof Artalk !== 'function' ? getScript('!{theme.asset.artalk_js}').then(initArtalk) typeof Artalk !== 'function' ? getScript('!{theme.asset.artalk_js}').then(initArtalk)
: setTimeout(()=>{initArtalk()},200) : setTimeout(()=>{initArtalk()},200)
} }

View File

@@ -2,13 +2,6 @@
script. script.
function loadDisqusjs () { 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 () { function initDisqusjs () {
window.disqusjs = null window.disqusjs = null
disqusjs = new DisqusJS(Object.assign({ disqusjs = new DisqusJS(Object.assign({
@@ -34,7 +27,7 @@ script.
if (window.disqusJsLoad) initDisqusjs() if (window.disqusJsLoad) initDisqusjs()
else { else {
addDisqusjsCSS() getCSS('!{url_for(theme.asset.disqusjs_css)}')
getScript('!{url_for(theme.asset.disqusjs)}').then(initDisqusjs) getScript('!{url_for(theme.asset.disqusjs)}').then(initDisqusjs)
window.disqusJsLoad = true window.disqusJsLoad = true
} }

View File

@@ -1,11 +1,4 @@
script. 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 loadGitalk () {
function initGitalk () { function initGitalk () {
var gitalk = new Gitalk(Object.assign({ var gitalk = new Gitalk(Object.assign({
@@ -23,7 +16,7 @@ script.
if (typeof Gitalk === 'function') initGitalk() if (typeof Gitalk === 'function') initGitalk()
else { else {
addGitalkSource() getCSS('!{url_for(theme.asset.gitalk_css)}')
getScript('!{url_for(theme.asset.gitalk)}').then(initGitalk) getScript('!{url_for(theme.asset.gitalk)}').then(initGitalk)
} }
} }

View File

@@ -3,13 +3,6 @@
script. script.
function loadWaline () { 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 () { function initWaline () {
const waline = Waline.init(Object.assign({ const waline = Waline.init(Object.assign({
el: '#waline-wrap', el: '#waline-wrap',
@@ -21,10 +14,11 @@ script.
}, !{JSON.stringify(option)})) }, !{JSON.stringify(option)}))
} }
if (typeof Waline === 'function') initWaline() if (typeof Waline === 'object') initWaline()
else { else {
insertCSS() getCSS('!{url_for(theme.asset.waline_css)}').then(() => {
getScript('!{url_for(theme.asset.waline_js)}').then(initWaline) getScript('!{url_for(theme.asset.waline_js)}').then(initWaline)
})
} }
} }

View File

@@ -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) else getScript('!{url_for(theme.asset.waline_js)}').then(loadWaline)
} }

View File

@@ -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'") link(rel='stylesheet' href=url_for(theme.asset.sharejs_css) media="print" onload="this.media='all'")
script(src=url_for(theme.asset.sharejs) defer) script(src=url_for(theme.asset.sharejs) defer)

View File

@@ -1,6 +1,30 @@
- const { effect,loop,source,sub,startDelay,typeSpeed,backSpeed } = theme.subtitle - const { effect,source,sub,typed_option } = theme.subtitle
- let subContent = sub || new Array() - let subContent = sub || new Array()
script.
window.typedJSFn = {
init: (str) => {
window.typed = new Typed('#subtitle', Object.assign({
strings: str,
startDelay: 300,
typeSpeed: 150,
loop: true,
backSpeed: 50,
}, !{JSON.stringify(typed_option)}))
},
run: (subtitleType) => {
if (!{effect}) {
if (typeof Typed === 'function') {
subtitleType()
} else {
getScript('!{url_for(theme.asset.typed)}').then(subtitleType)
}
} else {
subtitleType()
}
}
}
case source case source
when 1 when 1
script. script.
@@ -12,28 +36,13 @@ case source
const from = '出自 ' + data.from const from = '出自 ' + data.from
const sub = !{JSON.stringify(subContent)} const sub = !{JSON.stringify(subContent)}
sub.unshift(data.hitokoto, from) sub.unshift(data.hitokoto, from)
window.typed = new Typed('#subtitle', { typedJSFn.init(sub)
strings: sub,
startDelay: !{startDelay},
typeSpeed: !{typeSpeed},
loop: !{loop},
backSpeed: !{backSpeed},
})
} else { } else {
document.getElementById('subtitle').innerHTML = data.hitokoto document.getElementById('subtitle').innerHTML = data.hitokoto
} }
}) })
} }
typedJSFn.run(subtitleType)
if (!{effect}) {
if (typeof Typed === 'function') {
subtitleType()
} else {
getScript('!{url_for(theme.asset.typed)}').then(subtitleType)
}
} else {
subtitleType()
}
when 2 when 2
script. script.
@@ -44,28 +53,13 @@ case source
const from = '出自 ' + str[1] const from = '出自 ' + str[1]
const sub = !{JSON.stringify(subContent)} const sub = !{JSON.stringify(subContent)}
sub.unshift(con, from) sub.unshift(con, from)
window.typed = new Typed('#subtitle', { typedJSFn.init(sub)
strings: sub,
startDelay: !{startDelay},
typeSpeed: !{typeSpeed},
loop: !{loop},
backSpeed: !{backSpeed},
})
} else { } else {
document.getElementById('subtitle').innerHTML = con document.getElementById('subtitle').innerHTML = con
} }
}) })
} }
typedJSFn.run(subtitleType)
if (!{effect}) {
if (typeof Typed === 'function') {
subtitleType()
} else {
getScript('!{url_for(theme.asset.typed)}').then(subtitleType)
}
} else {
subtitleType()
}
when 3 when 3
script. script.
@@ -76,53 +70,23 @@ case source
const sub = !{JSON.stringify(subContent)} const sub = !{JSON.stringify(subContent)}
const content = result.data.content const content = result.data.content
sub.unshift(content) sub.unshift(content)
window.typed = new Typed('#subtitle', { typedJSFn.init(sub)
strings: sub,
startDelay: !{startDelay},
typeSpeed: !{typeSpeed},
loop: !{loop},
backSpeed: !{backSpeed},
})
} else { } else {
document.getElementById('subtitle').innerHTML = result.data.content document.getElementById('subtitle').innerHTML = result.data.content
} }
}) })
}) })
} }
typedJSFn.run(subtitleType)
if (!{effect}) {
if (typeof Typed === 'function') {
subtitleType()
} else {
getScript('!{url_for(theme.asset.typed)}').then(subtitleType)
}
} else {
subtitleType()
}
default default
- subContent = subContent.length ? subContent : new Array(config.subtitle) - subContent = subContent.length ? subContent : new Array(config.subtitle)
script. script.
function subtitleType () { function subtitleType () {
if (!{effect}) { if (!{effect}) {
window.typed = new Typed("#subtitle", { typedJSFn.init(!{JSON.stringify(subContent)})
strings: !{JSON.stringify(subContent)},
startDelay: !{startDelay},
typeSpeed: !{typeSpeed},
loop: !{loop},
backSpeed: !{backSpeed}
})
} else { } else {
document.getElementById("subtitle").innerHTML = '!{subContent[0]}' document.getElementById("subtitle").innerHTML = '!{subContent[0]}'
} }
} }
typedJSFn.run(subtitleType)
if (!{effect}) {
if (typeof Typed === 'function') {
subtitleType()
} else {
getScript('!{url_for(theme.asset.typed)}').then(subtitleType)
}
} else {
subtitleType()
}

View File

@@ -14,7 +14,10 @@ if theme.aside.card_recent_post.enable
.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)
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 .content
a.title(href=url_for(link) title=title)= title a.title(href=url_for(link) title=title)= title
if theme.aside.card_recent_post.sort === 'updated' if theme.aside.card_recent_post.sort === 'updated'

View File

@@ -1,6 +1,6 @@
{ {
"name": "hexo-theme-butterfly", "name": "hexo-theme-butterfly",
"version": "4.5.1", "version": "4.6.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

@@ -1,11 +1,11 @@
algolia_search_v4: algolia_search_v4:
name: algoliasearch name: algoliasearch
file: dist/algoliasearch-lite.umd.js file: dist/algoliasearch-lite.umd.js
version: 4.14.2 version: 4.14.3
instantsearch_v4: instantsearch_v4:
name: instantsearch.js name: instantsearch.js
file: dist/instantsearch.production.min.js file: dist/instantsearch.production.min.js
version: 4.49.0 version: 4.49.4
pjax: pjax:
name: pjax name: pjax
file: pjax.min.js file: pjax.min.js
@@ -37,17 +37,17 @@ disqusjs_css:
twikoo: twikoo:
name: twikoo name: twikoo
file: dist/twikoo.all.min.js file: dist/twikoo.all.min.js
version: 1.6.7 version: 1.6.8
waline_js: waline_js:
name: '@waline/client' name: '@waline/client'
file: dist/waline.js file: dist/waline.js
other_name: waline other_name: waline
version: 2.13.0 version: 2.14.7
waline_css: waline_css:
name: '@waline/client' name: '@waline/client'
file: dist/waline.css file: dist/waline.css
other_name: waline other_name: waline
version: 2.13.0 version: 2.14.7
sharejs: sharejs:
name: butterfly-extsrc name: butterfly-extsrc
file: sharejs/dist/js/social-share.min.js file: sharejs/dist/js/social-share.min.js
@@ -64,16 +64,16 @@ katex:
name: katex name: katex
file: dist/katex.min.css file: dist/katex.min.css
other_name: KaTeX other_name: KaTeX
version: 0.16.3 version: 0.16.4
katex_copytex: katex_copytex:
name: katex name: katex
file: dist/contrib/copy-tex.min.js file: dist/contrib/copy-tex.min.js
other_name: KaTeX other_name: KaTeX
version: 0.16.3 version: 0.16.4
mermaid: mermaid:
name: mermaid name: mermaid
file: dist/mermaid.min.js file: dist/mermaid.min.js
version: 9.1.7 version: 9.3.0
canvas_ribbon: canvas_ribbon:
name: butterfly-extsrc name: butterfly-extsrc
file: dist/canvas-ribbon.min.js file: dist/canvas-ribbon.min.js
@@ -131,7 +131,7 @@ fancybox_v4:
medium_zoom: medium_zoom:
name: medium-zoom name: medium-zoom
file: dist/medium-zoom.min.js file: dist/medium-zoom.min.js
version: 1.0.6 version: 1.0.8
snackbar_css: snackbar_css:
name: node-snackbar name: node-snackbar
file: dist/snackbar.min.css file: dist/snackbar.min.css
@@ -144,7 +144,7 @@ fontawesomeV6:
name: '@fortawesome/fontawesome-free' name: '@fortawesome/fontawesome-free'
file: css/all.min.css file: css/all.min.css
other_name: font-awesome other_name: font-awesome
version: 6.2.0 version: 6.2.1
flickr_justified_gallery_js: flickr_justified_gallery_js:
name: flickr-justified-gallery name: flickr-justified-gallery
file: dist/fjGallery.min.js file: dist/fjGallery.min.js
@@ -183,11 +183,11 @@ prismjs_autoloader:
artalk_js: artalk_js:
name: artalk name: artalk
file: dist/Artalk.js file: dist/Artalk.js
version: 2.4.3 version: 2.4.4
artalk_css: artalk_css:
name: artalk name: artalk
file: dist/Artalk.css file: dist/Artalk.css
version: 2.4.3 version: 2.4.4
pace_js: pace_js:
name: pace-js name: pace-js
other_name: pace other_name: pace

View File

@@ -12,7 +12,7 @@ hexo.extend.filter.register('before_generate', () => {
const themeConfig = hexo.theme.config const themeConfig = hexo.theme.config
const { CDN } = themeConfig 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 = { const internalSrc = {
main: { main: {
name: 'hexo-theme-butterfly', name: 'hexo-theme-butterfly',
@@ -46,7 +46,7 @@ hexo.extend.filter.register('before_generate', () => {
} }
const createCDNLink = (data, type, cond = '') => { const createCDNLink = (data, type, cond = '') => {
Object.keys(data).map(key => { Object.keys(data).forEach(key => {
let { name, version, file, other_name } = data[key] let { name, version, file, other_name } = data[key]
const min_file = minFile(file) const min_file = minFile(file)
@@ -65,6 +65,7 @@ hexo.extend.filter.register('before_generate', () => {
min_cdnjs_file, min_cdnjs_file,
cdnjs_name cdnjs_name
} }
const cdnSource = { const cdnSource = {
local: cond === 'internal' ? cdnjs_file : `/pluginsSrc/${name}/${file}`, local: cond === 'internal' ? cdnjs_file : `/pluginsSrc/${name}/${file}`,
jsdelivr: `https://cdn.jsdelivr.net/npm/${name}${verType}/${min_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}`, cdnjs: `https://cdnjs.cloudflare.com/ajax/libs/${cdnjs_name}/${version}/${min_cdnjs_file}`,
custom: (CDN.custom_format || '').replace(/\$\{(.+?)\}/g, (match, $1) => value[$1]) custom: (CDN.custom_format || '').replace(/\$\{(.+?)\}/g, (match, $1) => value[$1])
} }
data[key] = cdnSource[type] data[key] = cdnSource[type]
}) })
if (cond === 'internal') data['main_css'] = 'css/index.css' if (cond === 'internal') data.main_css = 'css/index.css'
return data return data
} }
@@ -89,6 +90,6 @@ hexo.extend.filter.register('before_generate', () => {
return obj return obj
} }
themeConfig.asset = Object.assign(createCDNLink(internalSrc,CDN.internal_provider,'internal'), themeConfig.asset = Object.assign(createCDNLink(internalSrc, CDN.internal_provider, 'internal'),
createCDNLink(thirdPartySrc,CDN.third_party_provider), deleteNullValue(CDN.option)) createCDNLink(thirdPartySrc, CDN.third_party_provider), deleteNullValue(CDN.option))
}) })

View File

@@ -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())) const newArray = use.map(item => item.toLowerCase().replace(/\b[a-z]/g, s => s.toUpperCase()))
themeConfig.comments.use = newArray themeConfig.comments.use = newArray
}) })

View File

@@ -1,8 +1,7 @@
const logger = require('hexo-log')()
hexo.extend.filter.register('before_generate', () => { hexo.extend.filter.register('before_generate', () => {
// Get first two digits of the Hexo version number // Get first two digits of the Hexo version number
const hexoVer = hexo.version.replace(/(^.*\..*)\..*/, '$1') const hexoVer = hexo.version.replace(/(^.*\..*)\..*/, '$1')
const logger = hexo.log
if (hexoVer < 5.3) { if (hexoVer < 5.3) {
logger.error('Please update Hexo to V5.3.0 or higher!') 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) { if (hexo.locals.get) {
const data = hexo.locals.get('data') const data = hexo.locals.get('data')
if (data && data.butterfly) { 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' ") logger.error(" 'butterfly.yml' 已經棄用,請使用 '_config.butterfly.yml' ")
process.exit(-1) process.exit(-1)
} }

View File

@@ -1,17 +1,13 @@
const logger = require('hexo-log')()
hexo.on('ready', () => { hexo.on('ready', () => {
const { version } = require('../../package.json') const { version } = require('../../package.json')
logger.info(` hexo.log.info(`
=================================================================== ===================================================================
##### # # ##### ##### ###### ##### ###### # # #
##### # # ##### ##### ###### ##### ###### # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # ##### # # # # ##### # # ##### # #
##### # # # # ##### # # ##### # # # # # # # # # ##### # # #
# # # # # # # ##### # # # # # # # # # # # # # # #
# # # # # # # # # # # # ##### #### # # ###### # # # ###### #
##### #### # # ###### # # # ###### #
${version} ${version}
===================================================================`) ===================================================================`)
}) })

View File

@@ -6,40 +6,40 @@
'use strict' 'use strict'
hexo.extend.filter.register('before_post_render', function (data) { hexo.extend.filter.register('before_post_render', function (data) {
const { config } = this const imgTestReg = /\.(png|jpe?g|gif|svg|webp)(\?.*)?$/
if (config.post_asset_folder) { let randomCover
const imgTestReg = /\.(png|jpe?g|gif|svg|webp)(\?.*)?$/ 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 topImg = data.top_img
const cover = data.cover
if (topImg && topImg.indexOf('/') === -1 && imgTestReg.test(topImg)) data.top_img = data.path + topImg 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) { const randomCoverFn = () => {
data.randomcover = randomCover() const theme = hexo.theme.config
return data 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 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
}
}

View File

@@ -1,13 +1,13 @@
hexo.extend.helper.register('findArchiveLength', function (func) { hexo.extend.helper.register('findArchiveLength', function (func) {
const allPostsLength = this.site.posts.length; const allPostsLength = this.site.posts.length
if (hexo.config.archive_generator && hexo.config.archive_generator.enable === false ) return allPostsLength if (hexo.config.archive_generator && hexo.config.archive_generator.enable === false) return allPostsLength
const { yearly, monthly, daily } = hexo.config.archive_generator const { yearly, monthly, daily } = hexo.config.archive_generator
const { year, month, day } = this.page const { year, month, day } = this.page
if (yearly === false || !year) return allPostsLength if (yearly === false || !year) return allPostsLength
const posts = this.site.posts.sort('date') 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') { if (type === 'year') {
return y1 === y2 return y1 === y2
} else if (type === 'month') { } else if (type === 'month') {
@@ -18,15 +18,15 @@ hexo.extend.helper.register('findArchiveLength', function (func) {
} }
const generateDateObj = (type) => { const generateDateObj = (type) => {
let dateObj = [] const dateObj = []
let length = 0 let length = 0
posts.forEach(post => { posts.forEach(post => {
let date = post.date.clone() const date = post.date.clone()
const year = date.year() const year = date.year()
const month = date.month() + 1 const month = date.month() + 1
const day = date.date() 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)) { 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}` const name = type === 'year' ? year : type === 'month' ? `${year}-${month}` : `${year}-${month}-${day}`
@@ -40,12 +40,12 @@ hexo.extend.helper.register('findArchiveLength', function (func) {
} else { } else {
lastData.count++ lastData.count++
} }
}); })
return dateObj return dateObj
} }
const data = func('createArchiveObj', ()=> { const data = func('createArchiveObj', () => {
const yearObj = yearly ? generateDateObj('year') : [] const yearObj = yearly ? generateDateObj('year') : []
const monthObj = monthly ? generateDateObj('month') : [] const monthObj = monthly ? generateDateObj('month') : []
const dayObj = daily ? generateDateObj('day') : [] 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 const name = month ? day ? `${year}-${month}-${day}` : `${year}-${month}` : year
return data.find(item => item.name === name).count return data.find(item => item.name === name).count
}) })

View File

@@ -9,8 +9,8 @@ hexo.extend.helper.register('inject_head_js', function () {
const { darkmode, aside } = this.theme const { darkmode, aside } = this.theme
const { theme_color } = hexo.theme.config const { theme_color } = hexo.theme.config
const themeColorLight = theme_color && theme_color.enable && theme_color.meta_theme_color_light || '#ffffff' 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 themeColorDark = (theme_color && theme_color.enable && theme_color.meta_theme_color_dark) || '#0d0d0d'
const localStore = ` const localStore = `
win.saveToLocal = { 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 = '' let darkmodeJs = ''
if (darkmode.enable) { if (darkmode.enable) {
darkmodeJs = ` darkmodeJs = `
@@ -144,5 +155,5 @@ hexo.extend.helper.register('inject_head_js', function () {
detectApple() detectApple()
` `
return `<script>(win=>{${localStore + getScript + darkmodeJs + asideStatus + detectApple}})(window)</script>` return `<script>(win=>{${localStore + getScript + getCSS + darkmodeJs + asideStatus + detectApple}})(window)</script>`
}) })

View File

@@ -54,8 +54,8 @@ hexo.extend.helper.register('cloudTags', function (options = {}) {
return result return result
}) })
hexo.extend.helper.register('urlNoIndex', function (url = null) { hexo.extend.helper.register('urlNoIndex', function (url = null, trailingIndex = false, trailingHtml = false) {
return prettyUrls(url || this.url, { trailing_index: false, trailing_html: false }) return prettyUrls(url || this.url, { trailing_index: trailingIndex, trailing_html: trailingHtml })
}) })
hexo.extend.helper.register('md5', function (path) { 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) { hexo.extend.helper.register('findArchivesTitle', function (page, menu, date) {
if (page.year) { if (page.year) {
const dateStr = page.month ? `${page.year}-${page.month}` : `${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' const dateFormat = page.month ? hexo.theme.config.aside.card_archives.format : 'YYYY'
return date(dateStr, date_format) return date(dateStr, dateFormat)
} }
const defaultTitle = this._p('page.archives') const defaultTitle = this._p('page.archives')
@@ -95,3 +95,11 @@ hexo.extend.helper.register('findArchivesTitle', function (page, menu, date) {
return loop(menu) || defaultTitle 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
})

View File

@@ -15,7 +15,7 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
title: post.title, title: post.title,
path: post.path, path: post.path,
cover: post.cover, cover: post.cover,
randomcover: post.randomcover, cover_type: post.cover_type,
weight: 1, weight: 1,
updated: post.updated, updated: post.updated,
created: post.date created: post.date
@@ -50,13 +50,14 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
result += '<div class="relatedPosts-list">' result += '<div class="relatedPosts-list">'
for (let i = 0; i < Math.min(relatedPosts.length, limitNum); i++) { for (let i = 0; i < Math.min(relatedPosts.length, limitNum); i++) {
const cover = const cover = relatedPosts[i].cover || 'var(--default-bg-color)'
relatedPosts[i].cover === false
? relatedPosts[i].randomcover
: relatedPosts[i].cover
const title = this.escape_html(relatedPosts[i].title) const title = this.escape_html(relatedPosts[i].title)
result += `<div><a href="${this.url_for(relatedPosts[i].path)}" title="${title}">` result += `<div><a href="${this.url_for(relatedPosts[i].path)}" title="${title}">`
result += `<img class="cover" src="${this.url_for(cover)}" alt="cover">` if (relatedPosts[i].cover_type === 'img') {
result += `<img class="cover" src="${this.url_for(cover)}" alt="cover">`
} else {
result += `<div class="cover" style="background: ${cover}"></div>`
}
if (dateType === 'created') { if (dateType === 'created') {
result += `<div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> ${this.date(relatedPosts[i].created, hexoConfig.date_format)}</div>` result += `<div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> ${this.date(relatedPosts[i].created, hexoConfig.date_format)}</div>`
} else { } else {

View File

@@ -1,6 +1,8 @@
/** /**
* Butterfly * Butterfly
* galleryGroup and allery * galleryGroup and gallery
* {% galleryGroup [name] [descr] [url] [img] %}
* {% gallery [lazyload],[rowHeight],[limit] %}
*/ */
'use strict' 'use strict'
@@ -8,13 +10,38 @@
const urlFor = require('hexo-util').url_for.bind(hexo) const urlFor = require('hexo-util').url_for.bind(hexo)
function gallery (args, content) { function gallery (args, content) {
return `<div class="fj-gallery">${hexo.render.renderSync({ text: content, engine: 'markdown' }).split('\n').join('')} const { data, languages } = hexo.theme.i18n
</div>` args = args.join(' ').split(',')
const rowHeight = args[1] || 220
const limit = args[2] || 10
const lazyload = args[0] === 'true'
const regex = /!\[(.*?)\]\(([^\s]*)\s*(?:["'](.*?)["']?)?\s*\)/g
const lazyloadClass = lazyload ? 'lazyload' : ''
let m
const arr = []
while ((m = regex.exec(content)) !== null) {
if (m.index === regex.lastIndex) {
regex.lastIndex++
}
arr.push({
url: m[2],
alt: m[1],
title: m[3]
})
}
return `<div class="gallery">
<div class="fj-gallery ${lazyloadClass}" data-rowHeight="${rowHeight}" data-limit="${limit}">
<span class="gallery-data">${JSON.stringify(arr)}</span>
</div>
<button class="gallery-load-more"><span>${data[languages[0]].load_more}</span><i class="fa-solid fa-arrow-down"></i></button>
</div>`
} }
function galleryGroup (args) { function galleryGroup (args) {
const name = args[0] const name = args[0]
const desrc = args[1] const descr = args[1]
const url = urlFor(args[2]) const url = urlFor(args[2])
const img = urlFor(args[3]) const img = urlFor(args[3])
@@ -23,7 +50,7 @@ function galleryGroup (args) {
<img class="gallery-group-img no-lightbox" src='${img}' alt="Group Image Gallery"> <img class="gallery-group-img no-lightbox" src='${img}' alt="Group Image Gallery">
<figcaption> <figcaption>
<div class="gallery-group-name">${name}</div> <div class="gallery-group-name">${name}</div>
<p>${desrc}</p> <p>${descr}</p>
<a href='${url}'></a> <a href='${url}'></a>
</figcaption> </figcaption>
</figure> </figure>

View File

@@ -36,11 +36,11 @@
.postImgHover .postImgHover
&:hover &:hover
img .cover
opacity: .8 opacity: .8
transform: scale(1.1) transform: scale(1.1)
img .cover
position: absolute position: absolute
width: 100% width: 100%
height: 100% height: 100%

View File

@@ -33,6 +33,7 @@
--pseudo-hover: $pseudo-hover --pseudo-hover: $pseudo-hover
--headline-presudo: #a0a0a0 --headline-presudo: #a0a0a0
--scrollbar-color: $scrollbar-color --scrollbar-color: $scrollbar-color
--default-bg-color: $theme-color
body body
position: relative position: relative
@@ -165,7 +166,7 @@ a
if $site-name-font 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

View File

@@ -115,7 +115,7 @@
width: w = 4.2em width: w = 4.2em
height: w height: w
& > img :first-child
@extend .imgHover @extend .imgHover
.content .content

View File

@@ -1,6 +1,6 @@
#footer #footer
position: relative position: relative
background: $light-blue background-color: $light-blue
background-attachment: scroll background-attachment: scroll
background-position: bottom background-position: bottom
background-size: cover background-size: cover

View File

@@ -124,7 +124,8 @@
background: rgba(255, 255, 255, .8) background: rgba(255, 255, 255, .8)
box-shadow: 0 5px 6px -5px rgba(133, 133, 133, .6) box-shadow: 0 5px 6px -5px rgba(133, 133, 133, .6)
a a,
.site-name
color: var(--font-color) color: var(--font-color)
text-shadow: none text-shadow: none
@@ -137,8 +138,16 @@
box-shadow: 0 5px 6px -5px alpha($grey, .6) box-shadow: 0 5px 6px -5px alpha($grey, .6)
transition: transform .2s ease-in-out, opacity .2s ease-in-out transition: transform .2s ease-in-out, opacity .2s ease-in-out
#blog-info
color: var(--font-color)
&:hover
color: $light-blue
.site-name
text-shadow: none
a, a,
#site-name,
#toggle-menu #toggle-menu
color: var(--font-color) color: var(--font-color)
text-shadow: none text-shadow: none
@@ -146,7 +155,12 @@
&:hover &:hover
color: $light-blue color: $light-blue
&.nav-visible &.fixed
#nav
top: 0
transition: all .5s
&.nav-visible:not(.fixed)
#nav #nav
transition: all .5s transition: all .5s
transform: translate3d(0, 100%, 0) transform: translate3d(0, 100%, 0)
@@ -156,6 +170,19 @@
top: 70px top: 70px
transition: top .5s transition: top .5s
&.fixed
#nav
position: fixed
& + .layout
& > .aside-content > .sticky_layout
top: 70px
transition: top .5s
#card-toc
.toc-content
max-height: calc(100vh - 170px)
#page #page
h1.page-title h1.page-title
margin: 8px 0 20px margin: 8px 0 20px
@@ -253,8 +280,15 @@
&.show &.show
opacity: 1 opacity: 1
#blog_name #blog-info
flex: 1 flex: 1
color: var(--light-grey)
@extend .limit-one-line
.site-icon
margin-right: 6px
height: 36px
vertical-align: middle
#toggle-menu #toggle-menu
display: none display: none
@@ -270,10 +304,9 @@
&:hover &:hover
color: var(--white) color: var(--white)
#site-name .site-name
text-shadow: 2px 2px 4px rgba($dark-black, .15) text-shadow: 2px 2px 4px rgba($dark-black, .15)
font-weight: bold font-weight: bold
cursor: pointer
.menus_items .menus_items
display: inline display: inline

View File

@@ -47,3 +47,22 @@
+maxWidth900() +maxWidth900()
#hide-aside-btn #hide-aside-btn
display: none display: none
if hexo-config('rightside_scroll_percent')
#go-up
.scroll-percent
display: none
&.show-percent
.scroll-percent
display: block
& + i
display: none
&:hover
.scroll-percent
display: none
& + i
display: block

View File

@@ -106,7 +106,7 @@ if hexo-config('readmode')
color: var(--font-color) !important color: var(--font-color) !important
.hljs .hljs
background: var(-highlight-bg) !important background: var(--highlight-bg) !important
h1, h1,
h2, h2,

View File

@@ -101,7 +101,7 @@
width: 80px width: 80px
height: 80px height: 80px
img :first-child
@extend .imgHover @extend .imgHover
&-info &-info

View File

@@ -15,7 +15,7 @@
height: auto height: auto
&:hover &:hover
img.post_bg img.post-bg
transform: scale(1.1) transform: scale(1.1)
&.ads-wrap &.ads-wrap
@@ -31,7 +31,7 @@
width: 100% width: 100%
height: 230px height: 230px
img.post_bg .post-bg
@extend .imgHover @extend .imgHover
&.right &.right

View File

@@ -28,7 +28,7 @@
.algolia-hit-item-content .algolia-hit-item-content
margin: 0 0 8px margin: 0 0 8px
word-break: break-all word-break: break-word
.ais-Pagination .ais-Pagination
margin: 20px 0 0 margin: 20px 0 0
@@ -69,6 +69,8 @@
#algolia-hits #algolia-hits
> div > div
overflow-y: scroll overflow-y: scroll
margin: 0 -20px
padding: 0 22px
+minWidth768() +minWidth768()
max-height: calc(80vh - 240px) max-height: calc(80vh - 240px)

View File

@@ -51,15 +51,17 @@
color: $search-color color: $search-color
.search-result .search-result
margin: 0 8px 8px 0 margin: 0 0 8px
word-break: break-all word-break: break-word
.search-keyword .search-keyword
color: $search-keyword-highlight color: $search-keyword-highlight
font-weight: bold font-weight: bold
.search-result-list .search-result-list
overflow-y: auto overflow-y: overlay
margin: 0 -20px
padding: 0 22px
max-height: calc(80vh - 130px) max-height: calc(80vh - 130px)
+maxWidth768() +maxWidth768()

View File

@@ -94,9 +94,46 @@
overflow: auto overflow: auto
padding: 0 0 16px padding: 0 0 16px
.fj-gallery .gallery
margin: 0 0 16px margin: 0 0 16px
opacity: 0 text-align: center
.img-alt .fj-gallery
display: none opacity: 0
.img-alt
display: none
&.lazyload
+ button
display: inline-block
.gallery-data
display: none
button
display: none
margin-top: 25px
padding: 10px
width: 9em
border-radius: 5px
background: var(--btn-bg)
color: var(--btn-color)
font-weight: bold
font-size: 1.1em
transition: all .3s
& > *
transition: all .4s
i
width: 0
opacity: 0
&:hover
background: var(--btn-hover-color)
i
margin-left: 2px
width: 20px
opacity: 1

View File

@@ -1,21 +1,24 @@
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
let blogNameWidth, menusWidth, searchWidth, $nav let headerContentWidth, $nav
let mobileSidebarOpen = false let mobileSidebarOpen = false
const adjustMenu = (init) => { const adjustMenu = init => {
const getAllWidth = ele => {
let width = 0
ele.length && Array.from(ele).forEach(i => { width += i.offsetWidth })
return width
}
if (init) { if (init) {
blogNameWidth = document.getElementById('site-name').offsetWidth const blogInfoWidth = getAllWidth(document.querySelector('#blog-info > a').children)
const $menusEle = document.querySelectorAll('#menus .menus_item') const menusWidth = getAllWidth(document.getElementById('menus').children)
menusWidth = 0 headerContentWidth = blogInfoWidth + menusWidth
$menusEle.length && $menusEle.forEach(i => { menusWidth += i.offsetWidth })
const $searchEle = document.querySelector('#search-button')
searchWidth = $searchEle ? $searchEle.offsetWidth : 0
$nav = document.getElementById('nav') $nav = document.getElementById('nav')
} }
let hideMenuIndex = '' let hideMenuIndex = ''
if (window.innerWidth <= 768) hideMenuIndex = true if (window.innerWidth <= 768) hideMenuIndex = true
else hideMenuIndex = blogNameWidth + menusWidth + searchWidth > $nav.offsetWidth - 120 else hideMenuIndex = headerContentWidth > $nav.offsetWidth - 120
if (hideMenuIndex) { if (hideMenuIndex) {
$nav.classList.add('hide-menu') $nav.classList.add('hide-menu')
@@ -229,14 +232,42 @@ document.addEventListener('DOMContentLoaded', function () {
* justified-gallery 圖庫排版 * justified-gallery 圖庫排版
*/ */
const runJustifiedGallery = function (ele) { const runJustifiedGallery = function (ele) {
ele.forEach(item => { const htmlStr = arr => {
const $imgList = item.querySelectorAll('img') let str = ''
const replaceDq = str => str.replace(/"/g, '&quot;') // replace double quotes to &quot;
$imgList.forEach(i => { arr.forEach(i => {
const dataLazySrc = i.getAttribute('data-lazy-src') const alt = i.alt ? `alt="${replaceDq(i.alt)}"` : ''
if (dataLazySrc) i.src = dataLazySrc const title = i.title ? `title="${replaceDq(i.title)}"` : ''
btf.wrap(i, 'div', { class: 'fj-gallery-item' }) str += `<div class="fj-gallery-item"><img src="${i.url}" ${alt + title}"></div>`
}) })
return str
}
const lazyloadFn = (i, arr) => {
const loadItem = i.getAttribute('data-limit')
const arrLength = arr.length
if (arrLength > loadItem) i.insertAdjacentHTML('beforeend', htmlStr(arr.splice(0, loadItem)))
else {
i.insertAdjacentHTML('beforeend', htmlStr(arr))
i.classList.remove('lazyload')
}
return arrLength > loadItem ? loadItem : arrLength
}
ele.forEach(item => {
const arr = JSON.parse(item.querySelector('.gallery-data').textContent)
if (!item.classList.contains('lazyload')) item.innerHTML = htmlStr(arr)
else {
lazyloadFn(item, arr)
const limit = item.getAttribute('data-limit')
const clickBtnFn = () => {
const lastItemLength = lazyloadFn(item, arr)
fjGallery(item, 'appendImages', item.querySelectorAll(`.fj-gallery-item:nth-last-child(-n+${lastItemLength})`))
btf.loadLightbox(item.querySelectorAll('img'))
lastItemLength < limit && item.nextElementSibling.removeEventListener('click', clickBtnFn)
}
item.nextElementSibling.addEventListener('click', clickBtnFn)
}
}) })
if (window.fjGallery) { if (window.fjGallery) {
@@ -244,13 +275,24 @@ document.addEventListener('DOMContentLoaded', function () {
return return
} }
const newEle = document.createElement('link') getCSS(`${GLOBAL_CONFIG.source.justifiedGallery.css}`)
newEle.rel = 'stylesheet'
newEle.href = GLOBAL_CONFIG.source.justifiedGallery.css
document.body.appendChild(newEle)
getScript(`${GLOBAL_CONFIG.source.justifiedGallery.js}`).then(() => { btf.initJustifiedGallery(ele) }) getScript(`${GLOBAL_CONFIG.source.justifiedGallery.js}`).then(() => { btf.initJustifiedGallery(ele) })
} }
/**
* rightside scroll percent
*/
const rightsideScrollPercent = currentTop => {
const perNum = btf.getScrollPercent(currentTop, document.body)
const $goUp = document.getElementById('go-up')
if (perNum < 95) {
$goUp.classList.add('show-percent')
$goUp.querySelector('.scroll-percent').textContent = perNum
} else {
$goUp.classList.remove('show-percent')
}
}
/** /**
* 滾動處理 * 滾動處理
*/ */
@@ -276,40 +318,43 @@ document.addEventListener('DOMContentLoaded', function () {
const $header = document.getElementById('page-header') const $header = document.getElementById('page-header')
const isChatBtnHide = typeof chatBtnHide === 'function' const isChatBtnHide = typeof chatBtnHide === 'function'
const isChatBtnShow = typeof chatBtnShow === 'function' const isChatBtnShow = typeof chatBtnShow === 'function'
const isShowPercent = GLOBAL_CONFIG.percent.rightside
const scrollTask = btf.throttle(() => { const scrollTask = btf.throttle(() => {
const currentTop = window.scrollY || document.documentElement.scrollTop const currentTop = window.scrollY || document.documentElement.scrollTop
const isDown = scrollDirection(currentTop) const isDown = scrollDirection(currentTop)
if (currentTop > 56) { if (currentTop > 56) {
if (isDown) { if (isDown) {
if ($header.classList.contains('nav-visible')) $header.classList.remove('nav-visible') if ($header.classList.contains('nav-visible')) $header.classList.remove('nav-visible')
if (isChatBtnShow && isChatShow === true) { if (isChatBtnShow && isChatShow === true) {
chatBtnHide() chatBtnHide()
isChatShow = false isChatShow = false
}
} else {
if (!$header.classList.contains('nav-visible')) $header.classList.add('nav-visible')
if (isChatBtnHide && isChatShow === false) {
chatBtnShow()
isChatShow = true
}
}
$header.classList.add('nav-fixed')
if (window.getComputedStyle($rightside).getPropertyValue('opacity') === '0') {
$rightside.style.cssText = 'opacity: 0.8; transform: translateX(-58px)'
} }
} else { } else {
if (currentTop === 0) { if (!$header.classList.contains('nav-visible')) $header.classList.add('nav-visible')
$header.classList.remove('nav-fixed', 'nav-visible') if (isChatBtnHide && isChatShow === false) {
chatBtnShow()
isChatShow = true
} }
$rightside.style.cssText = "opacity: ''; transform: ''"
} }
$header.classList.add('nav-fixed')
if (document.body.scrollHeight <= innerHeight) { if (window.getComputedStyle($rightside).getPropertyValue('opacity') === '0') {
$rightside.style.cssText = 'opacity: 0.8; transform: translateX(-58px)' $rightside.style.cssText = 'opacity: 0.8; transform: translateX(-58px)'
} }
}, 200) } else {
if (currentTop === 0) {
$header.classList.remove('nav-fixed', 'nav-visible')
}
$rightside.style.cssText = "opacity: ''; transform: ''"
}
isShowPercent && rightsideScrollPercent(currentTop)
if (document.body.scrollHeight <= innerHeight) {
$rightside.style.cssText = 'opacity: 0.8; transform: translateX(-58px)'
}
}, 200)
window.scrollCollect = scrollTask window.scrollCollect = scrollTask
window.addEventListener('scroll', scrollCollect) window.addEventListener('scroll', scrollCollect)
@@ -325,26 +370,15 @@ document.addEventListener('DOMContentLoaded', function () {
if (!($article && (isToc || isAnchor))) return if (!($article && (isToc || isAnchor))) return
let $tocLink, $cardToc, scrollPercent, autoScrollToc, isExpand let $tocLink, $cardToc, autoScrollToc, $tocPercentage, isExpand
if (isToc) { if (isToc) {
const $cardTocLayout = document.getElementById('card-toc') const $cardTocLayout = document.getElementById('card-toc')
$cardToc = $cardTocLayout.getElementsByClassName('toc-content')[0] $cardToc = $cardTocLayout.getElementsByClassName('toc-content')[0]
$tocLink = $cardToc.querySelectorAll('.toc-link') $tocLink = $cardToc.querySelectorAll('.toc-link')
const $tocPercentage = $cardTocLayout.querySelector('.toc-percentage') $tocPercentage = $cardTocLayout.querySelector('.toc-percentage')
isExpand = $cardToc.classList.contains('is-expand') isExpand = $cardToc.classList.contains('is-expand')
scrollPercent = currentTop => {
const docHeight = $article.clientHeight
const winHeight = document.documentElement.clientHeight
const headerHeight = $article.offsetTop
const contentMath = (docHeight > winHeight) ? (docHeight - winHeight) : (document.documentElement.scrollHeight - winHeight)
const scrollPercent = (currentTop - headerHeight) / (contentMath)
const scrollPercentRounded = Math.round(scrollPercent * 100)
const percentage = (scrollPercentRounded > 100) ? 100 : (scrollPercentRounded <= 0) ? 0 : scrollPercentRounded
$tocPercentage.textContent = percentage
}
window.mobileToc = { window.mobileToc = {
open: () => { open: () => {
$cardTocLayout.style.cssText = 'animation: toc-open .3s; opacity: 1; right: 55px' $cardTocLayout.style.cssText = 'animation: toc-open .3s; opacity: 1; right: 55px'
@@ -433,13 +467,14 @@ document.addEventListener('DOMContentLoaded', function () {
} }
// main of scroll // main of scroll
window.tocScrollFn = function () { window.tocScrollFn = btf.throttle(() => {
return btf.throttle(function () { const currentTop = window.scrollY || document.documentElement.scrollTop
const currentTop = window.scrollY || document.documentElement.scrollTop if (isToc && GLOBAL_CONFIG.percent.toc) {
isToc && scrollPercent(currentTop) $tocPercentage.textContent = btf.getScrollPercent(currentTop, $article)
findHeadPosition(currentTop) }
}, 100)() findHeadPosition(currentTop)
} }, 100)
window.addEventListener('scroll', tocScrollFn) window.addEventListener('scroll', tocScrollFn)
} }

View File

@@ -56,7 +56,7 @@ window.addEventListener('load', () => {
post = '...' post = '...'
} }
let matchContent = pre + content.substring(start, end) + post const matchContent = pre + content.substring(start, end) + post
return matchContent return matchContent
} }
@@ -68,10 +68,11 @@ window.addEventListener('load', () => {
const search = instantsearch({ const search = instantsearch({
indexName: algolia.indexName, indexName: algolia.indexName,
/* global algoliasearch */
searchClient: algoliasearch(algolia.appId, algolia.apiKey), searchClient: algoliasearch(algolia.appId, algolia.apiKey),
searchFunction(helper) { searchFunction (helper) {
helper.state.query && helper.search() helper.state.query && helper.search()
}, }
}) })
const configure = instantsearch.widgets.configure({ const configure = instantsearch.widgets.configure({
@@ -89,16 +90,16 @@ window.addEventListener('load', () => {
const hits = instantsearch.widgets.hits({ const hits = instantsearch.widgets.hits({
container: '#algolia-hits', container: '#algolia-hits',
templates: { templates: {
item(data) { item (data) {
const link = data.permalink ? data.permalink : (GLOBAL_CONFIG.root + data.path) const link = data.permalink ? data.permalink : (GLOBAL_CONFIG.root + data.path)
const result = data._highlightResult const result = data._highlightResult
const content = result.contentStripTruncate const content = result.contentStripTruncate
? cutContent(result.contentStripTruncate.value) ? cutContent(result.contentStripTruncate.value)
: result.contentStrip : result.contentStrip
? cutContent(result.contentStrip.value) ? cutContent(result.contentStrip.value)
: result.content : result.content
? cutContent(result.content.value) ? cutContent(result.content.value)
: '' : ''
return ` return `
<a href="${link}" class="algolia-hit-item-link"> <a href="${link}" class="algolia-hit-item-link">
${result.title.value || 'no-title'} ${result.title.value || 'no-title'}
@@ -130,7 +131,7 @@ window.addEventListener('load', () => {
}) })
const powerBy = instantsearch.widgets.poweredBy({ const powerBy = instantsearch.widgets.poweredBy({
container: '#algolia-info > .algolia-poweredBy', container: '#algolia-info > .algolia-poweredBy'
}) })
const pagination = instantsearch.widgets.pagination({ const pagination = instantsearch.widgets.pagination({
@@ -144,8 +145,7 @@ window.addEventListener('load', () => {
} }
}) })
search.addWidgets([configure, searchBox, hits, stats, powerBy, pagination]) // add the widgets to the instantsearch instance
search.addWidgets([configure,searchBox,hits,stats,powerBy,pagination]) // add the widgets to the instantsearch instance
search.start() search.start()

View File

@@ -56,7 +56,7 @@ window.addEventListener('load', () => {
const res = await response.text() const res = await response.text()
const t = await new window.DOMParser().parseFromString(res, 'text/xml') const t = await new window.DOMParser().parseFromString(res, 'text/xml')
const a = await t const a = await t
data = [...a.querySelectorAll('entry')].map(item =>{ data = [...a.querySelectorAll('entry')].map(item => {
return { return {
title: item.querySelector('title').textContent, title: item.querySelector('title').textContent,
content: item.querySelector('content') && item.querySelector('content').textContent, content: item.querySelector('content') && item.querySelector('content').textContent,
@@ -84,8 +84,11 @@ window.addEventListener('load', () => {
$input.addEventListener('input', function () { $input.addEventListener('input', function () {
const keywords = this.value.trim().toLowerCase().split(/[\s]+/) const keywords = this.value.trim().toLowerCase().split(/[\s]+/)
if (keywords[0] !== '') $loadingStatus.innerHTML = '<i class="fas fa-spinner fa-pulse"></i>' if (keywords[0] !== '') $loadingStatus.innerHTML = '<i class="fas fa-spinner fa-pulse"></i>'
else {
$resultContent.innerHTML = ''
return
}
$resultContent.innerHTML = ''
let str = '<div class="search-result-list">' let str = '<div class="search-result-list">'
if (keywords.length <= 0) return if (keywords.length <= 0) return
let count = 0 let count = 0
@@ -150,7 +153,12 @@ window.addEventListener('load', () => {
// highlight all keywords // highlight all keywords
keywords.forEach(keyword => { keywords.forEach(keyword => {
const regS = new RegExp(keyword, 'gi') let regexStr = keyword
const specialRegex = /[^\w\s]+/ // match special characters
if (keyword.length === 1 && specialRegex.test(keyword)) {
regexStr = `\\${keyword}`
}
const regS = new RegExp(regexStr, 'gi')
matchContent = matchContent.replace(regS, '<span class="search-keyword">' + keyword + '</span>') matchContent = matchContent.replace(regS, '<span class="search-keyword">' + keyword + '</span>')
dataTitle = dataTitle.replace(regS, '<span class="search-keyword">' + keyword + '</span>') dataTitle = dataTitle.replace(regS, '<span class="search-keyword">' + keyword + '</span>')
}) })

File diff suppressed because one or more lines are too long

View File

@@ -62,10 +62,10 @@ const btf = {
const { position, bgLight, bgDark } = GLOBAL_CONFIG.Snackbar const { position, bgLight, bgDark } = GLOBAL_CONFIG.Snackbar
const bg = document.documentElement.getAttribute('data-theme') === 'light' ? bgLight : bgDark const bg = document.documentElement.getAttribute('data-theme') === 'light' ? bgLight : bgDark
Snackbar.show({ Snackbar.show({
text: text, text,
backgroundColor: bg, backgroundColor: bg,
showAction: showAction, showAction,
duration: duration, duration,
pos: position, pos: position,
customClass: 'snackbar-css' customClass: 'snackbar-css'
}) })
@@ -88,7 +88,7 @@ const btf = {
const minuteCount = dateDiff / minute const minuteCount = dateDiff / minute
if (monthCount > 12) { if (monthCount > 12) {
result = datePost.toLocaleDateString().replace(/\//g, '-') result = datePost.toISOString().slice(0, 10)
} else if (monthCount >= 1) { } else if (monthCount >= 1) {
result = parseInt(monthCount) + ' ' + GLOBAL_CONFIG.date_suffix.month result = parseInt(monthCount) + ' ' + GLOBAL_CONFIG.date_suffix.month
} else if (dayCount >= 1) { } else if (dayCount >= 1) {
@@ -122,7 +122,8 @@ const btf = {
scrollToDest: (pos, time = 500) => { scrollToDest: (pos, time = 500) => {
const currentPos = window.pageYOffset const currentPos = window.pageYOffset
if (currentPos > pos) pos = pos - 70 const isNavFixed = document.getElementById('page-header').classList.contains('fixed')
if (currentPos > pos || isNavFixed) pos = pos - 70
if ('scrollBehavior' in document.documentElement.style) { if ('scrollBehavior' in document.documentElement.style) {
window.scrollTo({ window.scrollTo({
@@ -186,12 +187,12 @@ const btf = {
* @param {*} options object key: value * @param {*} options object key: value
*/ */
wrap: (selector, eleType, options) => { wrap: (selector, eleType, options) => {
const creatEle = document.createElement(eleType) const createEle = document.createElement(eleType)
for (const [key, value] of Object.entries(options)) { for (const [key, value] of Object.entries(options)) {
creatEle.setAttribute(key, value) createEle.setAttribute(key, value)
} }
selector.parentNode.insertBefore(creatEle, selector) selector.parentNode.insertBefore(createEle, selector)
creatEle.appendChild(selector) createEle.appendChild(selector)
}, },
unwrap: el => { unwrap: el => {
@@ -255,7 +256,7 @@ const btf = {
if (!btf.isHidden(i)) { if (!btf.isHidden(i)) {
fjGallery(i, { fjGallery(i, {
itemSelector: '.fj-gallery-item', itemSelector: '.fj-gallery-item',
rowHeight: 220, rowHeight: i.getAttribute('data-rowHeight'),
gutter: 4, gutter: 4,
onJustify: function () { onJustify: function () {
this.$container.style.opacity = '1' this.$container.style.opacity = '1'
@@ -271,8 +272,19 @@ const btf = {
const title = GLOBAL_CONFIG_SITE.title const title = GLOBAL_CONFIG_SITE.title
window.history.replaceState({ window.history.replaceState({
url: location.href, url: location.href,
title: title title
}, title, anchor) }, title, anchor)
} }
},
getScrollPercent: (currentTop, ele) => {
const docHeight = ele.clientHeight
const winHeight = document.documentElement.clientHeight
const headerHeight = ele.offsetTop
const contentMath = (docHeight > winHeight) ? (docHeight - winHeight) : (document.documentElement.scrollHeight - winHeight)
const scrollPercent = (currentTop - headerHeight) / (contentMath)
const scrollPercentRounded = Math.round(scrollPercent * 100)
const percentage = (scrollPercentRounded > 100) ? 100 : (scrollPercentRounded <= 0) ? 0 : scrollPercentRounded
return percentage
} }
} }