Skip to content

Commit

Permalink
fix: 修復 github-issues 最新評論 獲取的url格式 bug
Browse files Browse the repository at this point in the history
fix: 當標題有符號'時,disqus 和 disqusjs 無法加載的 bug
  • Loading branch information
jerryc127 committed Mar 29, 2021
1 parent 6904850 commit 637da07
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
4 changes: 3 additions & 1 deletion layout/includes/third-party/comments/disqus.pug
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
- let disqusPageTitle = page.title.replace(/'/ig,"\\'")

script.
function loadDisqus () {
var disqus_config = function () {
this.page.url = '!{ page.permalink }'
this.page.identifier = '!{ page.path }'
this.page.title = '!{ page.title }'
this.page.title = '!{ disqusPageTitle }'
};

window.disqusReset = () => {
Expand Down
5 changes: 3 additions & 2 deletions layout/includes/third-party/comments/disqusjs.pug
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
- let disqusjsApi = theme.disqusjs.api || 'https://disqus.skk.moe/disqus/'
- let disqusjsPageTitle = page.title.replace(/'/ig,"\\'")

script.
function loadDisqusjs () {
function addDisqusjsCSS () {
Expand All @@ -15,7 +17,7 @@ script.
siteName: '!{theme.disqusjs.siteName}',
identifier: '!{ page.path }',
url: '!{ page.permalink }',
title: '!{ page.title }',
title: '!{ disqusjsPageTitle }',
api: '!{disqusjsApi}',
apikey: '!{theme.disqusjs.apikey}',
nocomment: '!{theme.disqusjs.nocomment}',
Expand Down Expand Up @@ -55,4 +57,3 @@ if is_post() && !theme.comments.lazyload && theme.comments.count && theme.commen
} else {
DISQUSWIDGETS.getCount({reset: true});
}

14 changes: 4 additions & 10 deletions layout/includes/third-party/newest-comments/github-issues.pug
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ script.
}

const findTrueUrl = (array) => {
let url = ''
Promise.all(array.map(item =>
fetch(item.url).then(resp => resp.json()).then(data => {
const urlArray = data.body.match(/(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?/ig)
if (data.user.login === 'utterances-bot') {
url = data.body.match(/https?\:\/\/[^\" ]+/ig).slice(-1)
return url[0]
return urlArray.pop()
} else {
url = data.body.match(/https?\:\/\/[^\" ]+/i)
return url[0]
return urlArray.shift()
}
})
)).then(res => {
Expand Down Expand Up @@ -104,8 +102,4 @@ script.

newestCommentInit()
document.addEventListener('pjax:complete', newestCommentInit)
})




})
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.7.0",
"version": "3.7.1",
"description": "A Simple and Card UI Design theme for Hexo",
"main": "package.json",
"scripts": {
Expand Down

0 comments on commit 637da07

Please sign in to comment.