mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-10 21:17:07 +08:00
refactor: 最新評論 leancloud呼叫由js sdk 改為 rest api 呼叫。應用可以不與valine同一個
feat: 最新評論增加錯誤輸出 style: 刪除不必要的語言檔案
This commit is contained in:
@@ -77,8 +77,7 @@ aside:
|
|||||||
card_newest_comments:
|
card_newest_comments:
|
||||||
heading: Newest Comments
|
heading: Newest Comments
|
||||||
loading_text: loading...
|
loading_text: loading...
|
||||||
zero_day: Today
|
error: Unable to get the data, please make sure the settings are correct.
|
||||||
day: days ago
|
|
||||||
|
|
||||||
date_suffix:
|
date_suffix:
|
||||||
just: Just
|
just: Just
|
||||||
|
|||||||
@@ -77,8 +77,7 @@ aside:
|
|||||||
card_newest_comments:
|
card_newest_comments:
|
||||||
heading: Newest Comments
|
heading: Newest Comments
|
||||||
loading_text: loading...
|
loading_text: loading...
|
||||||
zero_day: Today
|
error: Unable to get the data, please make sure the settings are correct.
|
||||||
day: days ago
|
|
||||||
|
|
||||||
date_suffix:
|
date_suffix:
|
||||||
just: Just
|
just: Just
|
||||||
|
|||||||
@@ -79,8 +79,7 @@ aside:
|
|||||||
card_newest_comments:
|
card_newest_comments:
|
||||||
heading: 最新评论
|
heading: 最新评论
|
||||||
loading_text: 正在加载中...
|
loading_text: 正在加载中...
|
||||||
zero_day: 今天
|
error: 无法获取资料,请确认相关配置是否正确
|
||||||
day: 天前
|
|
||||||
|
|
||||||
date_suffix:
|
date_suffix:
|
||||||
just: 刚刚
|
just: 刚刚
|
||||||
|
|||||||
@@ -79,8 +79,7 @@ aside:
|
|||||||
card_newest_comments:
|
card_newest_comments:
|
||||||
heading: 最新評論
|
heading: 最新評論
|
||||||
loading_text: 正在加載中...
|
loading_text: 正在加載中...
|
||||||
zero_day: 今天
|
error: 無法獲取資料,請確認相關配置是否正確
|
||||||
day: 天前
|
|
||||||
|
|
||||||
date_suffix:
|
date_suffix:
|
||||||
just: 剛剛
|
just: 剛剛
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ script.
|
|||||||
// set expiry to 10 min
|
// set expiry to 10 min
|
||||||
saveToLocal.set('disqus-newest-comments', JSON.stringify(disqusArray), 10/(60*24))
|
saveToLocal.set('disqus-newest-comments', JSON.stringify(disqusArray), 10/(60*24))
|
||||||
generateHtml(disqusArray)
|
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>`
|
</div></div>`
|
||||||
}
|
}
|
||||||
|
|
||||||
let $dom = document.querySelector('.card-newest-comments .aside-list')
|
let $dom = document.querySelector('#card-newest-comments .aside-list')
|
||||||
$dom.innerHTML= result
|
$dom.innerHTML= result
|
||||||
window.pjax && window.pjax.refresh($dom)
|
window.pjax && window.pjax.refresh($dom)
|
||||||
}
|
}
|
||||||
|
|
||||||
const newestCommentInit = () => {
|
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')
|
const data = saveToLocal.get('disqus-newest-comments')
|
||||||
if (data) {
|
if (data) {
|
||||||
generateHtml(JSON.parse(data))
|
generateHtml(JSON.parse(data))
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ script.
|
|||||||
})
|
})
|
||||||
saveToLocal.set('github-newest-comments', JSON.stringify(githubArray), 10/(60*24))
|
saveToLocal.set('github-newest-comments', JSON.stringify(githubArray), 10/(60*24))
|
||||||
generateHtml(githubArray)
|
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>`
|
</div></div>`
|
||||||
}
|
}
|
||||||
|
|
||||||
let $dom = document.querySelector('.card-newest-comments .aside-list')
|
let $dom = document.querySelector('#card-newest-comments .aside-list')
|
||||||
$dom.innerHTML= result
|
$dom.innerHTML= result
|
||||||
window.pjax && window.pjax.refresh($dom)
|
window.pjax && window.pjax.refresh($dom)
|
||||||
}
|
}
|
||||||
|
|
||||||
const newestCommentInit = () => {
|
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')
|
const data = saveToLocal.get('github-newest-comments')
|
||||||
if (data) {
|
if (data) {
|
||||||
generateHtml(JSON.parse(data))
|
generateHtml(JSON.parse(data))
|
||||||
|
|||||||
@@ -37,58 +37,59 @@ script.
|
|||||||
</div></div>`
|
</div></div>`
|
||||||
}
|
}
|
||||||
|
|
||||||
let $dom = document.querySelector('.card-newest-comments .aside-list')
|
let $dom = document.querySelector('#card-newest-comments .aside-list')
|
||||||
$dom.innerHTML= result
|
$dom.innerHTML= result
|
||||||
window.pjax && window.pjax.refresh($dom)
|
window.pjax && window.pjax.refresh($dom)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getValineData = () => {
|
const getValineData = () => {
|
||||||
|
let serverURL = ''
|
||||||
if (!(AV.applicationId && (AV.applicationKey || AV.masterKey))) {
|
if (!{Boolean(theme.newest_comments.leancloud.serverURL)}) {
|
||||||
const dataInit = {
|
serverURL = '!{theme.newest_comments.leancloud.serverURL}'
|
||||||
appId: '!{theme.newest_comments.leancloud.appId}',
|
} else {
|
||||||
appKey: '!{theme.newest_comments.leancloud.appKey}'
|
serverURL = 'https://!{theme.newest_comments.leancloud.appId.substring(0,8)}.api.lncldglobal.com'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!{theme.newest_comments.leancloud.serverURL ? true : false}) {
|
var settings = {
|
||||||
dataInit.serverURL= '!{theme.newest_comments.leancloud.serverURL}'
|
"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"
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
AV.init(dataInit)
|
$.ajax(settings).done((response) => {
|
||||||
}
|
|
||||||
|
|
||||||
const query = new AV.Query('Comment');
|
|
||||||
query.descending('createdAt').limit(!{theme.newest_comments.limit})
|
|
||||||
|
|
||||||
var valineArray = []
|
var valineArray = []
|
||||||
query.find().then(comments => {
|
response.results.forEach((e)=>{
|
||||||
comments.forEach(comment => {
|
|
||||||
valineArray.push({
|
valineArray.push({
|
||||||
'avatar': comment.get('QQAvatar'),
|
'avatar': e.QQAvatar,
|
||||||
'content': changeContent(comment.get('comment')),
|
'content': changeContent(e.comment),
|
||||||
'mail': comment.get('mail'),
|
'mail': e.mail,
|
||||||
'nick': comment.get('nick'),
|
'nick': e.nick,
|
||||||
'url': comment.get('url'),
|
'url': e.url,
|
||||||
'date': comment.createdAt,
|
'date': e.createdAt,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}).then(function() {
|
|
||||||
saveToLocal.set('leancloud-newest-comments', JSON.stringify(valineArray), 10/(60*24))
|
saveToLocal.set('leancloud-newest-comments', JSON.stringify(valineArray), 10/(60*24))
|
||||||
generateHtml(valineArray)
|
generateHtml(valineArray)
|
||||||
|
|
||||||
|
}).fail(()=>{
|
||||||
|
const $dom = document.querySelector('#card-newest-comments .aside-list')
|
||||||
|
$dom.innerHTML= "!{_p('aside.card_newest_comments.error')}"
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const newestCommentInit = () => {
|
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')
|
const data = saveToLocal.get('leancloud-newest-comments')
|
||||||
if (data) {
|
if (data) {
|
||||||
generateHtml(JSON.parse(data))
|
generateHtml(JSON.parse(data))
|
||||||
} else {
|
} else {
|
||||||
if (typeof window.AV === 'object') {
|
|
||||||
getValineData()
|
getValineData()
|
||||||
} else {
|
|
||||||
$.getScript('https://cdn.jsdelivr.net/npm/leancloud-storage@4.6.1/dist/av-min.js', getValineData)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.card-widget.card-newest-comments
|
.card-widget#card-newest-comments
|
||||||
.card-content
|
.card-content
|
||||||
.item-headline
|
.item-headline
|
||||||
i.fas.fa-bolt
|
i.fas.fa-bolt
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hexo-theme-butterfly",
|
"name": "hexo-theme-butterfly",
|
||||||
"version": "3.2.0-b2",
|
"version": "3.2.0-b3",
|
||||||
"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": {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
color: lookup('$tagsP-' + $type + '-color')
|
color: lookup('$tagsP-' + $type + '-color')
|
||||||
|
|
||||||
&:not(.simple)
|
&:not(.simple)
|
||||||
background: lighten(lookup('$tagsP-' + $type + '-color'), 80%) !important
|
background: lighten(lookup('$tagsP-' + $type + '-color'), 85%) !important
|
||||||
|
|
||||||
& > .note-icon
|
& > .note-icon
|
||||||
color: lookup('$tagsP-' + $type + '-color')
|
color: lookup('$tagsP-' + $type + '-color')
|
||||||
|
|||||||
Reference in New Issue
Block a user