fix:评论中存在超链接导致最近评论错位问题

This commit is contained in:
jiewenhuang 2023-10-13 14:35:28 +08:00
parent e6cc62f1b5
commit 60f2ca4838
1 changed files with 13 additions and 4 deletions

View File

@ -127,6 +127,16 @@
}).then(({ comments }) => { }).then(({ comments }) => {
document.getElementById('waline-recent').innerHTML = comments.map( document.getElementById('waline-recent').innerHTML = comments.map(
(comment) =>{ (comment) =>{
const commentContent = document.createElement('div');
let commentText =''
commentContent.innerHTML = comment.comment;
const hasAnchor = commentContent.querySelector('a') !== null;
if (hasAnchor) {
commentText = commentContent.textContent;
}else {
commentText = commentContent.outerHTML || commentContent.textContent;
}
const timestamp = new Date(comment.time); const timestamp = new Date(comment.time);
// 获取年、月、日、时、分、秒 // 获取年、月、日、时、分、秒
@ -148,10 +158,9 @@
<span class="date">${commentTime}</span> <span class="date">${commentTime}</span>
</div> </div>
</div> </div>
<div class="reply"><a class="link aside-reply-content" <div class="reply">
href="${comment.url}"> <a href="${comment.url}" class="link aside-reply-content">${commentText}</a>
<p>${comment.comment}</p> </div>`;
</a></div>`;
}).join(''); }).join('');