From 62904f5eb857c1952a9ca1fd4b662e49ae97c26e Mon Sep 17 00:00:00 2001 From: SukkaW Date: Fri, 19 Oct 2018 23:08:44 +0800 Subject: [PATCH] fix: fallback for unnecessary config --- src/disqus.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/disqus.js b/src/disqus.js index cbf7557..186f1f9 100644 --- a/src/disqus.js +++ b/src/disqus.js @@ -228,7 +228,11 @@ function DisqusJS(config) { // 填充站点名称和评论数目 d.getElementById('dsqjs-comment-num').innerHTML = disqusjs.page.length - d.getElementById('dsqjs-site-name').innerHTML = disqusjs.config.siteName + + if (disqusjs.config.siteName) { + d.getElementById('dsqjs-site-name').innerHTML = disqusjs.config.siteName + } + // 获取评论列表 getComment() } else if (res.code === 0 && res.response.length !== 1) { @@ -317,7 +321,8 @@ function DisqusJS(config) { list.unshift({ comment, author: comment.author.name, - isPrimary: comment.author.username === disqusjs.config.admin.toLowerCase(), + // 如果不设置 admin 会返回 undefined,所以需要嘴一个判断 + isPrimary: (disqusjs.config.admin ? (comment.author.username === disqusjs.config.admin.toLowerCase()) : false), children: getChildren(+comment.id) }); } @@ -338,7 +343,7 @@ function DisqusJS(config) { return { comment, author: comment.author.name, - isPrimary: comment.author.username === disqusjs.config.admin.toLowerCase(), + isPrimary: (disqusjs.config.admin ? (comment.author.username === disqusjs.config.admin.toLowerCase()) : false), children: getChildren(+comment.id) }; }); @@ -379,7 +384,8 @@ function DisqusJS(config) { } // 处理 Admin Label - if (data.isPrimary) { + // 需要同时设置 isPrimary 和 adminLabel;admin 已经在 processData() 中做过判断了 + if (disqusjs.config.adminLabel && data.isPrimary) { data.comment.authorEl += `${disqusjs.config.adminLabel}`; } @@ -410,7 +416,7 @@ function DisqusJS(config) { */ - let html = `
${s.avatarEl}
${s.authorEl}
${s.message}
` + let html = `
${s.avatarEl}
${s.authorEl}
${s.message}
` return html; } @@ -491,6 +497,7 @@ function DisqusJS(config) { var disqusjs = []; disqusjs.config = config + disqusjs.config.api = (disqusjs.config.api ? disqusjs.config.api : 'https://disqus.skk.moe/disqus/') // 定义 disqusjs.page,之后会填充 thread id、title 等数据 disqusjs.page = [];