feat: 增加首頁評論數顯示

fix: 修復點擊toc後,滾動完toc的highlight在點擊的上一個元素
fix: 修復打賞按鈕Hover的bug close #473
improvement: 友情鏈接界面增加title顯示(top_img設為false時)
improvement: 優化toc顯示,當向上滾動時,導航欄不會遮擋 toc close #472
improvement: 升級facebook comment sdk版本
This commit is contained in:
Jerry
2021-01-25 19:39:53 +08:00
parent d33dc5551c
commit 6962353af6
27 changed files with 400 additions and 237 deletions

View File

@@ -266,7 +266,8 @@ comments:
# lazyload: The comment system will be load when comment element enters the browser's viewport.
# If you set it to true, the comment count will be invalid
lazyload: false
count: false # Display comment count in top_img
count: false # Display comment count in post's top_img
card_post_count: false # Display comment count in Home Page
# disqus
# https://disqus.com/

View File

@@ -13,6 +13,8 @@ page:
category: Category
archives: Archives
card_post_count: comments
sticky: Sticky
no_title: No title

View File

@@ -13,6 +13,8 @@ page:
category: Category
archives: Archives
card_post_count: comments
sticky: Sticky
no_title: No title

View File

@@ -13,6 +13,8 @@ page:
category: 分类
archives: 归档
card_post_count: 条评论
sticky: 置顶
no_title: 无题

View File

@@ -13,6 +13,8 @@ page:
category: 分類
archives: 歸檔
card_post_count: 條評論
sticky: 置頂
no_title: 無題

View File

@@ -30,6 +30,9 @@ div
!=partial('includes/loading/loading-js', {}, {cache: true})
.js-pjax
if needLoadCountJs
!=partial('includes/third-party/card-post-count/index', {}, {cache: true})
if loadSubJs
include ./third-party/subtitle.pug

View File

@@ -20,13 +20,13 @@ if !theme.disable_top_img && page.top_img !== false
- var imgSource = top_img && top_img.indexOf('/') !== -1 ? `background-image: url('${url_for(top_img)}')` : `background: ${top_img}`
- var bg_img = top_img ? imgSource : ''
- var site_title = is_archive() ? _p('page.archives') : page.title || page.tag || page.category || config.title
- var isHomeClass = is_home() ? 'full_page' : 'not-index-bg'
- var isHomeClass = is_home() ? 'full_page' : 'not-home-page'
- is_post() ? isHomeClass = 'post-bg' : isHomeClass
else
- var isHomeClass = 'no-top-img'
- var isHomeClass = 'not-top-img'
else
- var top_img = false
- var isHomeClass = 'no-top-img'
- var isHomeClass = 'not-top-img'
header#page-header(class=isHomeClass style=bg_img)
!=partial('includes/header/nav', {}, {cache: true})

View File

@@ -18,7 +18,7 @@ mixin postUI(posts)
.article-meta-wrap
if (is_home() && (article.top || article.sticky > 0))
span.article-meta
i.fas.fa-thumbtack.article-meta__icon.sticky
i.fas.fa-thumbtack.sticky
span.sticky= _p('sticky')
span.article-meta__separator |
if (theme.post_meta.page.date_type)
@@ -42,7 +42,7 @@ mixin postUI(posts)
if (theme.post_meta.page.categories && article.categories.data.length > 0)
span.article-meta
span.article-meta__separator |
i.fas.fa-inbox.article-meta__icon
i.fas.fa-inbox
each item, index in article.categories.data
a(href=url_for(item.path)).article-meta__categories #[=item.name]
if (index < article.categories.data.length - 1)
@@ -50,12 +50,43 @@ mixin postUI(posts)
if (theme.post_meta.page.tags && article.tags.data.length > 0)
span.article-meta.tags
span.article-meta__separator |
i.fas.fa-tag.article-meta__icon
i.fas.fa-tag
each item, index in article.tags.data
a(href=url_for(item.path)).article-meta__tags #[=item.name]
if (index < article.tags.data.length - 1)
span.article-meta__link #[='•']
mixin countBlockInIndex
- needLoadCountJs = true
span.article-meta
span.article-meta__separator |
i.fas.fa-comments
if block
block
span.article-meta-label= ' ' + _p('card_post_count')
if theme.comments.card_post_count
case theme.comments.use[0]
when 'Disqus'
when 'Disqusjs'
+countBlockInIndex
a(href=full_url_for(link) + '#disqus_thread')
when 'Valine'
+countBlockInIndex
a(href=url_for(link) + '#post-comment' itemprop="discussionUrl")
span.valine-comment-count(data-xid=url_for(link) itemprop="commentCount")
when 'Waline'
+countBlockInIndex
a(href=url_for(link) + '#post-comment')
span.waline-comment-count(id=url_for(link))
when 'Twikoo'
+countBlockInIndex
a.twikoo-count(href=url_for(link) + '#post-comment')
when 'Facebook Comments'
+countBlockInIndex
a(href=url_for(link) + '#post-comment')
span.fb-comments-count(data-href=urlNoIndex(article.permalink))
//- Display the article introduction on homepage
case theme.index_post_content.method
when false

View File

@@ -1,4 +1,8 @@
.flink#article-container
#article-container
if top_img === false
h1.page-title= page.title
.flink
if site.data.link
each i in site.data.link
if i.class_name

View File

@@ -1,5 +1,5 @@
.post-reward
.reward-button
.reward-button.button--animated
i.fas.fa-qrcode
= ' ' + _p('donate')
.reward-main

View File

@@ -0,0 +1,16 @@
script.
(() => {
const getCount = () => {
if (window.DISQUSWIDGETS === undefined) {
var d = document, s = d.createElement('script');
s.src = 'https://!{theme.disqus.shortname}.disqus.com/count.js';
s.id = 'dsq-count-scr';
(d.head || d.body).appendChild(s);
} else {
DISQUSWIDGETS.getCount({reset: true});
}
}
window.pjax ? getCount() : window.addEventListener('load', getCount)
})()

View File

@@ -0,0 +1,15 @@
script.
(()=>{
function loadFBComment () {
if (typeof FB === 'object') FB.XFBML.parse()
else {
let ele = document.createElement('script')
ele.setAttribute('src','https://connect.facebook.net/!{theme.facebook_comments.lang}/sdk.js#xfbml=1&version=v9.0')
ele.setAttribute('async', 'true')
ele.setAttribute('defer', 'true')
ele.setAttribute('crossorigin', 'anonymous')
document.body.appendChild(ele)
}
}
window.pjax ? loadFBComment() : window.addEventListener('load', loadFBComment)
})()

View File

@@ -0,0 +1,12 @@
case theme.comments.use[0]
when 'Twikoo'
include ./twikoo.pug
when 'Disqus'
when 'Disqusjs'
include ./disqus.pug
when 'Valine'
include ./valine.pug
when 'Waline'
include ./waline.pug
when 'Facebook Comments'
include ./fb.pug

View File

@@ -0,0 +1,37 @@
script.
(() => {
const getCommentUrl = () => {
const eleGroup = document.querySelectorAll('#recent-posts .article-title')
let urlArray = []
eleGroup.forEach(i=>{
urlArray.push(i.getAttribute('href'))
})
return urlArray
}
const getCount = () => {
const runTwikoo = () => {
twikoo.getCommentsCount({
envId: '!{theme.twikoo.envId}',
region: '!{theme.twikoo.region}',
urls: getCommentUrl(),
includeReply: false
}).then(function (res) {
document.querySelectorAll('#recent-posts .twikoo-count').forEach((item,index) => {
item.innerText = res[index].count
})
}).catch(function (err) {
console.log(err)
})
}
if (typeof twikoo === 'object') {
runTwikoo()
} else {
getScript('!{theme.CDN.twikoo}').then(runTwikoo)
}
}
window.pjax ? getCount() : window.addEventListener('load', getCount)
})()

View File

@@ -0,0 +1,19 @@
script.
(() => {
function loadValine () {
function initValine () {
let initData = {
el: '#vcomment',
appId: '#{theme.valine.appId}',
appKey: '#{theme.valine.appKey}',
}
const valine = new Valine(initData)
}
if (typeof Valine === 'function') initValine()
else getScript('!{url_for(theme.CDN.valine)}').then(initValine)
}
window.pjax ? loadValine() : window.addEventListener('load', loadValine)
})()

View File

@@ -0,0 +1,18 @@
script.
(() => {
function loadWaline () {
function initWaline () {
let initData = {
el: '#waline-wrap',
serverURL: '!{theme.waline.serverURL}',
}
const waline = new Waline(initData)
}
if (typeof Waline === 'function') initWaline()
else getScript('!{url_for(theme.CDN.waline)}').then(initWaline)
}
window.pjax ? loadWaline() : window.addEventListener('load', loadWaline)
})()

View File

@@ -7,7 +7,7 @@ script.
if (typeof FB === 'object') FB.XFBML.parse()
else {
let ele = document.createElement('script')
ele.setAttribute('src','https://connect.facebook.net/!{theme.facebook_comments.lang}/sdk.js#xfbml=1&version=v7.0')
ele.setAttribute('src','https://connect.facebook.net/!{theme.facebook_comments.lang}/sdk.js#xfbml=1&version=v9.0')
ele.setAttribute('async', 'true')
ele.setAttribute('defer', 'true')
ele.setAttribute('crossorigin', 'anonymous')

View File

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

View File

@@ -54,8 +54,8 @@ hexo.extend.helper.register('cloudTags', function (options = {}) {
return result
})
hexo.extend.helper.register('urlNoIndex', function () {
return prettyUrls(this.url, { trailing_index: false, trailing_html: false })
hexo.extend.helper.register('urlNoIndex', function (url = null) {
return prettyUrls(url || this.url, { trailing_index: false, trailing_html: false })
})
hexo.extend.helper.register('md5', function (path) {

View File

@@ -110,6 +110,7 @@
position: sticky
position: -webkit-sticky
top: 20px
transition: top .3s
.card-tag-cloud
a

View File

@@ -69,7 +69,7 @@
font-size: 30px
// page
&.not-index-bg
&.not-home-page
height: 20rem
+maxWidth768()
@@ -101,19 +101,6 @@
background-color: alpha($dark-black, .5)
content: ''
&.no-top-img
margin-bottom: .5rem
height: 60px
background: 0
#nav
background: rgba(255, 255, 255, .8)
box-shadow: 0 5px 6px -5px rgba(133, 133, 133, .6)
a
color: var(--font-color)
text-shadow: none
#post-info
position: absolute
bottom: 5rem
@@ -129,6 +116,75 @@
bottom: 1.1rem
padding: 0 1.1rem
&.not-top-img
margin-bottom: .5rem
height: 60px
background: 0
#nav
background: rgba(255, 255, 255, .8)
box-shadow: 0 5px 6px -5px rgba(133, 133, 133, .6)
a
color: var(--font-color)
text-shadow: none
&.nav-fixed
#nav
position: fixed
top: -60px
z-index: 91
background: rgba(255, 255, 255, .8)
box-shadow: 0 5px 6px -5px alpha($grey, .6)
transition: transform .2s ease-in-out, opacity .2s ease-in-out
a,
#site-name,
#toggle-menu
color: var(--font-color)
text-shadow: none
&:hover
color: $light-blue
&.nav-visible
#nav
transition: all .5s
transform: translate3d(0, 100%, 0)
& + .layout
& > .aside-content > .sticky_layout
top: 70px
transition: top .5s
// css hack
// all browser in ios and safari in all apple device
_::-webkit-full-page-media,
_:future,
:root #page-header.full_page
background-attachment: scroll !important
#page
h1.page-title
margin: .4rem 0 1rem
// for not top_img
#post
& > #post-info
margin-bottom: 1.5rem
.post-title
padding-bottom: .2rem
border-bottom: 1px solid var(--light-grey)
color: var(--text-highlight-color)
.post-edit-link
float: right
#post-meta,
#post-meta a
color: #78818a
#post-info
.post-title
@extend .limit-more-line
@@ -186,30 +242,6 @@
time
display: none
// for not top_img
#post
& > #post-info
margin-bottom: 1.5rem
.post-title
padding-bottom: .2rem
border-bottom: 1px solid var(--light-grey)
color: var(--text-highlight-color)
.post-edit-link
float: right
#post-meta,
#post-meta a
color: #78818a
// css hack
// all browser in ios and safari in all apple device
_::-webkit-full-page-media,
_:future,
:root #page-header.full_page
background-attachment: scroll !important
#nav
position: absolute
top: 0
@@ -227,10 +259,6 @@ _:future,
+maxWidth768()
padding: 0 16px
&:not(.fixed)
#menus
padding-right: 0 !important
&.show
opacity: 1
@@ -251,27 +279,6 @@ _:future,
&:hover
color: var(--white)
&.fixed
position: fixed
top: -60px
z-index: 91
background: rgba(255, 255, 255, .8)
box-shadow: 0 5px 6px -5px alpha($grey, .6)
transition: transform .2s ease-in-out, opacity .2s ease-in-out
a,
#site-name,
#toggle-menu
color: var(--font-color)
text-shadow: none
&:hover
color: $light-blue
&.visible
transition: all .5s
transform: translate3d(0, 100%, 0)
#site-name
text-shadow: .1rem .1rem .2rem rgba($dark-black, .15)
font-weight: bold
@@ -369,4 +376,3 @@ _:future,
padding-bottom: .3rem
text-shadow: .05rem .05rem .1rem rgba($dark-black, .3)
font-size: .78em
cursor: pointer

View File

@@ -13,9 +13,7 @@
transition: all .4s
&:hover
box-shadow: inset 9em 0 0 0 var(--btn-hover-color)
.reward-main
& > .reward-main
display: block
.reward-main

View File

@@ -53,8 +53,8 @@ if hexo-config('darkmode.enable') || hexo-config('display_mode') == 'dark'
//
#page-header
& > #nav.fixed,
&.no-top-img #nav
&.nav-fixed > #nav,
&.not-top-img > #nav
background: alpha(#121212, .8)
box-shadow: 0 5px 6px -5px rgba(133, 133, 133, 0)

View File

@@ -49,9 +49,6 @@ if hexo-config('readmode')
#aside-content
display: none
#body-wrap
padding-left: 0 !important
#page-header.post-bg
background-color: transparent
background-image: none !important
@@ -80,7 +77,7 @@ if hexo-config('readmode')
.post-outdate-notice,
#web_bg,
#rightside,
.no-top-img
.not-top-img
display: none !important
#article-container

View File

@@ -46,7 +46,3 @@
& > div
width: 100% !important
#page
h1.page-title
margin-top: .4rem

View File

@@ -1,4 +1,5 @@
.flink#article-container
#article-container
.flink
.flink-desc
margin: .2rem 0 .5rem

View File

@@ -315,7 +315,7 @@ document.addEventListener('DOMContentLoaded', function () {
let initTop = 0
let isChatShow = true
const $nav = document.getElementById('nav')
const $header = document.getElementById('page-header')
const isChatBtnHide = typeof chatBtnHide === 'function'
const isChatBtnShow = typeof chatBtnShow === 'function'
window.addEventListener('scroll', btf.throttle(function (e) {
@@ -323,25 +323,25 @@ document.addEventListener('DOMContentLoaded', function () {
const isDown = scrollDirection(currentTop)
if (currentTop > 56) {
if (isDown) {
if ($nav.classList.contains('visible')) $nav.classList.remove('visible')
if ($header.classList.contains('nav-visible')) $header.classList.remove('nav-visible')
if (isChatBtnShow && isChatShow === true) {
chatBtnHide()
isChatShow = false
}
} else {
if (!$nav.classList.contains('visible')) $nav.classList.add('visible')
if (!$header.classList.contains('nav-visible')) $header.classList.add('nav-visible')
if (isChatBtnHide && isChatShow === false) {
chatBtnShow()
isChatShow = true
}
}
$nav.classList.add('fixed')
$header.classList.add('nav-fixed')
if (window.getComputedStyle($rightside).getPropertyValue('opacity') === '0') {
$rightside.style.cssText = 'opacity: 1; transform: translateX(-38px)'
}
} else {
if (currentTop === 0) {
$nav.classList.remove('fixed', 'visible')
$header.classList.remove('nav-fixed', 'nav-visible')
}
$rightside.style.cssText = "opacity: ''; transform: ''"
}
@@ -448,7 +448,7 @@ document.addEventListener('DOMContentLoaded', function () {
let currentIndex = ''
list.forEach(function (ele, index) {
if (top > btf.getEleTop(ele) - 70) {
if (top > btf.getEleTop(ele) - 80) {
currentId = '#' + encodeURI(ele.getAttribute('id'))
currentIndex = index
}