forked from jerryc127/hexo-theme-butterfly
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 在綫聊天新增facebook洽談外掛程式 closed jerryc127#918
feat: 添加artalk評論 closed jerryc127#933 fix: 修復 開啟 archor 後, facebook評論加載不正確的 bug fix: 修復 facebook 評論數無法加載的 bug
- Loading branch information
Showing
17 changed files
with
281 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
- const { server, site } = theme.artalk | ||
|
||
script. | ||
(() => { | ||
const getArtalkCount = () => { | ||
const runWidget = () => { | ||
Artalk.LoadCountWidget({ | ||
server: '!{server}', | ||
site: '!{site}', | ||
countEl: '.artalk-count' | ||
}) | ||
} | ||
|
||
if (typeof Artalk === 'function') runWidget() | ||
else getScript('!{theme.asset.artalk_js}').then(runWidget) | ||
} | ||
|
||
|
||
window.pjax ? getArtalkCount() : window.addEventListener('load', getArtalkCount) | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
- let { pageID, lang } = theme.messenger | ||
- lang = theme.comments.use && theme.comments.use.includes('Facebook Comments') ? theme.facebook_comments.lang : lang | ||
|
||
#fb-customer-chat.fb-customerchat(page_id=pageID attribution='biz_inbox') | ||
|
||
script. | ||
document.getElementById('fb-root') ? '' : document.body.insertAdjacentHTML('afterend', '<div id="fb-root"></div>') | ||
|
||
window.fbAsyncInit = function() { | ||
FB.init({ | ||
xfbml: true, | ||
version: 'v14.0' | ||
}); | ||
}; | ||
|
||
(function(d, s, id) { | ||
var js, fjs = d.getElementsByTagName(s)[0]; | ||
if (d.getElementById(id)) return; | ||
js = d.createElement(s); js.id = id; | ||
js.src = 'https://connect.facebook.net/!{lang}/sdk/xfbml.customerchat.js'; | ||
fjs.parentNode.insertBefore(js, fjs); | ||
}(document, 'script', 'facebook-jssdk')); | ||
|
||
if (!{theme.chat_btn}) { | ||
var chatBtnFn = () => { | ||
var chatBtn = document.getElementById("chat_btn") | ||
chatBtn.addEventListener("click", function(){ | ||
FB.CustomerChat.show(); | ||
}); | ||
} | ||
chatBtnFn() | ||
} else { | ||
if (!{theme.chat_hide_show}) { | ||
function chatBtnHide () { | ||
FB.CustomerChat.hide() | ||
} | ||
function chatBtnShow () { | ||
FB.CustomerChat.show(false) | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
- const { server, site } = theme.artalk | ||
|
||
script. | ||
function addArtalkSource () { | ||
const ele = document.createElement('link') | ||
ele.rel = 'stylesheet' | ||
ele.href= '!{theme.asset.artalk_css}' | ||
document.getElementsByTagName('head')[0].appendChild(ele) | ||
} | ||
|
||
function loadArtalk () { | ||
function initArtalk () { | ||
window.artalkItem = new Artalk({ | ||
el: '#artalk-wrap', | ||
server: '!{server}', | ||
site: '!{site}', | ||
pageKey: location.pathname, | ||
darkMode: document.documentElement.getAttribute('data-theme') === 'dark', | ||
countEl: '.artalk-count' | ||
}) | ||
} | ||
|
||
if (typeof window.artalkItem === 'object') setTimeout(()=>{initArtalk()},200) | ||
else { | ||
addArtalkSource() | ||
typeof Artalk !== 'function' ? getScript('!{theme.asset.artalk_js}').then(initArtalk) | ||
: setTimeout(()=>{initArtalk()},200) | ||
} | ||
} | ||
|
||
document.getElementById('darkmode').addEventListener('click',()=> { | ||
if (typeof window.artalkItem !== 'object') return | ||
let isDark = document.documentElement.getAttribute('data-theme') === 'dark' | ||
window.artalkItem.setDarkMode(!isDark) | ||
}) | ||
|
||
|
||
if ('!{theme.comments.use[0]}' === 'Artalk' || !!{theme.comments.lazyload}) { | ||
if (!{theme.comments.lazyload}) btf.loadComment(document.getElementById('artalk-wrap'), loadArtalk) | ||
else loadArtalk() | ||
} else { | ||
function loadOtherComment () { | ||
loadArtalk() | ||
} | ||
} |
20 changes: 15 additions & 5 deletions
20
layout/includes/third-party/comments/facebook_comments.pug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,5 @@ hr | |
data-width="100%") | ||
when 'Remark42' | ||
#remark42 | ||
when 'Artalk' | ||
#artalk-wrap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
- const { server, option } = theme.artalk | ||
- const avatarCdn = option !== null && option.gravatar ? option.gravatar.mirror : 'https://sdn.geekzu.org/avatar/' | ||
- const avatarDefault = option !== null && option.gravatar ? option.gravatar.default : 'mp' | ||
|
||
script. | ||
window.addEventListener('load', () => { | ||
const changeContent = (content) => { | ||
if (content === '') return content | ||
|
||
content = content.replace(/<img.*?src="(.*?)"?[^\>]+>/ig, '[!{_p("aside.card_newest_comments.image")}]') // replace image link | ||
content = content.replace(/<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi, '[!{_p("aside.card_newest_comments.link")}]') // replace url | ||
content = content.replace(/<pre><code>.*?<\/pre>/gi, '[!{_p("aside.card_newest_comments.code")}]') // replace code | ||
content = content.replace(/<[^>]+>/g,"") // remove html tag | ||
|
||
if (content.length > 150) { | ||
content = content.substring(0,150) + '...' | ||
} | ||
return content | ||
} | ||
|
||
const generateHtml = array => { | ||
let result = '' | ||
|
||
if (array.length) { | ||
for (let i = 0; i < array.length; i++) { | ||
result += '<div class=\'aside-list-item\'>' | ||
|
||
if (!{theme.newest_comments.avatar}) { | ||
const name = '!{theme.lazyload.enable ? "data-lazy-src" : "src"}' | ||
result += `<a href='${array[i].url}' class='thumbnail'><img ${name}='${array[i].avatar}' alt='${array[i].nick}'></a>` | ||
} | ||
|
||
result += `<div class='content'> | ||
<a class='comment' href='${array[i].url}' title='${array[i].content}'>${array[i].content}</a> | ||
<div class='name'><span>${array[i].nick} / </span><time datetime="${array[i].date}">${btf.diffDate(array[i].date, true)}</time></div> | ||
</div></div>` | ||
} | ||
} else { | ||
result += '!{_p("aside.card_newest_comments.zero")}' | ||
} | ||
|
||
let $dom = document.querySelector('#card-newest-comments .aside-list') | ||
$dom.innerHTML= result | ||
window.lazyLoadInstance && window.lazyLoadInstance.update() | ||
window.pjax && window.pjax.refresh($dom) | ||
} | ||
|
||
const getComment = () => { | ||
fetch('!{server}/api/stat?type=latest_comments&limit=!{theme.newest_comments.limit}',{method: "POST"}) | ||
.then(response => response.json()) | ||
.then(d => { | ||
const artalk = d.data.map(function (e) { | ||
return { | ||
'avatar': '!{avatarCdn}' + e.email_encrypted + '?d=!{avatarDefault}', | ||
'content': changeContent(e.content_marked), | ||
'nick': e.nick, | ||
'url': e.page_url, | ||
'date': e.date, | ||
} | ||
}) | ||
saveToLocal.set('artalk-newest-comments', JSON.stringify(artalk), !{theme.newest_comments.storage}/(60*24)) | ||
generateHtml(artalk) | ||
}).catch(e => { | ||
const $dom = document.querySelector('#card-newest-comments .aside-list') | ||
$dom.innerHTML= "!{_p('aside.card_newest_comments.error')}" | ||
}) | ||
} | ||
|
||
const newestCommentInit = () => { | ||
if (document.querySelector('#card-newest-comments .aside-list')) { | ||
const data = saveToLocal.get('artalk-newest-comments') | ||
if (data) { | ||
generateHtml(JSON.parse(data)) | ||
} else { | ||
getComment() | ||
} | ||
} | ||
} | ||
|
||
newestCommentInit() | ||
document.addEventListener('pjax:complete', newestCommentInit) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.