refactor: 最新評論 leancloud呼叫由js sdk 改為 rest api 呼叫。應用可以不與valine同一個

feat: 最新評論增加錯誤輸出
style: 刪除不必要的語言檔案
This commit is contained in:
Jerry
2020-09-13 16:58:56 +08:00
parent 554d05d576
commit 97bb8313d0
10 changed files with 48 additions and 45 deletions

View File

@@ -77,8 +77,7 @@ aside:
card_newest_comments:
heading: Newest Comments
loading_text: loading...
zero_day: Today
day: days ago
error: Unable to get the data, please make sure the settings are correct.
date_suffix:
just: Just

View File

@@ -77,8 +77,7 @@ aside:
card_newest_comments:
heading: Newest Comments
loading_text: loading...
zero_day: Today
day: days ago
error: Unable to get the data, please make sure the settings are correct.
date_suffix:
just: Just

View File

@@ -79,8 +79,7 @@ aside:
card_newest_comments:
heading: 最新评论
loading_text: 正在加载中...
zero_day: 今天
day: 天前
error: 无法获取资料,请确认相关配置是否正确
date_suffix:
just: 刚刚

View File

@@ -79,8 +79,7 @@ aside:
card_newest_comments:
heading: 最新評論
loading_text: 正在加載中...
zero_day: 今天
day: 天前
error: 無法獲取資料,請確認相關配置是否正確
date_suffix:
just: 剛剛

View File

@@ -28,6 +28,9 @@ script.
// set expiry to 10 min
saveToLocal.set('disqus-newest-comments', JSON.stringify(disqusArray), 10/(60*24))
generateHtml(disqusArray)
}).fail(()=>{
const $dom = document.querySelector('#card-newest-comments .aside-list')
$dom.innerHTML= "!{_p('aside.card_newest_comments.error')}"
})
}
@@ -47,13 +50,13 @@ script.
</div></div>`
}
let $dom = document.querySelector('.card-newest-comments .aside-list')
let $dom = document.querySelector('#card-newest-comments .aside-list')
$dom.innerHTML= result
window.pjax && window.pjax.refresh($dom)
}
const newestCommentInit = () => {
if (document.querySelector('.card-newest-comments .aside-list')) {
if (document.querySelector('#card-newest-comments .aside-list')) {
const data = saveToLocal.get('disqus-newest-comments')
if (data) {
generateHtml(JSON.parse(data))

View File

@@ -27,6 +27,9 @@ script.
})
saveToLocal.set('github-newest-comments', JSON.stringify(githubArray), 10/(60*24))
generateHtml(githubArray)
}).fail(()=>{
const $dom = document.querySelector('#card-newest-comments .aside-list')
$dom.innerHTML= "!{_p('aside.card_newest_comments.error')}"
})
}
@@ -46,13 +49,13 @@ script.
</div></div>`
}
let $dom = document.querySelector('.card-newest-comments .aside-list')
let $dom = document.querySelector('#card-newest-comments .aside-list')
$dom.innerHTML= result
window.pjax && window.pjax.refresh($dom)
}
const newestCommentInit = () => {
if (document.querySelector('.card-newest-comments .aside-list')) {
if (document.querySelector('#card-newest-comments .aside-list')) {
const data = saveToLocal.get('github-newest-comments')
if (data) {
generateHtml(JSON.parse(data))

View File

@@ -37,58 +37,59 @@ script.
</div></div>`
}
let $dom = document.querySelector('.card-newest-comments .aside-list')
let $dom = document.querySelector('#card-newest-comments .aside-list')
$dom.innerHTML= result
window.pjax && window.pjax.refresh($dom)
}
const getValineData = () => {
if (!(AV.applicationId && (AV.applicationKey || AV.masterKey))) {
const dataInit = {
appId: '!{theme.newest_comments.leancloud.appId}',
appKey: '!{theme.newest_comments.leancloud.appKey}'
let serverURL = ''
if (!{Boolean(theme.newest_comments.leancloud.serverURL)}) {
serverURL = '!{theme.newest_comments.leancloud.serverURL}'
} else {
serverURL = 'https://!{theme.newest_comments.leancloud.appId.substring(0,8)}.api.lncldglobal.com'
}
if (!{theme.newest_comments.leancloud.serverURL ? true : false}) {
dataInit.serverURL= '!{theme.newest_comments.leancloud.serverURL}'
}
AV.init(dataInit)
var settings = {
"url": `${serverURL}/1.1/classes/Comment?limit=!{theme.newest_comments.limit}&order=-createdAt`,
"method": "GET",
"timeout": 0,
"headers": {
"X-LC-Id": '!{theme.newest_comments.leancloud.appId}',
"X-LC-Key": '!{theme.newest_comments.leancloud.appKey}',
"Content-Type": "application/json"
},
}
const query = new AV.Query('Comment');
query.descending('createdAt').limit(!{theme.newest_comments.limit})
var valineArray = []
query.find().then(comments => {
comments.forEach(comment => {
$.ajax(settings).done((response) => {
var valineArray = []
response.results.forEach((e)=>{
valineArray.push({
'avatar': comment.get('QQAvatar'),
'content': changeContent(comment.get('comment')),
'mail': comment.get('mail'),
'nick': comment.get('nick'),
'url': comment.get('url'),
'date': comment.createdAt,
'avatar': e.QQAvatar,
'content': changeContent(e.comment),
'mail': e.mail,
'nick': e.nick,
'url': e.url,
'date': e.createdAt,
})
})
}).then(function() {
saveToLocal.set('leancloud-newest-comments', JSON.stringify(valineArray), 10/(60*24))
generateHtml(valineArray)
}).fail(()=>{
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')) {
if (document.querySelector('#card-newest-comments .aside-list')) {
const data = saveToLocal.get('leancloud-newest-comments')
if (data) {
generateHtml(JSON.parse(data))
} else {
if (typeof window.AV === 'object') {
getValineData()
} else {
$.getScript('https://cdn.jsdelivr.net/npm/leancloud-storage@4.6.1/dist/av-min.js', getValineData)
}
getValineData()
}
}
}

View File

@@ -1,4 +1,4 @@
.card-widget.card-newest-comments
.card-widget#card-newest-comments
.card-content
.item-headline
i.fas.fa-bolt

View File

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

View File

@@ -26,7 +26,7 @@
color: lookup('$tagsP-' + $type + '-color')
&:not(.simple)
background: lighten(lookup('$tagsP-' + $type + '-color'), 80%) !important
background: lighten(lookup('$tagsP-' + $type + '-color'), 85%) !important
& > .note-icon
color: lookup('$tagsP-' + $type + '-color')