Skip to content

Commit

Permalink
feat: 增加首頁評論數顯示
Browse files Browse the repository at this point in the history
fix: 修復點擊toc後,滾動完toc的highlight在點擊的上一個元素
fix: 修復打賞按鈕Hover的bug close jerryc127#473
improvement: 友情鏈接界面增加title顯示(top_img設為false時)
improvement: 優化toc顯示,當向上滾動時,導航欄不會遮擋 toc close jerryc127#472
improvement: 升級facebook comment sdk版本
  • Loading branch information
jerryc127 committed Jan 25, 2021
1 parent d33dc55 commit 6962353
Show file tree
Hide file tree
Showing 27 changed files with 399 additions and 236 deletions.
3 changes: 2 additions & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
2 changes: 2 additions & 0 deletions languages/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ page:
category: Category
archives: Archives

card_post_count: comments

sticky: Sticky
no_title: No title

Expand Down
2 changes: 2 additions & 0 deletions languages/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ page:
category: Category
archives: Archives

card_post_count: comments

sticky: Sticky
no_title: No title

Expand Down
2 changes: 2 additions & 0 deletions languages/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ page:
category: 分类
archives: 归档

card_post_count: 条评论

sticky: 置顶
no_title: 无题

Expand Down
2 changes: 2 additions & 0 deletions languages/zh-TW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ page:
category: 分類
archives: 歸檔

card_post_count: 條評論

sticky: 置頂
no_title: 無題

Expand Down
3 changes: 3 additions & 0 deletions layout/includes/additional-js.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions layout/includes/header/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
37 changes: 34 additions & 3 deletions layout/includes/mixins/post-ui.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -42,19 +42,50 @@ 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)
i.fas.fa-angle-right
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
Expand Down
40 changes: 22 additions & 18 deletions layout/includes/page/flink.pug
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
.flink#article-container
if site.data.link
each i in site.data.link
if i.class_name
h2!= i.class_name
if i.class_desc
.flink-desc!=i.class_desc
.flink-list
each item in i.link_list
.flink-list-item
a(href=url_for(item.link) title=item.name target="_blank")
if theme.lazyload.enable
img(data-lazy-src=url_for(item.avatar) onerror=`this.onerror=null;this.src='` + url_for(theme.error_img.flink) + `'` alt=item.name )
else
img(src=url_for(item.avatar) onerror=`this.onerror=null;this.src='` + url_for(theme.error_img.flink) + `'` alt=item.name )
span.flink-item-name= item.name
span.flink-item-desc(title=item.descr)= item.descr
!= page.content
#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
h2!= i.class_name
if i.class_desc
.flink-desc!=i.class_desc
.flink-list
each item in i.link_list
.flink-list-item
a(href=url_for(item.link) title=item.name target="_blank")
if theme.lazyload.enable
img(data-lazy-src=url_for(item.avatar) onerror=`this.onerror=null;this.src='` + url_for(theme.error_img.flink) + `'` alt=item.name )
else
img(src=url_for(item.avatar) onerror=`this.onerror=null;this.src='` + url_for(theme.error_img.flink) + `'` alt=item.name )
span.flink-item-name= item.name
span.flink-item-desc(title=item.descr)= item.descr
!= page.content

24 changes: 12 additions & 12 deletions layout/includes/post/reward.pug
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
.post-reward
.reward-button
.reward-button.button--animated
i.fas.fa-qrcode
= ' ' + _p('donate')
.reward-main
ul.reward-all
each item in theme.reward.QR_code
- var clickTo = item.link ? item.link : item.img
li.reward-item
a(href=url_for(clickTo) target='_blank')
if theme.lazyload.enable
img.post-qr-code-img(data-lazy-src=url_for(item.img) alt=item.text)
else
img.post-qr-code-img(src=url_for(item.img) alt=item.text)
.post-qr-code-desc=item.text
.reward-main
ul.reward-all
each item in theme.reward.QR_code
- var clickTo = item.link ? item.link : item.img
li.reward-item
a(href=url_for(clickTo) target='_blank')
if theme.lazyload.enable
img.post-qr-code-img(data-lazy-src=url_for(item.img) alt=item.text)
else
img.post-qr-code-img(src=url_for(item.img) alt=item.text)
.post-qr-code-desc=item.text

16 changes: 16 additions & 0 deletions layout/includes/third-party/card-post-count/disqus.pug
Original file line number Diff line number Diff line change
@@ -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)

})()
15 changes: 15 additions & 0 deletions layout/includes/third-party/card-post-count/fb.pug
Original file line number Diff line number Diff line change
@@ -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)
})()
12 changes: 12 additions & 0 deletions layout/includes/third-party/card-post-count/index.pug
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions layout/includes/third-party/card-post-count/twikoo.pug
Original file line number Diff line number Diff line change
@@ -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)

})()
19 changes: 19 additions & 0 deletions layout/includes/third-party/card-post-count/valine.pug
Original file line number Diff line number Diff line change
@@ -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)
})()
18 changes: 18 additions & 0 deletions layout/includes/third-party/card-post-count/waline.pug
Original file line number Diff line number Diff line change
@@ -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)
})()
2 changes: 1 addition & 1 deletion layout/includes/third-party/comments/facebook_comments.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions scripts/helpers/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions source/css/_layout/aside.styl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
position: sticky
position: -webkit-sticky
top: 20px
transition: top .3s

.card-tag-cloud
a
Expand Down
Loading

0 comments on commit 6962353

Please sign in to comment.