diff --git a/src/disqus.js b/src/disqus.js index e71ddbe..979cdab 100644 --- a/src/disqus.js +++ b/src/disqus.js @@ -450,18 +450,20 @@ function DisqusJS(config) { */ let removeDisqUs = (msg) => { // aMatcher - 只处理 Disqus 短链接 - var aMatcher = new RegExp(/(.+)<\/a>/gi), + var aMatcher = new RegExp(/(.+?)<\/a>/gi), hrefMatcher = new RegExp(/href=\"(.+?)\"/gi) - let link = (msg.match(aMatcher) || []) - link.map((link) => { + let link = (msg.match(aMatcher) || []); + link.map((olink) => { // (.*) 是贪婪处理,会一致匹配到最后,可以用于匹配最后一次 - link = link.match(hrefMatcher)[0].replace(/href=\"https:\/\/disq.us\/url\?url=/g, '').replace(/(.*)"/, '$1'); - link = decodeURIComponent(link).replace(/(.*):(.*)cuid=(.*)/, '$1') - msg = msg.replace(aMatcher, `${link}`) + let link = olink.match(hrefMatcher)[0].replace(/href=\"https:\/\/disq.us\/url\?url=/g, '').replace(/(.*)"/, '$1'); + link = decodeURIComponent(link); + link = link.replace(/(.*):(.*)cuid=(.*)/, '$1') + msg = msg.replace(olink, `${link}`) }) // 在最后添加 target="_blank" 可以生效到全局链接(包括 Disqus CDN 直链) - return msg.replace(/href=/g, 'target="_blank" href=') + msg = msg.replace(/href=/g, `target="_blank" href=`) + return msg } let renderPostItem = (s) => { @@ -610,4 +612,4 @@ function DisqusJS(config) { } } -export default DisqusJS; \ No newline at end of file +export default DisqusJS;